Search in sources :

Example 1 with GridSortOrder

use of com.vaadin.data.provider.GridSortOrder in project jmix by jmix-framework.

the class AbstractDataGridSettingsBinder method applyColumnSettings.

protected void applyColumnSettings(DataGrid dataGrid, DataGridSettings settings, Collection<DataGrid.Column> oldColumns) {
    Grid grid = getGrid(dataGrid);
    List<DataGridSettings.ColumnSettings> columnsSettings = CollectionUtils.isEmpty(settings.getColumns()) ? Collections.emptyList() : settings.getColumns();
    List<DataGrid.Column> newColumns = new ArrayList<>();
    // add columns from saved settings
    for (DataGridSettings.ColumnSettings columnSettings : columnsSettings) {
        for (DataGrid.Column column : oldColumns) {
            if (column.getId().equals(columnSettings.getId())) {
                newColumns.add(column);
                Double width = columnSettings.getWidth();
                if (width != null) {
                    column.setWidth(width);
                } else {
                    column.setWidthAuto();
                }
                Boolean collapsed = columnSettings.getCollapsed();
                if (collapsed != null && grid.isColumnReorderingAllowed()) {
                    column.setCollapsed(collapsed);
                }
                break;
            }
        }
    }
    // add columns not saved in settings (perhaps new)
    for (DataGrid.Column column : oldColumns) {
        if (!newColumns.contains(column)) {
            newColumns.add(column);
        }
    }
    // if the data grid contains only one column, always show it
    if (newColumns.size() == 1) {
        newColumns.get(0).setCollapsed(false);
    }
    // We don't save settings for columns hidden by security permissions,
    // so we need to return them back to they initial positions
    DataGridSettingsUtils.restoreColumnsOrder(dataGrid, newColumns);
    grid.setColumnOrder(newColumns.stream().map(DataGrid.Column::getId).toArray(String[]::new));
    if (dataGrid.isSortable() && !isApplyDataLoadingSettings(dataGrid)) {
        // apply sorting
        grid.clearSortOrder();
        String sortColumnId = settings.getSortColumnId();
        if (StringUtils.isNotEmpty(sortColumnId)) {
            Grid.Column column = grid.getColumn(sortColumnId);
            if (column != null) {
                DataGrid.SortDirection sortDirection = settings.getSortDirection();
                if (sortDirection != null) {
                    List<GridSortOrder> sortOrders = Collections.singletonList(new GridSortOrder(column, WrapperUtils.convertToGridSortDirection(sortDirection)));
                    grid.setSortOrder(sortOrders);
                }
            }
        }
    }
}
Also used : GridSortOrder(com.vaadin.data.provider.GridSortOrder) DataGrid(io.jmix.ui.component.DataGrid) Grid(com.vaadin.ui.Grid) DataGrid(io.jmix.ui.component.DataGrid) DataGridSettings(io.jmix.ui.settings.component.DataGridSettings)

Example 2 with GridSortOrder

use of com.vaadin.data.provider.GridSortOrder in project jmix by jmix-framework.

the class AbstractDataGridSettingsBinder method applyDataLoadingSettings.

@Override
public void applyDataLoadingSettings(DataGrid dataGrid, SettingsWrapper wrapper) {
    DataGridSettings dataGridSettings = wrapper.getSettings();
    if (dataGrid.isSortable() && isApplyDataLoadingSettings(dataGrid)) {
        if (dataGridSettings.getColumns() == null) {
            return;
        }
        String sortColumnId = dataGridSettings.getSortColumnId();
        if (StringUtils.isNotEmpty(sortColumnId)) {
            Grid grid = getGrid(dataGrid);
            Grid.Column column = grid.getColumn(sortColumnId);
            if (column != null) {
                if (dataGrid.getItems() instanceof DataGridItems.Sortable) {
                    ((DataGridItems.Sortable) dataGrid.getItems()).suppressSorting();
                }
                try {
                    grid.clearSortOrder();
                    DataGrid.SortDirection sortDirection = dataGridSettings.getSortDirection();
                    if (sortDirection != null) {
                        List<GridSortOrder> sortOrders = Collections.singletonList(new GridSortOrder<>(column, WrapperUtils.convertToGridSortDirection(sortDirection)));
                        grid.setSortOrder(sortOrders);
                    }
                } finally {
                    if (dataGrid.getItems() instanceof DataGridItems.Sortable) {
                        ((DataGridItems.Sortable) dataGrid.getItems()).enableSorting();
                    }
                }
            }
        }
    }
}
Also used : GridSortOrder(com.vaadin.data.provider.GridSortOrder) DataGrid(io.jmix.ui.component.DataGrid) Grid(com.vaadin.ui.Grid) DataGrid(io.jmix.ui.component.DataGrid) DataGridSettings(io.jmix.ui.settings.component.DataGridSettings)

Example 3 with GridSortOrder

use of com.vaadin.data.provider.GridSortOrder in project cuba by cuba-platform.

the class WebAbstractDataGrid method onSort.

protected void onSort(com.vaadin.event.SortEvent<GridSortOrder<E>> e) {
    if (component.getDataProvider() instanceof SortableDataProvider) {
        // noinspection unchecked
        SortableDataProvider<E> dataProvider = (SortableDataProvider<E>) component.getDataProvider();
        List<GridSortOrder<E>> sortOrders = e.getSortOrder();
        if (sortOrders.isEmpty()) {
            dataProvider.resetSortOrder();
        } else {
            GridSortOrder<E> sortOrder = sortOrders.get(0);
            Column<E> column = getColumnByGridColumn(sortOrder.getSorted());
            if (column != null) {
                MetaPropertyPath propertyPath = column.getPropertyPath();
                boolean ascending = com.vaadin.shared.data.sort.SortDirection.ASCENDING.equals(sortOrder.getDirection());
                dataProvider.sort(new Object[] { propertyPath }, new boolean[] { ascending });
            }
        }
    }
    List<SortOrder> sortOrders = convertToDataGridSortOrder(e.getSortOrder());
    SortEvent event = new SortEvent(WebAbstractDataGrid.this, sortOrders, e.isUserOriginated());
    publish(SortEvent.class, event);
}
Also used : GridSortOrder(com.vaadin.data.provider.GridSortOrder) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) GridSortOrder(com.vaadin.data.provider.GridSortOrder) SortableDataProvider(com.haulmont.cuba.web.widgets.data.SortableDataProvider)

Example 4 with GridSortOrder

use of com.vaadin.data.provider.GridSortOrder in project cuba by cuba-platform.

the class WebAbstractDataGrid method applyDataLoadingSettings.

public void applyDataLoadingSettings(Element element) {
    if (!isSettingsEnabled()) {
        return;
    }
    if (isSortable() && isApplyDataLoadingSettings()) {
        Element columnsElem = element.element("columns");
        if (columnsElem != null) {
            String sortColumnId = columnsElem.attributeValue("sortColumnId");
            if (!StringUtils.isEmpty(sortColumnId)) {
                Grid.Column<E, ?> column = component.getColumn(sortColumnId);
                if (column != null) {
                    if (getItems() instanceof DataGridItems.Sortable) {
                        ((DataGridItems.Sortable<E>) getItems()).suppressSorting();
                    }
                    try {
                        component.clearSortOrder();
                        String sortDirection = columnsElem.attributeValue("sortDirection");
                        if (StringUtils.isNotEmpty(sortDirection)) {
                            List<GridSortOrder<E>> sortOrders = Collections.singletonList(new GridSortOrder<>(column, com.vaadin.shared.data.sort.SortDirection.valueOf(sortDirection)));
                            component.setSortOrder(sortOrders);
                        }
                    } finally {
                        if (getItems() instanceof DataGridItems.Sortable) {
                            ((DataGridItems.Sortable<E>) getItems()).enableSorting();
                        }
                    }
                }
            }
        }
    }
}
Also used : GridSortOrder(com.vaadin.data.provider.GridSortOrder) Element(org.dom4j.Element) CubaEnhancedGrid(com.haulmont.cuba.web.widgets.CubaEnhancedGrid)

Example 5 with GridSortOrder

use of com.vaadin.data.provider.GridSortOrder in project cuba by cuba-platform.

the class WebAbstractDataGrid method applyColumnSettings.

protected void applyColumnSettings(Element element, Collection<Column<E>> oldColumns) {
    Element columnsElem = element.element("columns");
    List<Column<E>> newColumns = new ArrayList<>();
    // add columns from saved settings
    for (Element colElem : columnsElem.elements("columns")) {
        for (Column<E> column : oldColumns) {
            if (column.getId().equals(colElem.attributeValue("id"))) {
                newColumns.add(column);
                String width = colElem.attributeValue("width");
                if (width != null) {
                    column.setWidth(Double.parseDouble(width));
                } else {
                    column.setWidthAuto();
                }
                String collapsed = colElem.attributeValue("collapsed");
                if (collapsed != null && component.isColumnReorderingAllowed()) {
                    column.setCollapsed(Boolean.parseBoolean(collapsed));
                }
                break;
            }
        }
    }
    // add columns not saved in settings (perhaps new)
    for (Column<E> column : oldColumns) {
        if (!newColumns.contains(column)) {
            newColumns.add(column);
        }
    }
    // if the data grid contains only one column, always show it
    if (newColumns.size() == 1) {
        newColumns.get(0).setCollapsed(false);
    }
    // We don't save settings for columns hidden by security permissions,
    // so we need to return them back to they initial positions
    columnsOrder = restoreColumnsOrder(newColumns);
    component.setColumnOrder(newColumns.stream().map(Column::getId).toArray(String[]::new));
    if (isSortable() && !isApplyDataLoadingSettings()) {
        // apply sorting
        component.clearSortOrder();
        String sortColumnId = columnsElem.attributeValue("sortColumnId");
        if (!StringUtils.isEmpty(sortColumnId)) {
            Grid.Column<E, ?> column = component.getColumn(sortColumnId);
            if (column != null) {
                String sortDirection = columnsElem.attributeValue("sortDirection");
                if (StringUtils.isNotEmpty(sortDirection)) {
                    List<GridSortOrder<E>> sortOrders = Collections.singletonList(new GridSortOrder<>(column, com.vaadin.shared.data.sort.SortDirection.valueOf(sortDirection)));
                    component.setSortOrder(sortOrders);
                }
            }
        }
    }
}
Also used : GridSortOrder(com.vaadin.data.provider.GridSortOrder) Element(org.dom4j.Element) CubaEnhancedGrid(com.haulmont.cuba.web.widgets.CubaEnhancedGrid)

Aggregations

GridSortOrder (com.vaadin.data.provider.GridSortOrder)11 DataGridSettings (io.jmix.ui.settings.component.DataGridSettings)4 DataGrid (io.jmix.ui.component.DataGrid)3 Element (org.dom4j.Element)3 CubaEnhancedGrid (com.haulmont.cuba.web.widgets.CubaEnhancedGrid)2 Grid (com.vaadin.ui.Grid)2 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 SortableDataProvider (com.haulmont.cuba.web.widgets.data.SortableDataProvider)1 DataProvider (com.vaadin.data.provider.DataProvider)1 ListDataProvider (com.vaadin.data.provider.ListDataProvider)1 VaadinIcons (com.vaadin.icons.VaadinIcons)1 SortDirection (com.vaadin.shared.data.sort.SortDirection)1 Component (com.vaadin.ui.Component)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 DateRenderer (com.vaadin.ui.renderers.DateRenderer)1 HtmlRenderer (com.vaadin.ui.renderers.HtmlRenderer)1 ValoTheme (com.vaadin.ui.themes.ValoTheme)1 FacadeProvider (de.symeda.sormas.api.FacadeProvider)1 Captions (de.symeda.sormas.api.i18n.Captions)1 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)1