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)));
}
}
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);
}
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());
}
}
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);
}
}
}
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();
}
Aggregations