Search in sources :

Example 1 with Enumeration

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);
    }
}
Also used : Enumeration(io.jmix.core.metamodel.datatype.Enumeration) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Range(io.jmix.core.metamodel.model.Range)

Example 2 with Enumeration

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");
    }
}
Also used : Enumeration(io.jmix.core.metamodel.datatype.Enumeration) ParseException(java.text.ParseException) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Aggregations

Enumeration (io.jmix.core.metamodel.datatype.Enumeration)2 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 Range (io.jmix.core.metamodel.model.Range)1 ParseException (java.text.ParseException)1