Search in sources :

Example 1 with EnumerationImpl

use of io.jmix.core.metamodel.datatype.impl.EnumerationImpl in project jmix by jmix-framework.

the class MetaModelLoader method loadRange.

@SuppressWarnings("unchecked")
protected MetadataObjectInfo<Range> loadRange(Session session, MetaProperty metaProperty, Class<?> type, Map<String, Object> map) {
    Datatype datatype = (Datatype) map.get("datatype");
    if (datatype != null) {
        // A datatype is assigned explicitly
        return new MetadataObjectInfo<>(new DatatypeRange(datatype));
    }
    datatype = getAdaptiveDatatype(metaProperty, type);
    if (datatype == null) {
        datatype = datatypes.find(type);
    }
    if (datatype != null) {
        MetaClass metaClass = metaProperty.getDomain();
        Class<?> javaClass = metaClass.getJavaClass();
        try {
            String name = "get" + StringUtils.capitalize(metaProperty.getName());
            Method method = javaClass.getMethod(name);
            Class<Enum> returnType = (Class<Enum>) method.getReturnType();
            if (returnType.isEnum()) {
                return new MetadataObjectInfo<>(new EnumerationRange(new EnumerationImpl<>(returnType)));
            }
        } catch (NoSuchMethodException e) {
        // ignore
        }
        return new MetadataObjectInfo<>(new DatatypeRange(datatype));
    } else if (type.isEnum()) {
        return new MetadataObjectInfo<>(new EnumerationRange(new EnumerationImpl(type)));
    } else {
        return new MetadataObjectInfo<>(null, Collections.singletonList(new RangeInitTask(session, metaProperty, type, map)));
    }
}
Also used : EnumerationImpl(io.jmix.core.metamodel.datatype.impl.EnumerationImpl) AdaptiveNumberDatatype(io.jmix.core.metamodel.datatype.impl.AdaptiveNumberDatatype) Datatype(io.jmix.core.metamodel.datatype.Datatype)

Example 2 with EnumerationImpl

use of io.jmix.core.metamodel.datatype.impl.EnumerationImpl in project jmix by jmix-framework.

the class KeyValueMetaPropertyBuilder method build.

public KeyValueMetaProperty build(MetaClass metaClass, String name, Class javaClass) {
    MetaProperty.Type type;
    Range range;
    Session metadataSession = metadata.getSession();
    if (Entity.class.isAssignableFrom(javaClass)) {
        range = new ClassRange(metadataSession.findClass(javaClass));
        type = MetaProperty.Type.ASSOCIATION;
    } else if (EnumClass.class.isAssignableFrom(javaClass)) {
        @SuppressWarnings("unchecked") EnumerationImpl enumeration = new EnumerationImpl(javaClass);
        range = new EnumerationRange(enumeration);
        type = MetaProperty.Type.ENUM;
    } else {
        @SuppressWarnings("unchecked") Datatype datatype = datatypeRegistry.get(javaClass);
        range = new DatatypeRange(datatype);
        type = MetaProperty.Type.DATATYPE;
    }
    return new KeyValueMetaProperty(metaClass, name, javaClass, range, type);
}
Also used : ClassRange(io.jmix.core.metamodel.model.impl.ClassRange) EnumerationImpl(io.jmix.core.metamodel.datatype.impl.EnumerationImpl) EnumClass(io.jmix.core.metamodel.datatype.impl.EnumClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) EnumerationRange(io.jmix.core.metamodel.model.impl.EnumerationRange) ClassRange(io.jmix.core.metamodel.model.impl.ClassRange) Range(io.jmix.core.metamodel.model.Range) DatatypeRange(io.jmix.core.metamodel.model.impl.DatatypeRange) EnumerationRange(io.jmix.core.metamodel.model.impl.EnumerationRange) DatatypeRange(io.jmix.core.metamodel.model.impl.DatatypeRange) Session(io.jmix.core.metamodel.model.Session) Datatype(io.jmix.core.metamodel.datatype.Datatype)

Aggregations

Datatype (io.jmix.core.metamodel.datatype.Datatype)2 EnumerationImpl (io.jmix.core.metamodel.datatype.impl.EnumerationImpl)2 AdaptiveNumberDatatype (io.jmix.core.metamodel.datatype.impl.AdaptiveNumberDatatype)1 EnumClass (io.jmix.core.metamodel.datatype.impl.EnumClass)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 Range (io.jmix.core.metamodel.model.Range)1 Session (io.jmix.core.metamodel.model.Session)1 ClassRange (io.jmix.core.metamodel.model.impl.ClassRange)1 DatatypeRange (io.jmix.core.metamodel.model.impl.DatatypeRange)1 EnumerationRange (io.jmix.core.metamodel.model.impl.EnumerationRange)1