@Override public T getValue() { return columnComponent.getValue(); }
public Field createField(ReportInputParameter parameter) { Field field = fieldCreationMapping.get(parameter.getType()).createField(parameter); field.setRequiredMessage(messages.formatMessage(this.getClass(), "error.paramIsRequiredButEmpty", parameter.getLocName())); field.setId("param_" + parameter.getAlias()); field.setWidth("100%"); field.setFrame(frame.getWrappedFrame()); field.setEditable(true); field.setRequired(parameter.getRequired()); return field; }
protected void clear(Field... fields) { for (Field component : fields) { component.setValue(null); } }
@Override public void initFrame() { for (Component c : frame.getComponents()) { if (c instanceof Field) { Field field = (Field) c; if (field.isRequired() && StringUtils.isBlank(field.getRequiredMessage()) && StringUtils.isBlank(field.getCaption())) { field.setRequiredMessage(getDefaultRequiredMessage(wizard.getMessage(field.getId()))); } } } } }
protected void loadValidators(Field component, Element element) { List<Element> validatorElements = element.elements("validator"); if (!validatorElements.isEmpty()) { for (Element validatorElement : validatorElements) { Field.Validator validator = loadValidator(validatorElement); if (validator != null) { component.addValidator(validator); } } } else if (component.getDatasource() != null) { MetaProperty property = component.getMetaProperty(); Field.Validator validator = getDefaultValidator(property); if (validator != null) { component.addValidator(validator); } } }
editField.setFrame(getFrame()); editField.setWidth(fieldWidth); boolean required = editField.isRequired(); editField.setRequired(false); editField.setValue(Collections.EMPTY_LIST); } else { editField.setValue(null); Field.Validator validator = fieldValidators.get(field.getFqn()); if (validator != null) { editField.addValidator(validator);
protected void loadRequired(Field component, Element element) { String required = element.attributeValue("required"); if (StringUtils.isNotEmpty(required)) { component.setRequired(Boolean.parseBoolean(required)); } String requiredMessage = element.attributeValue("requiredMessage"); if (requiredMessage != null) { component.setRequiredMessage(loadResourceString(requiredMessage)); } else if (component.isRequired() && component.getDatasource() != null) { MetaPropertyPath propertyPath = component.getMetaPropertyPath(); String defaultRequiredMessage = getMessageTools() .getDefaultRequiredMessage(propertyPath.getMetaClass(), propertyPath.toString()); component.setRequiredMessage(defaultRequiredMessage); } }
protected void createComponent(ReportInputParameter parameter, int currentGridRow, boolean visible) { Field field = parameterFieldCreator.createField(parameter); field.setWidth("400px"); field.setValue(value); } else { CollectionDatasource datasource = (CollectionDatasource) field.getDatasource(); if (value instanceof Collection) { Collection collection = (Collection) value; field.addValidator(new ReportParamFieldValidator(parameter)); field.requestFocus(); field.setVisible(visible);
@SuppressWarnings("unchecked") @Override public void paramChanged(Param oldParam, Param newParam) { Component oldParamEditComponent = paramEditComponent; for (Component component : paramEditComponentLayout.getComponents()) { paramEditComponentLayout.remove(component); } createParamEditLayout(); if (paramEditComponent instanceof Field) { ((Field) paramEditComponent).setRequired(condition.getRequired()); if (oldParam.getJavaClass().equals(newParam.getJavaClass()) && paramEditComponent.getClass().equals(oldParamEditComponent.getClass())) { ((Field) paramEditComponent).setValue(((Field) oldParamEditComponent).getValue()); } } }
protected void standardFieldInit(Field field, ProcFormParam formParam) { field.setRequired(formParam.isRequired()); field.setEditable(formParam.isEditable()); field.setRequiredMessage(messages.formatMessage(AbstractFormFieldGenerator.class, "fillField", formParam.getLocCaption())); }
protected void initRequired(Field<?> component, MetaPropertyPath metaPropertyPath) { MetaProperty metaProperty = metaPropertyPath.getMetaProperty(); boolean newRequired = metaProperty.isMandatory(); Object notNullUiComponent = metaProperty.getAnnotations() .get(NotNull.class.getName() + "_notnull_ui_component"); if (Boolean.TRUE.equals(notNullUiComponent)) { newRequired = true; } if (newRequired) { component.setRequired(true); if (Strings.isNullOrEmpty(component.getRequiredMessage())) { component.setRequiredMessage(messageTools.getDefaultRequiredMessage( metaPropertyPath.getMetaClass(), metaPropertyPath.toPathString()) ); } } }
protected void initDefaultValueField() { defaultValueLabel.setVisible(false); defaultValueBox.removeAll(); ReportInputParameter parameter = getItem(); if (canHaveDefaultValue()) { Field<Object> field = parameterFieldCreator.createField(parameter); field.addValueChangeListener(e -> { if (e.getValue() != null) { parameter.setDefaultValue(reportService.convertToString(e.getValue().getClass(), e.getValue())); } else { parameter.setDefaultValue(null); } }); if (parameter.getParameterClass() != null) { field.setValue(reportService.convertFromString(parameter.getParameterClass(), parameter.getDefaultValue())); } field.setRequired(false); defaultValueBox.add(field); defaultValueLabel.setVisible(true); } defaultValueBox.setEnabled(security.isEntityOpPermitted(metadata.getClassNN(ReportInputParameter.class), EntityOp.UPDATE)); }
cubaField.setRequired(true); cubaField.setRequiredMessage(requiredColumns.get(columnConf));
cubaField.setRequired(fci.getTargetRequired()); cubaField.setRequiredMessage(fci.getTargetRequiredMessage()); cubaField.addValidator(validator);
protected CubaEditorField createCustomField(final Field columnComponent) { if (!(columnComponent instanceof Buffered)) { throw new IllegalArgumentException("Editor field must implement " + "com.haulmont.cuba.gui.components.Buffered"); } Component content = WebComponentsHelper.getComposition(columnComponent); //noinspection unchecked CubaEditorField wrapper = new DataGridEditorCustomField(columnComponent) { @Override protected Component initContent() { return content; } }; if (content instanceof Component.Focusable) { wrapper.setFocusDelegate((Component.Focusable) content); } wrapper.setReadOnly(!columnComponent.isEditable()); wrapper.setRequiredIndicatorVisible(columnComponent.isRequired()); //noinspection unchecked columnComponent.addValueChangeListener(event -> wrapper.markAsDirty()); return wrapper; } }
/** * Set field's "required" flag to false if the value has been filtered by Row Level Security * This is necessary to allow user to submit form with filtered attribute even if attribute is required */ public static void handleFilteredAttributes(Field component, Datasource datasource, MetaPropertyPath mpp) { if (component.isRequired() && datasource.getState() == Datasource.State.VALID && datasource.getItem() != null && mpp.getMetaProperty().getRange().isClass()) { Entity targetItem = datasource.getItem(); MetaProperty[] propertiesChain = mpp.getMetaProperties(); if (propertiesChain.length > 1) { String basePropertyItem = Arrays.stream(propertiesChain) .limit(propertiesChain.length - 1) .map(MetadataObject::getName) .collect(Collectors.joining(".")); targetItem = datasource.getItem().getValueEx(basePropertyItem); } if (targetItem instanceof BaseGenericIdEntity) { String metaPropertyName = mpp.getMetaProperty().getName(); Object value = targetItem.getValue(metaPropertyName); BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) targetItem; String[] filteredAttributes = getFilteredAttributes(baseGenericIdEntity); if (value == null && filteredAttributes != null && ArrayUtils.contains(filteredAttributes, metaPropertyName)) { component.setRequired(false); } } } }
componentForEntity.setValue(null); }); } else { componentForEntity = lookupField; componentForEntity.addValueChangeListener(e -> { Entity selectedEntity = (Entity) e.getValue(); if (selectedEntity != null && !valueExists(selectedEntity)) { timeZone, optionCaptionProvider)); componentForEntity.setValue(null); });
@Override public void actionPerform(Component component) { editField.setEnabled(!editField.isEnabled()); if (!editField.isEnabled()) { if (editField instanceof ListEditor) { editField.setValue(Collections.EMPTY_LIST); } else { editField.setValue(null); } setIcon("icons/edit.png"); clearButton.setDescription(getMessage("bulk.editAttribute")); } else { setIcon("icons/trash.png"); clearButton.setDescription(getMessage("bulk.clearAttribute")); } } };