use of io.jmix.core.metamodel.datatype.Enumeration in project jmix-docs by Haulmont.
the class CustomerService method printOrderProperties.
public void printOrderProperties() {
// <1>
MetaClass metaClass = metadata.getClass(Order.class);
for (MetaProperty metaProperty : metaClass.getProperties()) {
// <2>
// <3>
String propertyName = metaProperty.getName();
// <4>
MetaProperty.Type propertyType = metaProperty.getType();
// <5>
Class<?> javaType = metaProperty.getJavaType();
// <6>
Range propertyRange = metaProperty.getRange();
String info = "name: " + propertyName + "\n type: " + propertyType + "\n Java type: " + javaType + "\n range: " + propertyRange;
if (propertyRange.isClass()) {
// <7>
// <8>
MetaClass refMetaClass = propertyRange.asClass();
// <9>
Range.Cardinality cardinality = propertyRange.getCardinality();
info += "\n reference to: " + refMetaClass;
info += "\n cardinality: " + cardinality;
} else if (propertyRange.isEnum()) {
// <10>
// <11>
Enumeration<?> enumeration = propertyRange.asEnumeration();
info += "\n enum: " + enumeration;
} else if (propertyRange.isDatatype()) {
// <12>
// <13>
Datatype<Object> propertyDatatype = propertyRange.asDatatype();
info += "\n data type: " + propertyDatatype;
}
System.out.println(info);
}
}
use of io.jmix.core.metamodel.datatype.Enumeration in project jmix by jmix-framework.
the class ValueDatasourceDelegate method convertEnumValues.
protected void convertEnumValues(KeyValueEntity entity, List<MetaProperty> enumProperties) {
try {
for (MetaProperty enumProperty : enumProperties) {
Object enumValue = entity.getValue(enumProperty.getName());
if (enumValue != null) {
Enumeration enumeration = enumProperty.getRange().asEnumeration();
entity.setValue(enumProperty.getName(), enumeration.parse(String.valueOf(enumValue)));
}
}
} catch (ParseException e) {
throw new RuntimeException("Unable to convert enum id to enum instance for EnumClass");
}
}
Aggregations