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