Search in sources :

Example 1 with GroupTable

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

the class GroupTableSettingsBinder method applyColumnSettings.

@Override
protected void applyColumnSettings(TableSettings tableSettings, Table table) {
    super.applyColumnSettings(tableSettings, table);
    GroupTableSettings groupTableSettings = (GroupTableSettings) tableSettings;
    List<String> groupProperties = groupTableSettings.getGroupProperties();
    if (groupProperties != null) {
        MetaClass metaClass = ((EntityTableItems) table.getItems()).getEntityMetaClass();
        List<MetaPropertyPath> properties = new ArrayList<>(groupProperties.size());
        for (String id : groupProperties) {
            MetaPropertyPath property = metadataTools.resolveMetaPropertyPathOrNull(metaClass, id);
            if (property != null) {
                properties.add(property);
            } else {
                log.warn("Ignored group property '{}'", id);
            }
        }
        ((GroupTable) table).groupBy(properties.toArray());
    } else {
        ((GroupTable) table).ungroup();
    }
}
Also used : GroupTable(io.jmix.ui.component.GroupTable) JmixGroupTable(io.jmix.ui.widget.JmixGroupTable) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) ArrayList(java.util.ArrayList) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems) GroupTableSettings(io.jmix.ui.settings.component.GroupTableSettings)

Example 2 with GroupTable

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

the class GroupTableLoader method loadColumns.

@Override
protected List<Table.Column> loadColumns(Table component, Element columnsElement, MetaClass metaClass, FetchPlan fetchPlan) {
    List<Table.Column> columns = super.loadColumns(component, columnsElement, metaClass, fetchPlan);
    Element groupElement = columnsElement.element("group");
    if (groupElement != null) {
        final List<Object> groupProperties = new ArrayList<>(columns.size());
        List<Element> columnElements = groupElement.elements("column");
        for (Element columnElement : columnElements) {
            String visible = columnElement.attributeValue("visible");
            if (StringUtils.isEmpty(visible) || Boolean.parseBoolean(visible)) {
                Object id = loadColumnId(columnElement, metaClass);
                Table.Column column = component.getColumn(id.toString());
                if (column == null) {
                    column = loadColumn(component, columnElement, metaClass);
                }
                if (column.isCollapsed()) {
                    String msg = String.format("Can't group by collapsed column: %s", column.getId());
                    throw new GuiDevelopmentException(msg, context);
                }
                if (column instanceof GroupTable.GroupColumn && ((GroupTable.GroupColumn<?>) column).isGroupAllowed()) {
                    groupProperties.add(column.getId());
                }
            }
        }
        getComponentContext().addPostInitTask((context1, window) -> {
            // enable grouping columns from descriptor if columnReorderingAllowed = false
            boolean reorderDisabled = !component.getColumnReorderingAllowed();
            component.setColumnReorderingAllowed(true);
            ((GroupTable) component).groupBy(groupProperties.toArray());
            if (reorderDisabled) {
                component.setColumnReorderingAllowed(false);
            }
        });
    }
    return columns;
}
Also used : GroupTable(io.jmix.ui.component.GroupTable) Table(io.jmix.ui.component.Table) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) GroupTable(io.jmix.ui.component.GroupTable) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Example 3 with GroupTable

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

the class GroupTableSettingsBinder method getSettings.

@Override
public GroupTableSettings getSettings(Table component) {
    GroupTable groupTable = (GroupTable) component;
    GroupTableSettings groupTableSettings = (GroupTableSettings) super.getSettings(component);
    List<String> groupProperties = getGroupProperties(groupTable);
    if (!groupProperties.isEmpty()) {
        groupTableSettings.setGroupProperties(groupProperties);
    }
    return groupTableSettings;
}
Also used : GroupTable(io.jmix.ui.component.GroupTable) JmixGroupTable(io.jmix.ui.widget.JmixGroupTable) GroupTableSettings(io.jmix.ui.settings.component.GroupTableSettings)

Example 4 with GroupTable

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

the class GroupTableSettingsBinder method saveSettings.

@Override
public boolean saveSettings(Table component, SettingsWrapper wrapper) {
    GroupTable groupTable = (GroupTable) component;
    GroupTableSettings groupTableSettings = wrapper.getSettings();
    boolean commonTableSettingsChanged = super.saveSettings(component, wrapper);
    boolean groupTableSettingsChanged = isGroupTableSettingsChanged(groupTable, groupTableSettings);
    if (!groupTableSettingsChanged && !commonTableSettingsChanged) {
        return false;
    }
    if (groupTableSettingsChanged) {
        // save columns settings if they were not saved
        if (groupTableSettings.getColumns() == null) {
            groupTableSettings.setColumns(getTableColumnSettings(groupTable));
        }
        groupTableSettings.setGroupProperties(getGroupProperties(groupTable));
    }
    return true;
}
Also used : GroupTable(io.jmix.ui.component.GroupTable) JmixGroupTable(io.jmix.ui.widget.JmixGroupTable) GroupTableSettings(io.jmix.ui.settings.component.GroupTableSettings)

Aggregations

GroupTable (io.jmix.ui.component.GroupTable)4 GroupTableSettings (io.jmix.ui.settings.component.GroupTableSettings)3 JmixGroupTable (io.jmix.ui.widget.JmixGroupTable)3 ArrayList (java.util.ArrayList)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)1 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)1 Table (io.jmix.ui.component.Table)1 EntityTableItems (io.jmix.ui.component.data.meta.EntityTableItems)1 Element (org.dom4j.Element)1