/** * For collection dynamic attributes the method returns a list of formatted collection items joined with the comma, * for non-collection dynamic attribute a formatted value is returned */ @SuppressWarnings("unchecked") public String getDynamicAttributeValueAsString(MetaProperty metaProperty, Object value) { CategoryAttribute categoryAttribute = getCategoryAttribute(metaProperty); if (categoryAttribute.getIsCollection()) { if (value instanceof Collection) { List<String> valuesList = ((Collection<Object>) value).stream() .map(item -> metadataTools.format(item, metaProperty)) .collect(Collectors.toList()); return Joiner.on(", ").join(valuesList); } } return metadataTools.format(value, metaProperty); } }
/** * Creates ListEditor component. * * @param valueSource value source * @param metaPropertyPath meta property path of dynamic attribute * @return list editor component or null */ @Nullable public Component generateComponent(ValueSource valueSource, MetaPropertyPath metaPropertyPath) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaPropertyPath.getMetaProperty()); if (categoryAttribute == null) { log.error("Dynamic attribute {} not found", metaPropertyPath.getMetaProperty().getName()); return null; } return generateComponent(valueSource, categoryAttribute); }
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 boolean isCollectionDynamicAttribute(MetaProperty metaProperty) { if (DynamicAttributesUtils.isDynamicAttribute(metaProperty.getName())) { CategoryAttribute attribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); return attribute != null && BooleanUtils.isTrue(attribute.getIsCollection()); } return false; } }
@Override public String getLocCaption() { if (isBlank(caption) && !isBlank(propertyPath)) { MessageTools messageTools = AppBeans.get(MessageTools.class); String propertyCaption = messageTools.getPropertyCaption(metaClass, propertyPath); if (!isBlank(propertyCaption)) { return propertyCaption + "." + locCaption; } } else if (isNotBlank(caption)) { MessageTools messageTools = AppBeans.get(MessageTools.class); return messageTools.loadString(messagesPack, caption); } MetaPropertyPath mpp = DynamicAttributesUtils.getMetaPropertyPath(metaClass, getCategoryAttributeId()); if (mpp != null) { return DynamicAttributesUtils.getCategoryAttribute(mpp.getMetaProperty()).getLocaleName(); } return super.getLocCaption(); } }
protected String getColumnCaption(Object columnId, Column column) { String caption = column.getCaption(); if (caption != null) { return caption; } if (!(columnId instanceof MetaPropertyPath)) { return StringUtils.capitalize(getColumnCaption(columnId)); } MetaPropertyPath mpp = (MetaPropertyPath) columnId; MetaProperty metaProperty = mpp.getMetaProperty(); if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames())) { return categoryAttribute.getLocaleName(); } caption = StringUtils.capitalize(categoryAttribute.getName()); } else { caption = StringUtils.capitalize(getColumnCaption(columnId)); } return caption; }
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; }
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); columnCaption = LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames()) ? categoryAttribute.getLocaleName() :
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
@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; }
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) { return createEnumField(context);
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaPropertyPath.getMetaProperty()); field.setCaption(categoryAttribute != null ? categoryAttribute.getLocaleName() : propertyName); } else {
protected EntityPropertyDiff(com.haulmont.chile.core.model.MetaProperty metaProperty) { metaClassName = metaProperty.getDomain().getName(); propertyName = metaProperty.getName(); if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); propertyCaption = categoryAttribute.getLocaleName(); } else { MessageTools messageTools = AppBeans.get(MessageTools.NAME); propertyCaption = messageTools.getPropertyCaption(metaProperty.getDomain(), metaProperty.getName()); } }
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(property);
@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()); } } } }
if (metaPropertyPath != null) { if (isDynamicAttribute(metaPropertyPath.getMetaProperty())) { CategoryAttribute categoryAttribute = getCategoryAttribute(metaPropertyPath.getMetaProperty()); ((Component.HasCaption) component).setCaption(categoryAttribute != null ? categoryAttribute.getLocaleName()
@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()); } } } }