Search in sources :

Example 1 with TableSettings

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

the class LegacyTableSettingsConverter method convertToComponentSettings.

@SuppressWarnings("unchecked")
@Override
public TableSettings convertToComponentSettings(Element settings) {
    TableSettings tableSettings = createSettings();
    tableSettings.setId(settings.attributeValue("name"));
    String textSelection = settings.attributeValue("textSelection");
    if (StringUtils.isNotBlank(textSelection)) {
        tableSettings.setTextSelection(Boolean.parseBoolean(textSelection));
    }
    String presentationId = settings.attributeValue("presentation");
    if (StringUtils.isNotBlank(presentationId) && tableSettings instanceof HasSettingsPresentation) {
        ((HasSettingsPresentation) tableSettings).setPresentationId(UuidProvider.fromString(presentationId));
    }
    Element columnsElem = settings.element("columns");
    if (columnsElem != null) {
        String sortProperty = columnsElem.attributeValue("sortProperty");
        if (StringUtils.isNotBlank(sortProperty)) {
            tableSettings.setSortProperty(sortProperty);
            String sortAscending = columnsElem.attributeValue("sortAscending");
            tableSettings.setSortAscending(Boolean.parseBoolean(sortAscending));
        }
        List<Element> columns = columnsElem.elements("columns");
        List<ColumnSettings> columnsSett = new ArrayList<>(columns.size());
        for (Element column : columns) {
            ColumnSettings columnSett = new ColumnSettings();
            columnSett.setId(column.attributeValue("id"));
            String width = column.attributeValue("width");
            if (StringUtils.isNotBlank(width)) {
                columnSett.setWidth(Integer.parseInt(width));
            }
            String visible = column.attributeValue("visible");
            if (StringUtils.isNotBlank(visible)) {
                columnSett.setVisible(Boolean.parseBoolean(visible));
            }
            columnsSett.add(columnSett);
        }
        tableSettings.setColumns(columnsSett);
    }
    return tableSettings;
}
Also used : CubaTableSettings(com.haulmont.cuba.settings.component.CubaTableSettings) TableSettings(io.jmix.ui.settings.component.TableSettings) HasSettingsPresentation(com.haulmont.cuba.settings.component.HasSettingsPresentation) ColumnSettings(io.jmix.ui.settings.component.TableSettings.ColumnSettings) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Example 2 with TableSettings

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

the class AbstractTableSettingsBinder method applyColumnSettings.

protected void applyColumnSettings(TableSettings tableSettings, Table table) {
    com.vaadin.v7.ui.Table vTable = getVTable(table);
    List<TableSettings.ColumnSettings> settingsColumns = CollectionUtils.isEmpty(tableSettings.getColumns()) ? Collections.emptyList() : tableSettings.getColumns();
    Object[] oldColumns = vTable.getVisibleColumns();
    List<Object> newColumns = new ArrayList<>();
    // add columns from saved settings
    for (TableSettings.ColumnSettings columnSetting : settingsColumns) {
        for (Object column : oldColumns) {
            if (column.toString().equals(columnSetting.getId())) {
                newColumns.add(column);
                Integer width = columnSetting.getWidth();
                vTable.setColumnWidth(column, width == null ? -1 : width);
                Boolean visible = columnSetting.getVisible();
                if (visible != null) {
                    if (vTable.isColumnCollapsingAllowed()) {
                        // throws exception if not
                        vTable.setColumnCollapsed(column, !visible);
                    }
                }
                break;
            }
        }
    }
    // add columns not saved in settings (perhaps new)
    for (Object column : oldColumns) {
        if (!newColumns.contains(column)) {
            newColumns.add(column);
        }
    }
    // if the table contains only one column, always show it
    if (newColumns.size() == 1) {
        if (vTable.isColumnCollapsingAllowed()) {
            // throws exception if not
            vTable.setColumnCollapsed(newColumns.get(0), false);
        }
    }
    vTable.setVisibleColumns(newColumns.toArray());
    EntityTableItems entityTableSource = (EntityTableItems) table.getItems();
    if (table.isSortable() && !isApplyDataLoadingSettings(table) && entityTableSource != null) {
        String sortProp = tableSettings.getSortProperty();
        if (!StringUtils.isEmpty(sortProp)) {
            MetaPropertyPath sortProperty = entityTableSource.getEntityMetaClass().getPropertyPath(sortProp);
            if (newColumns.contains(sortProperty)) {
                vTable.setSortContainerPropertyId(null);
                vTable.setSortAscending(Boolean.TRUE.equals(tableSettings.getSortAscending()));
                vTable.setSortContainerPropertyId(sortProperty);
            }
        } else {
            vTable.setSortContainerPropertyId(null);
        }
    }
}
Also used : TableSettings(io.jmix.ui.settings.component.TableSettings) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems)

Example 3 with TableSettings

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

the class AbstractTableSettingsBinder method getSettings.

@Override
public TableSettings getSettings(Table table) {
    TableSettings tableSettings = createTableSettings();
    tableSettings.setId(table.getId());
    tableSettings.setTextSelection(table.isTextSelectionEnabled());
    // get column settings
    tableSettings.setColumns(getTableColumnSettings(table));
    // get sort
    Table.SortInfo sortInfo = table.getSortInfo();
    if (sortInfo != null) {
        MetaPropertyPath sortProperty = (MetaPropertyPath) sortInfo.getPropertyId();
        if (sortProperty != null) {
            tableSettings.setSortProperty(sortProperty.toString());
            tableSettings.setSortAscending(sortInfo.getAscending());
        }
    }
    return tableSettings;
}
Also used : TableSettings(io.jmix.ui.settings.component.TableSettings) JmixEnhancedTable(io.jmix.ui.widget.JmixEnhancedTable) Table(io.jmix.ui.component.Table) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 4 with TableSettings

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

the class AbstractTableSettingsBinder method applyDataLoadingSettings.

@Override
public void applyDataLoadingSettings(Table table, SettingsWrapper wrapper) {
    EntityTableItems entityTableSource = (EntityTableItems) table.getItems();
    if (table.isSortable() && isApplyDataLoadingSettings(table) && entityTableSource != null) {
        TableSettings tableSettings = wrapper.getSettings();
        List<TableSettings.ColumnSettings> columns = tableSettings.getColumns();
        if (columns != null) {
            String sortProp = tableSettings.getSortProperty();
            if (sortProp != null) {
                List visibleColumns = Arrays.asList(getVTable(table).getVisibleColumns());
                MetaPropertyPath sortProperty = entityTableSource.getEntityMetaClass().getPropertyPath(sortProp);
                if (visibleColumns.contains(sortProperty)) {
                    if (table.getItems() instanceof TableItems.Sortable) {
                        ((TableItems.Sortable) table.getItems()).suppressSorting();
                    }
                    try {
                        com.vaadin.v7.ui.Table vTable = getVTable(table);
                        vTable.setSortContainerPropertyId(null);
                        vTable.setSortAscending(Boolean.TRUE.equals(tableSettings.getSortAscending()));
                        vTable.setSortContainerPropertyId(sortProperty);
                    } finally {
                        if (table.getItems() instanceof TableItems.Sortable) {
                            ((TableItems.Sortable) table.getItems()).enableSorting();
                        }
                    }
                }
            } else if (table.getSortInfo() != null) {
                TableItems tableItems = table.getItems();
                if (tableItems instanceof TableItems.Sortable) {
                    ((TableItems.Sortable) tableItems).resetSortOrder();
                }
            }
        }
    }
}
Also used : TableSettings(io.jmix.ui.settings.component.TableSettings) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems) TableItems(io.jmix.ui.component.data.TableItems) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems)

Example 5 with TableSettings

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

the class AbstractTableSettingsBinder method saveSettings.

@Override
public boolean saveSettings(Table table, SettingsWrapper wrapper) {
    TableSettings tableSettings = wrapper.getSettings();
    boolean settingsChanged = false;
    Boolean textSelection = tableSettings.getTextSelection();
    if (textSelection == null || BooleanUtils.toBoolean(textSelection) != table.isTextSelectionEnabled()) {
        tableSettings.setTextSelection(table.isTextSelectionEnabled());
        settingsChanged = true;
    }
    String settingsSortProperty = null;
    Boolean settingsSortAscending = null;
    if (tableSettings.getSortProperty() != null) {
        settingsSortProperty = tableSettings.getSortProperty();
        settingsSortAscending = tableSettings.getSortAscending();
    }
    boolean commonSettingsChanged = isCommonTableSettingsChanged(tableSettings, table);
    boolean sortChanged = isSettingsSortPropertyChanged(settingsSortProperty, settingsSortAscending, table.getSortInfo());
    if (commonSettingsChanged || sortChanged) {
        // save column settings
        tableSettings.setColumns(getTableColumnSettings(table));
        Table.SortInfo sortInfo = table.getSortInfo();
        if (sortInfo == null) {
            tableSettings.setSortProperty(null);
            tableSettings.setSortAscending(null);
        } else {
            MetaPropertyPath mpp = (MetaPropertyPath) sortInfo.getPropertyId();
            tableSettings.setSortProperty(mpp.toString());
            tableSettings.setSortAscending(sortInfo.getAscending());
        }
        settingsChanged = true;
    }
    return settingsChanged;
}
Also used : TableSettings(io.jmix.ui.settings.component.TableSettings) JmixEnhancedTable(io.jmix.ui.widget.JmixEnhancedTable) Table(io.jmix.ui.component.Table) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Aggregations

TableSettings (io.jmix.ui.settings.component.TableSettings)6 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)4 Table (io.jmix.ui.component.Table)2 EntityTableItems (io.jmix.ui.component.data.meta.EntityTableItems)2 JmixEnhancedTable (io.jmix.ui.widget.JmixEnhancedTable)2 CubaTableSettings (com.haulmont.cuba.settings.component.CubaTableSettings)1 HasSettingsPresentation (com.haulmont.cuba.settings.component.HasSettingsPresentation)1 TableItems (io.jmix.ui.component.data.TableItems)1 TablePresentationsLayout (io.jmix.ui.component.presentation.TablePresentationsLayout)1 ColumnSettings (io.jmix.ui.settings.component.TableSettings.ColumnSettings)1 ArrayList (java.util.ArrayList)1 Element (org.dom4j.Element)1