Search in sources :

Example 1 with AdaptiveNumberDatatype

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;
}
Also used : DatatypeRegistry(com.haulmont.chile.core.datatypes.DatatypeRegistry) MetaClass(com.haulmont.chile.core.model.MetaClass) AdaptiveNumberDatatype(com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype) AdaptiveNumberDatatype(com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype) Datatype(com.haulmont.chile.core.datatypes.Datatype) Nullable(javax.annotation.Nullable)

Aggregations

Datatype (com.haulmont.chile.core.datatypes.Datatype)1 DatatypeRegistry (com.haulmont.chile.core.datatypes.DatatypeRegistry)1 AdaptiveNumberDatatype (com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 Nullable (javax.annotation.Nullable)1