Search in sources :

Example 6 with Datatype

use of com.haulmont.chile.core.datatypes.Datatype in project cuba by cuba-platform.

the class TextAreaLoader method loadComponent.

@Override
public void loadComponent() {
    super.loadComponent();
    loadMaxLength(resultComponent, element);
    loadTrimming(resultComponent, element);
    loadInputPrompt(resultComponent, element);
    loadCaseConversion(resultComponent, element);
    loadTextChangeEventProperties(resultComponent, element);
    String cols = element.attributeValue("cols");
    if (StringUtils.isNotEmpty(cols)) {
        resultComponent.setColumns(Integer.parseInt(cols));
    }
    String rows = element.attributeValue("rows");
    if (StringUtils.isNotEmpty(rows)) {
        resultComponent.setRows(Integer.parseInt(rows));
    }
    String wordwrap = element.attributeValue("wordwrap");
    if (StringUtils.isNotEmpty(wordwrap)) {
        resultComponent.setWordwrap(Boolean.parseBoolean(wordwrap));
    }
    String datatypeAttribute = element.attributeValue("datatype");
    if (StringUtils.isNotEmpty(datatypeAttribute)) {
        Datatype datatype = Datatypes.get(datatypeAttribute);
        resultComponent.setDatatype(datatype);
    }
}
Also used : Datatype(com.haulmont.chile.core.datatypes.Datatype)

Example 7 with Datatype

use of com.haulmont.chile.core.datatypes.Datatype in project cuba by cuba-platform.

the class TextFieldLoader method loadComponent.

@Override
public void loadComponent() {
    super.loadComponent();
    loadMaxLength(resultComponent, element);
    loadTrimming(resultComponent, element);
    String datatypeAttribute = element.attributeValue("datatype");
    if (StringUtils.isNotEmpty(datatypeAttribute)) {
        Datatype datatype = Datatypes.get(datatypeAttribute);
        resultComponent.setDatatype(datatype);
    }
    resultComponent.setFormatter(loadFormatter(element));
    loadInputPrompt(resultComponent, element);
    loadCaseConversion(resultComponent, element);
    loadTextChangeEventProperties(resultComponent, element);
}
Also used : Datatype(com.haulmont.chile.core.datatypes.Datatype)

Example 8 with Datatype

use of com.haulmont.chile.core.datatypes.Datatype in project cuba by cuba-platform.

the class LinkColumnHelper method initColumn.

public static void initColumn(Table table, final String propertyName, final Handler handler) {
    final ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.NAME);
    table.addGeneratedColumn(propertyName, new Table.ColumnGenerator() {

        @Override
        public Component generateCell(final Entity entity) {
            // //process properties like building.house.room
            String[] props = propertyName.split("\\.");
            Instance nestedEntity = entity;
            for (int i = 0; i < props.length - 1; i++) {
                nestedEntity = nestedEntity.getValue(props[i]);
                if (nestedEntity == null) {
                    break;
                }
            }
            final Object value = (nestedEntity == null) ? null : nestedEntity.getValue(props[props.length - 1]);
            if (value != null) {
                Button button = componentsFactory.createComponent(Button.class);
                button.setStyleName("link");
                button.setAction(new AbstractAction("open") {

                    @Override
                    public void actionPerform(Component component) {
                        handler.onClick(entity);
                    }

                    @Override
                    public String getCaption() {
                        String str;
                        Datatype datatype = Datatypes.get(value.getClass());
                        if (datatype != null) {
                            UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
                            str = datatype.format(value, sessionSource.getLocale());
                        } else {
                            str = value.toString();
                        }
                        return str;
                    }
                });
                button.setStyleName("link");
                return button;
            }
            return null;
        }
    });
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Table(com.haulmont.cuba.gui.components.Table) Instance(com.haulmont.chile.core.model.Instance) Datatype(com.haulmont.chile.core.datatypes.Datatype) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Button(com.haulmont.cuba.gui.components.Button) Component(com.haulmont.cuba.gui.components.Component) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction)

Example 9 with Datatype

use of com.haulmont.chile.core.datatypes.Datatype in project cuba by cuba-platform.

the class MetaModelLoader method loadProperty.

protected MetadataObjectInfo<MetaProperty> loadProperty(MetaClassImpl metaClass, Field field) {
    Collection<RangeInitTask> tasks = new ArrayList<>();
    MetaPropertyImpl property = new MetaPropertyImpl(metaClass, field.getName());
    Range.Cardinality cardinality = getCardinality(field);
    Map<String, Object> map = new HashMap<>();
    map.put("cardinality", cardinality);
    boolean mandatory = isMandatory(field);
    map.put("mandatory", mandatory);
    Datatype datatype = getAdaptiveDatatype(field);
    map.put("datatype", datatype);
    String inverseField = getInverseField(field);
    if (inverseField != null)
        map.put("inverseField", inverseField);
    Class<?> type;
    Class typeOverride = getTypeOverride(field);
    if (typeOverride != null)
        type = typeOverride;
    else
        type = field.getType();
    property.setMandatory(mandatory);
    property.setReadOnly(!setterExists(field));
    property.setAnnotatedElement(field);
    property.setDeclaringClass(field.getDeclaringClass());
    MetadataObjectInfo<Range> info = loadRange(property, type, map);
    Range range = info.getObject();
    if (range != null) {
        ((AbstractRange) range).setCardinality(cardinality);
        property.setRange(range);
        assignPropertyType(field, property, range);
        assignInverse(property, range, inverseField);
    }
    if (info.getObject() != null && info.getObject().isEnum()) {
        property.setJavaType(info.getObject().asEnumeration().getJavaClass());
    } else {
        property.setJavaType(field.getType());
    }
    tasks.addAll(info.getTasks());
    return new MetadataObjectInfo<>(property, tasks);
}
Also used : AdaptiveNumberDatatype(com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype) Datatype(com.haulmont.chile.core.datatypes.Datatype)

Example 10 with Datatype

use of com.haulmont.chile.core.datatypes.Datatype in project cuba by cuba-platform.

the class MetaModelLoader method loadRange.

protected MetadataObjectInfo<Range> loadRange(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.get(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(metaProperty, type, map)));
    }
}
Also used : EnumerationImpl(com.haulmont.chile.core.datatypes.impl.EnumerationImpl) AdaptiveNumberDatatype(com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype) Datatype(com.haulmont.chile.core.datatypes.Datatype)

Aggregations

Datatype (com.haulmont.chile.core.datatypes.Datatype)27 ParseException (java.text.ParseException)9 Entity (com.haulmont.cuba.core.entity.Entity)6 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)6 Datatypes (com.haulmont.chile.core.datatypes.Datatypes)3 AdaptiveNumberDatatype (com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype)3 MetaClass (com.haulmont.chile.core.model.MetaClass)3 Element (org.dom4j.Element)3 Logger (org.slf4j.Logger)3 JsonObject (com.google.gson.JsonObject)2 EnumClass (com.haulmont.chile.core.datatypes.impl.EnumClass)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)2 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 Metadata (com.haulmont.cuba.core.global.Metadata)2 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)2 RestAPIException (com.haulmont.restapi.exception.RestAPIException)2 Map (java.util.Map)2 Inject (javax.inject.Inject)2 Document (org.dom4j.Document)2