use of com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype in project cuba by cuba-platform.
the class DynamicAttributesGuiTools method getCustomNumberDatatype.
/**
* Returns custom {@link AdaptiveNumberDatatype} for dynamic attribute with specified {@code NumberFormatPattern}
*/
@Nullable
public Datatype getCustomNumberDatatype(CategoryAttribute attribute) {
if (attribute == null || attribute.getConfiguration().getNumberFormatPattern() == null || Boolean.TRUE.equals(attribute.getIsCollection())) {
return null;
}
DatatypeRegistry registry = AppBeans.get(DatatypeRegistry.NAME);
String pattern = attribute.getConfiguration().getNumberFormatPattern();
String datatypeId = "customRuntimeDatatype-" + pattern;
Class type;
if (PropertyType.DECIMAL.equals(attribute.getDataType())) {
type = BigDecimal.class;
} else {
type = Number.class;
}
Datatype datatype;
try {
datatype = registry.get(datatypeId);
} catch (IllegalArgumentException e) {
datatype = new AdaptiveNumberDatatype(type, pattern, "", "");
registry.register(datatype, datatypeId, false);
}
return datatype;
}
Aggregations