Search in sources :

Example 6 with Formatter

use of io.jmix.ui.component.formatter.Formatter in project jmix by jmix-framework.

the class AbstractTableLoader method loadAggregation.

@SuppressWarnings("unchecked")
protected void loadAggregation(Table.Column column, Element columnElement) {
    Element aggregationElement = columnElement.element("aggregation");
    if (aggregationElement != null) {
        AggregationInfo aggregation = new AggregationInfo();
        aggregation.setPropertyPath((MetaPropertyPath) column.getId());
        String aggregationType = aggregationElement.attributeValue("type");
        if (StringUtils.isNotEmpty(aggregationType)) {
            aggregation.setType(AggregationInfo.Type.valueOf(aggregationType));
        }
        String aggregationEditable = aggregationElement.attributeValue("editable");
        if (StringUtils.isNotEmpty(aggregationEditable)) {
            aggregation.setEditable(Boolean.parseBoolean(aggregationEditable));
        }
        String valueDescription = aggregationElement.attributeValue("valueDescription");
        if (StringUtils.isNotEmpty(valueDescription)) {
            column.setValueDescription(loadResourceString(valueDescription));
        }
        Formatter formatter = loadFormatter(aggregationElement);
        aggregation.setFormatter(formatter == null ? column.getFormatter() : formatter);
        String strategyClass = aggregationElement.attributeValue("strategyClass");
        if (StringUtils.isNotEmpty(strategyClass)) {
            Class<?> aggregationClass = getClassManager().findClass(strategyClass);
            if (aggregationClass == null) {
                throw new GuiDevelopmentException(String.format("Class %s is not found", strategyClass), context);
            }
            try {
                Constructor<?> constructor = aggregationClass.getDeclaredConstructor();
                AggregationStrategy customStrategy = (AggregationStrategy) constructor.newInstance();
                applicationContext.getAutowireCapableBeanFactory().autowireBean(customStrategy);
                aggregation.setStrategy(customStrategy);
            } catch (Exception e) {
                throw new RuntimeException("Unable to instantiate strategy for aggregation", e);
            }
        }
        if (aggregationType == null && strategyClass == null) {
            throw new GuiDevelopmentException("Incorrect aggregation - type or strategyClass is required", context);
        }
        column.setAggregation(aggregation);
    }
}
Also used : Formatter(io.jmix.ui.component.formatter.Formatter) Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) AggregationInfo(io.jmix.ui.component.AggregationInfo) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) AggregationStrategy(io.jmix.ui.component.data.aggregation.AggregationStrategy)

Aggregations

Formatter (io.jmix.ui.component.formatter.Formatter)6 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)4 Element (org.dom4j.Element)4 Nullable (javax.annotation.Nullable)3 Strings (com.google.common.base.Strings)2 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)2 AttributeDefinition (io.jmix.dynattr.AttributeDefinition)2 MsgBundleTools (io.jmix.dynattr.MsgBundleTools)2 Iterables (com.google.common.collect.Iterables)1 Security (com.haulmont.cuba.core.global.Security)1 UiComponents (com.haulmont.cuba.gui.UiComponents)1 FieldGroup (com.haulmont.cuba.gui.components.FieldGroup)1 FieldCaptionAlignment (com.haulmont.cuba.gui.components.FieldGroup.FieldCaptionAlignment)1 FieldGroupFieldFactory (com.haulmont.cuba.gui.components.FieldGroupFieldFactory)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 DsContext (com.haulmont.cuba.gui.data.DsContext)1 EmbeddedDatasource (com.haulmont.cuba.gui.data.EmbeddedDatasource)1 DynamicAttributesGuiTools (com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools)1 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)1