/** * @return collection of all Java enums used as a type of an entity attribute */ public Collection<Class> getAllEnums() { if (enums == null) { synchronized (this) { enums = new HashSet<>(); for (MetaClass metaClass : metadata.getSession().getClasses()) { for (MetaProperty metaProperty : metaClass.getProperties()) { if (metaProperty.getRange() != null && metaProperty.getRange().isEnum()) { Class c = metaProperty.getRange().asEnumeration().getJavaClass(); enums.add(c); } } } } } return enums; }
protected String getDisplayValue(String value) { if (StringUtils.isEmpty(value)) { return value; } final String entityName = getLogItem().getEntity(); com.haulmont.chile.core.model.MetaClass metaClass = getClassFromEntityName(entityName); if (metaClass != null) { com.haulmont.chile.core.model.MetaProperty property = metaClass.getProperty(getName()); if (property != null) { if (property.getRange().isDatatype()) { return value; } else if (property.getRange().isEnum()) { String nameKey = property.getRange().asEnumeration().getJavaClass().getSimpleName() + "." + value; String packageName = property.getRange().asEnumeration().getJavaClass().getPackage().getName(); Messages messages = AppBeans.get(Messages.NAME); return messages.getMessage(packageName, nameKey); } else { return value; } } else { return value; } } else { return value; } }
/** * Java class of the target MetaProperty range */ public Class getRangeJavaClass() { if (metaProperties.length < 1) { throw new RuntimeException("Empty property path at metaclass " + metaClass.getName() + " - possibly wrong property name"); } Range range = metaProperties[metaProperties.length - 1].getRange(); if (range.isDatatype()) { return range.asDatatype().getJavaClass(); } else if (range.isClass()) { return range.asClass().getJavaClass(); } else if (range.isEnum()) { return range.asEnumeration().getJavaClass(); } else { throw new UnsupportedOperationException(); } }
property.setJavaType(info.getObject().asEnumeration().getJavaClass()); } else { property.setJavaType(field.getType());
public MetaPropertyInfo(MetaProperty metaProperty) { Messages messages = AppBeans.get(Messages.class); Metadata metadata = AppBeans.get(Metadata.class); this.name = metaProperty.getName(); this.attributeType = metaProperty.getType(); switch (attributeType) { case DATATYPE: Datatype<Object> datatype = metaProperty.getRange().asDatatype(); try { this.type = metadata.getDatatypes().getId(datatype); } catch (Exception e) { this.type = datatype.toString(); } break; case ASSOCIATION: case COMPOSITION: this.type = metaProperty.getRange().asClass().getName(); break; case ENUM: this.type = metaProperty.getRange().asEnumeration().getJavaClass().getName(); break; } this.cardinality = metaProperty.getRange().getCardinality(); this.readOnly = metaProperty.isReadOnly(); this.mandatory = metaProperty.isMandatory(); this.isPersistent = metadata.getTools().isPersistent(metaProperty); this.isTransient = metadata.getTools().isNotPersistent(metaProperty); this.description = messages.getTools().getPropertyCaption(metaProperty); }
@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()); } } } }