use of com.haulmont.cuba.gui.xml.DeclarativeColumnGenerator in project cuba by cuba-platform.
the class AbstractTableLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadEditable(resultComponent, element);
loadValidators(resultComponent, element);
loadSettingsEnabled(resultComponent, element);
loadAlign(resultComponent, element);
loadStyleName(resultComponent, element);
loadHeight(resultComponent, element);
loadWidth(resultComponent, element);
loadIcon(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadTabIndex(resultComponent, element);
loadSortable(resultComponent, element);
loadReorderingAllowed(resultComponent, element);
loadColumnControlVisible(resultComponent, element);
loadAggregatable(resultComponent, element);
loadAggregationStyle(resultComponent, element);
loadPresentations(resultComponent, element);
loadActions(resultComponent, element);
loadContextMenuEnabled(resultComponent, element);
loadMultiLineCells(resultComponent, element);
loadColumnHeaderVisible(resultComponent, element);
loadShowSelection(resultComponent, element);
loadTextSelectionEnabled(resultComponent, element);
loadResponsive(resultComponent, element);
Element columnsElement = element.element("columns");
Element rowsElement = element.element("rows");
if (rowsElement == null) {
throw new GuiDevelopmentException("Table doesn't have 'rows' element", context.getCurrentFrameId(), "Table ID", element.attributeValue("id"));
}
String rowHeaderMode = rowsElement.attributeValue("rowHeaderMode");
if (StringUtils.isBlank(rowHeaderMode)) {
rowHeaderMode = rowsElement.attributeValue("headerMode");
if (StringUtils.isNotBlank(rowHeaderMode)) {
Logger log = LoggerFactory.getLogger(AbstractTableLoader.class);
log.warn("Attribute headerMode is deprecated. Use rowHeaderMode.");
}
}
if (!StringUtils.isEmpty(rowHeaderMode)) {
resultComponent.setRowHeaderMode(Table.RowHeaderMode.valueOf(rowHeaderMode));
}
loadButtonsPanel(resultComponent);
// must be before datasource setting
loadRowsCount(resultComponent, element);
String datasource = rowsElement.attributeValue("datasource");
if (StringUtils.isBlank(datasource)) {
throw new GuiDevelopmentException("Table 'rows' element doesn't have 'datasource' attribute", context.getCurrentFrameId(), "Table ID", element.attributeValue("id"));
}
Datasource ds = context.getDsContext().get(datasource);
if (ds == null) {
throw new GuiDevelopmentException("Can't find datasource by name: " + datasource, context.getCurrentFrameId());
}
if (!(ds instanceof CollectionDatasource)) {
throw new GuiDevelopmentException("Not a CollectionDatasource: " + datasource, context.getCurrentFrameId());
}
CollectionDatasource cds = (CollectionDatasource) ds;
List<Table.Column> availableColumns;
if (columnsElement != null) {
availableColumns = loadColumns(resultComponent, columnsElement, cds);
} else {
availableColumns = new ArrayList<>();
}
for (Table.Column column : availableColumns) {
resultComponent.addColumn(column);
loadValidators(resultComponent, column);
loadRequired(resultComponent, column);
}
addDynamicAttributes(resultComponent, ds, availableColumns);
resultComponent.setDatasource(cds);
for (Table.Column column : availableColumns) {
if (column.getXmlDescriptor() != null) {
String generatorMethod = column.getXmlDescriptor().attributeValue("generator");
if (StringUtils.isNotEmpty(generatorMethod)) {
// noinspection unchecked
resultComponent.addGeneratedColumn(String.valueOf(column), new DeclarativeColumnGenerator(resultComponent, generatorMethod));
}
}
}
String multiselect = element.attributeValue("multiselect");
if (StringUtils.isNotEmpty(multiselect)) {
resultComponent.setMultiSelect(Boolean.parseBoolean(multiselect));
}
}
Aggregations