public Boolean getIsEntity() { return getDataType() == PropertyType.ENTITY; }
public List<String> getEnumerationOptions() { Preconditions.checkState(getDataType() == PropertyType.ENUMERATION, "Only enumeration attributes have options"); String[] values = StringUtils.split(enumeration, ','); return values != null ? Arrays.asList(values) : Collections.<String>emptyList(); }
protected String getCategoryAttributeValueName(CategoryAttributeValue attributeValue) { CategoryAttribute categoryAttribute = attributeValue.getCategoryAttribute(); String fieldName = null; switch (categoryAttribute.getDataType()) { case DATE: fieldName = "dateValue"; break; case ENUMERATION: case STRING: fieldName = "stringValue"; break; case INTEGER: fieldName = "intValue"; break; case DOUBLE: fieldName = "doubleValue"; break; case BOOLEAN: fieldName = "booleanValue"; break; } return fieldName; }
/** * Resolve attribute value's Java class */ public static Class getAttributeClass(CategoryAttribute attribute) { PropertyType propertyType = attribute.getDataType(); switch (propertyType) { case STRING: return String.class; case INTEGER: return Integer.class; case DOUBLE: return Double.class; case BOOLEAN: return Boolean.class; case DATE: return Date.class; case ENUMERATION: return String.class; case ENTITY: return attribute.getJavaClassForEntity(); } return String.class; }
public Param(Builder builder) { name = builder.name; setJavaClass(builder.javaClass); entityWhere = builder.entityWhere; entityView = (builder.entityView != null) ? builder.entityView : View.MINIMAL; property = builder.property; inExpr = builder.inExpr; required = builder.required; categoryAttrId = builder.categoryAttrId; isDateInterval = builder.isDateInterval; useUserTimeZone = builder.useUserTimeZone; if (DynamicAttributesUtils.isDynamicAttribute(builder.property)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(builder.property); if (categoryAttribute.getDataType() == PropertyType.ENUMERATION) { type = Type.RUNTIME_ENUM; } } }
protected Object getOldCategoryAttributeValue(CategoryAttributeValue attributeValue, EntityAttributeChanges changes) { CategoryAttribute categoryAttribute = attributeValue.getCategoryAttribute(); PersistenceTools persistenceTools = persistence.getTools(); String fieldName = null; switch (categoryAttribute.getDataType()) { case DATE: fieldName = "dateValue"; break; case ENUMERATION: case STRING: fieldName = "stringValue"; break; case INTEGER: fieldName = "intValue"; break; case DOUBLE: fieldName = "doubleValue"; break; case BOOLEAN: fieldName = "booleanValue"; break; } if (fieldName != null) { return changes != null ? changes.getOldValue(fieldName) : persistenceTools.getOldValue(attributeValue, fieldName); } return null; }
.filter(cav -> cav.getCategoryAttribute().getDataType() == PropertyType.ENTITY && cav.getChildValues() != null) .forEach(cav -> cavsOfEntityType.addAll(cav.getChildValues()));
protected Component createStringField(ComponentGenerationContext context, MetaPropertyPath mpp) { TextInputField textField = null; Element xmlDescriptor = context.getXmlDescriptor(); if (xmlDescriptor != null) { final String rows = xmlDescriptor.attributeValue("rows"); if (!StringUtils.isEmpty(rows)) { TextArea textArea = uiComponents.create(TextArea.class); textArea.setRows(Integer.parseInt(rows)); textField = textArea; } } if (DynamicAttributesUtils.isDynamicAttribute(context.getProperty()) && mpp != null) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(mpp.getMetaProperty()); if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.STRING && categoryAttribute.getRowsCount() != null && categoryAttribute.getRowsCount() > 1) { TextArea textArea = uiComponents.create(TextArea.class); textArea.setRows(categoryAttribute.getRowsCount()); textField = textArea; } } if (textField == null) { textField = uiComponents.create(TextField.class); } setValueSource(textField, context); String maxLength = xmlDescriptor != null ? xmlDescriptor.attributeValue("maxLength") : null; if (StringUtils.isNotEmpty(maxLength)) { ((TextInputField.MaxLengthLimited) textField).setMaxLength(Integer.parseInt(maxLength)); } return textField; }
Collection<String> componentIds = FIELDS_VISIBLE_FOR_DATATYPES.get(attribute.getDataType()); if (componentIds != null) { for (String componentId : componentIds) { if (attribute.getDataType() == PropertyType.ENTITY) { if (StringUtils.isNotBlank(attribute.getEntityClass())) { defaultEntityField.setEditable(true); if (attribute.getDataType() == PropertyType.DATE) { if (Boolean.TRUE.equals(attribute.getDefaultDateIsCurrent())) { attributeFieldGroup.setVisible("defaultDate", false); if (attribute.getDataType() == PropertyType.BOOLEAN || attribute.getDataType() == PropertyType.ENUMERATION) { attributeFieldGroup.setFieldValue("isCollection", null);
@Nullable public Field createField(Datasource datasource, MetaProperty property) { if (DynamicAttributesUtils.isDynamicAttribute(property)) { CategoryAttribute attribute = DynamicAttributesUtils.getCategoryAttribute(property); if (attribute.getDataType().equals(PropertyType.ENUMERATION)) { return createEnumField(datasource, property); } else if (attribute.getIsCollection()) { return createListEditorField(datasource, property); } } if (property.getRange().isDatatype()) { Class type = property.getRange().asDatatype().getJavaClass(); if (type.equals(String.class)) { return createStringField(datasource, property); } else if (type.equals(Boolean.class)) { return createBooleanField(datasource, property); } else if (type.equals(java.sql.Date.class) || type.equals(Date.class)) { return createDateField(datasource, property); } else if (type.equals(Time.class)) { return createTimeField(datasource, property); } else if (Number.class.isAssignableFrom(type)) { return createNumberField(datasource, property); } } else if (property.getRange().isClass()) { return createEntityField(datasource, property); } else if (property.getRange().isEnum()) { return createEnumField(datasource, property); } return null; }
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) { return createEnumField(context);
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(property); if (categoryAttribute.getDataType().equals(PropertyType.ENUMERATION)) { return LocaleHelper.getEnumLocalizedValue((String) value, categoryAttribute.getEnumerationLocales());
/** * Creates ListEditor component. * * @param valueSource value source * @param categoryAttribute category attribute * @return list editor component or null */ @Nullable public Component generateComponent(ValueSource valueSource, CategoryAttribute categoryAttribute) { ListEditor listEditor = uiComponents.create(ListEditor.NAME); listEditor.setEntityJoinClause(categoryAttribute.getJoinClause()); listEditor.setEntityWhereClause(categoryAttribute.getWhereClause()); ListEditor.ItemType itemType = getListEditorItemType(categoryAttribute.getDataType()); listEditor.setItemType(itemType); if (!Strings.isNullOrEmpty(categoryAttribute.getEntityClass())) { Class<?> clazz = scripting.loadClass(categoryAttribute.getEntityClass()); if (clazz == null) { log.error("Unable to find class of entity {} for dynamic attribute {}", categoryAttribute.getEntityClass(), categoryAttribute.getCode()); return null; } MetaClass metaClass = metadata.getClassNN(clazz); listEditor.setEntityName(metaClass.getName()); listEditor.setUseLookupField(BooleanUtils.isTrue(categoryAttribute.getLookup())); } //noinspection unchecked listEditor.setValueSource(valueSource); return listEditor; }
if (deleted) { Object oldValue; switch (cav.getCategoryAttribute().getDataType()) { case STRING: case ENUMERATION: break; default: log.warn("Unsupported dynamic attribute type: " + cav.getCategoryAttribute().getDataType()); oldValue = null;
StringUtils.capitalize(attribute.getName())); if (attribute.getDataType().equals(PropertyType.STRING)) { ClientConfig clientConfig = getConfiguration().getConfig(ClientConfig.class); column.setMaxTextLength(clientConfig.getDynamicAttributesTableColumnMaxTextLength()); if (attribute.getDataType().equals(PropertyType.ENUMERATION)) { column.setFormatter(value -> LocaleHelper.getEnumLocalizedValue((String) value, attribute.getEnumerationLocales())
@SuppressWarnings("unchecked") @Override protected void valueBindingConnected(ValueSource<V> valueSource) { super.valueBindingConnected(valueSource); if (valueSource instanceof EntityValueSource) { MetaPropertyPath propertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath(); MetaProperty metaProperty = propertyPath.getMetaProperty(); if (metaProperty.getRange().isEnum()) { //noinspection unchecked setOptions(new EnumOptions(metaProperty.getJavaType())); } if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) { setOptionsMap((Map<String, V>) categoryAttribute.getLocalizedEnumerationMap()); } } } }
@SuppressWarnings("unchecked") @Override protected void valueBindingConnected(ValueSource<V> valueSource) { super.valueBindingConnected(valueSource); if (valueSource instanceof EntityValueSource) { MetaPropertyPath propertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath(); MetaProperty metaProperty = propertyPath.getMetaProperty(); if (metaProperty.getRange().isEnum()) { //noinspection unchecked setOptions(new EnumOptions(metaProperty.getRange().asEnumeration().getJavaClass())); } if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) { setOptionsMap((Map<String, I>) categoryAttribute.getLocalizedEnumerationMap()); } } } }
@SuppressWarnings("unchecked") @Override protected void valueBindingConnected(ValueSource<V> valueSource) { super.valueBindingConnected(valueSource); if (valueSource instanceof EntityValueSource) { MetaPropertyPath propertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath(); MetaProperty metaProperty = propertyPath.getMetaProperty(); if (metaProperty.getRange().isEnum()) { //noinspection unchecked setOptions(new EnumOptions(metaProperty.getRange().asEnumeration().getJavaClass())); } if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) { setOptionsMap((Map<String, I>) categoryAttribute.getLocalizedEnumerationMap()); } } } }