Search in sources :

Example 1 with Datatype

use of io.jmix.core.metamodel.datatype.Datatype 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 Datatype

use of io.jmix.core.metamodel.datatype.Datatype 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)

Example 3 with Datatype

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

the class ComponentLoaderHelper method loadTableColumnType.

public static void loadTableColumnType(io.jmix.ui.component.Table.Column column, Element element, ApplicationContext applicationContext) {
    if (!(column instanceof Table.Column)) {
        return;
    }
    if (column.getMetaPropertyPath() != null) {
        ((Table.Column<?>) column).setType(column.getMetaPropertyPath().getRangeJavaClass());
    }
    String type = element.attributeValue("type");
    if (StringUtils.isNotEmpty(type)) {
        DatatypeRegistry datatypeRegistry = applicationContext.getBean(DatatypeRegistry.class);
        Datatype datatype = datatypeRegistry.get(type);
        ((Table.Column<?>) column).setType(datatype.getJavaClass());
    }
}
Also used : DatatypeRegistry(io.jmix.core.metamodel.datatype.DatatypeRegistry) Datatype(io.jmix.core.metamodel.datatype.Datatype)

Example 4 with Datatype

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

the class DsContextLoader method loadProperties.

private void loadProperties(Element element, ValueDatasource datasource) {
    Element propsEl = element.element("properties");
    if (propsEl != null) {
        for (Element propEl : propsEl.elements()) {
            String name = propEl.attributeValue("name");
            String className = propEl.attributeValue("class");
            if (className != null) {
                datasource.addProperty(name, ReflectionHelper.getClass(className));
            } else {
                String typeName = propEl.attributeValue("datatype");
                Datatype datatype = typeName == null ? Datatypes.getNN(String.class) : Datatypes.get(typeName);
                datasource.addProperty(name, datatype);
            }
        }
        String idProperty = propsEl.attributeValue("idProperty");
        if (idProperty != null) {
            if (datasource.getMetaClass().findProperty(idProperty) == null)
                throw new DevelopmentException(String.format("Property '%s' is not defined", idProperty));
            datasource.setIdName(idProperty);
        }
    }
}
Also used : Element(org.dom4j.Element) Datatype(io.jmix.core.metamodel.datatype.Datatype) DevelopmentException(io.jmix.core.DevelopmentException)

Example 5 with Datatype

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

the class DatatypesControllerManager method getDatatypesJson.

public String getDatatypesJson() {
    JsonArray jsonArray = new JsonArray();
    try {
        for (String id : datatypes.getIds()) {
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("id", id);
            // for backward compatibility
            jsonObject.addProperty("name", id);
            Datatype datatype = datatypes.get(id);
            if (datatype instanceof ParameterizedDatatype) {
                Map<String, Object> parameters = ((ParameterizedDatatype) datatype).getParameters();
                for (Map.Entry<String, Object> entry : parameters.entrySet()) {
                    jsonObject.addProperty(entry.getKey(), entry.getValue().toString());
                }
            }
            jsonArray.add(jsonObject);
        }
    } catch (Exception e) {
        log.error("Fail to get datatype settings", e);
        throw new RestAPIException("Fail to get datatype settings", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR, e);
    }
    return jsonArray.toString();
}
Also used : JsonArray(com.google.gson.JsonArray) ParameterizedDatatype(io.jmix.core.metamodel.datatype.ParameterizedDatatype) JsonObject(com.google.gson.JsonObject) RestAPIException(io.jmix.rest.exception.RestAPIException) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) RestAPIException(io.jmix.rest.exception.RestAPIException) Datatype(io.jmix.core.metamodel.datatype.Datatype) ParameterizedDatatype(io.jmix.core.metamodel.datatype.ParameterizedDatatype)

Aggregations

Datatype (io.jmix.core.metamodel.datatype.Datatype)32 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)8 MetaClass (io.jmix.core.metamodel.model.MetaClass)7 Nullable (javax.annotation.Nullable)5 AdaptiveNumberDatatype (io.jmix.core.metamodel.datatype.impl.AdaptiveNumberDatatype)4 EnumClass (io.jmix.core.metamodel.datatype.impl.EnumClass)4 ParseException (java.text.ParseException)4 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)3 Range (io.jmix.core.metamodel.model.Range)3 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)3 DatatypeRegistry (com.haulmont.chile.core.datatypes.DatatypeRegistry)2 Metadata (com.haulmont.cuba.core.global.Metadata)2 Entity (io.jmix.core.Entity)2 DependsOnProperties (io.jmix.core.metamodel.annotation.DependsOnProperties)2 JmixProperty (io.jmix.core.metamodel.annotation.JmixProperty)2 EnumerationImpl (io.jmix.core.metamodel.datatype.impl.EnumerationImpl)2 RestAPIException (io.jmix.rest.exception.RestAPIException)2 ValueSource (io.jmix.ui.component.data.ValueSource)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2