Search in sources :

Example 1 with TableColumnState

use of org.eclipse.scout.rt.shared.services.common.bookmark.TableColumnState in project scout.rt by eclipse.

the class BookmarkUtility method backupTableColumns.

/**
 * Constructs a list of {@link TableColumnState} objects which describe the set of columns of the given {@link ITable}
 * .
 *
 * @param table
 *          The table with the columns to back-up.
 * @return A {@link List} of {@link TableColumnState} objects that can be restored via
 *         {@link #restoreTableColumns(ITable, List)}
 */
public static List<TableColumnState> backupTableColumns(ITable table) {
    ArrayList<TableColumnState> allColumns = new ArrayList<TableColumnState>();
    ColumnSet columnSet = table.getColumnSet();
    // add all columns but in user order
    for (IColumn<?> c : columnSet.getAllColumnsInUserOrder()) {
        TableColumnState colState = new TableColumnState();
        colState.setColumnClassName(c.getColumnId());
        colState.setDisplayable(c.isDisplayable());
        colState.setVisible(c.isDisplayable() && c.isVisible());
        colState.setWidth(c.getWidth());
        if (c instanceof INumberColumn) {
            colState.setAggregationFunction(((INumberColumn) c).getAggregationFunction());
            colState.setBackgroundEffect(((INumberColumn) c).getBackgroundEffect());
        }
        if (columnSet.isUserSortColumn(c)) {
            int sortOrder = columnSet.getSortColumnIndex(c);
            if (sortOrder >= 0) {
                colState.setSortOrder(sortOrder);
                colState.setSortAscending(c.isSortAscending());
                colState.setGroupingActive(c.isGroupingActive());
            } else {
                colState.setSortOrder(-1);
            }
        }
        allColumns.add(colState);
    }
    return allColumns;
}
Also used : INumberColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.INumberColumn) ArrayList(java.util.ArrayList) ColumnSet(org.eclipse.scout.rt.client.ui.basic.table.ColumnSet) TableColumnState(org.eclipse.scout.rt.shared.services.common.bookmark.TableColumnState)

Example 2 with TableColumnState

use of org.eclipse.scout.rt.shared.services.common.bookmark.TableColumnState in project scout.rt by eclipse.

the class BookmarkUtility method restoreTableColumns.

/**
 * Restores a tables columns from the given list of {@link TableColumnState} objects.
 *
 * @param table
 *          The table to be restored.
 * @param oldColumns
 *          A {@link List} of {@link TableColumnState} objects to restore. Such can be retrieved by the
 *          {@link #backupTableColumns(ITable)} method.
 */
public static void restoreTableColumns(ITable table, List<TableColumnState> oldColumns) {
    if (oldColumns != null && oldColumns.size() > 0 && table != null) {
        ColumnSet columnSet = table.getColumnSet();
        // visible columns and width
        ArrayList<IColumn> visibleColumns = new ArrayList<IColumn>();
        for (TableColumnState colState : oldColumns) {
            // legacy support: null=true
            if (colState.getVisible() == null || colState.getVisible()) {
                IColumn col = resolveColumn(columnSet.getDisplayableColumns(), colState.getClassName());
                if (col != null && col.isDisplayable()) {
                    if (colState.getWidth() > 0) {
                        col.setWidth(colState.getWidth());
                    }
                    visibleColumns.add(col);
                }
            }
        }
        List<IColumn<?>> existingVisibleCols = columnSet.getVisibleColumns();
        if (!existingVisibleCols.equals(visibleColumns)) {
            columnSet.setVisibleColumns(visibleColumns);
        }
        // aggregation functions and background effect:
        for (TableColumnState colState : oldColumns) {
            IColumn<?> col = BookmarkUtility.resolveColumn(columnSet.getColumns(), colState.getClassName());
            if (col instanceof INumberColumn) {
                if (colState.getAggregationFunction() != null) {
                    ((INumberColumn<?>) col).setAggregationFunction(colState.getAggregationFunction());
                }
                ((INumberColumn<?>) col).setBackgroundEffect(colState.getBackgroundEffect());
            }
        }
        // sort order (only respect visible and user-sort columns)
        boolean userSortValid = true;
        TreeMap<Integer, IColumn> sortColMap = new TreeMap<Integer, IColumn>();
        HashMap<IColumn<?>, TableColumnState> sortColToColumnState = new HashMap<>();
        HashSet<IColumn<?>> groupedCols = new HashSet<>();
        for (TableColumnState colState : oldColumns) {
            if (colState.getSortOrder() >= 0) {
                IColumn col = BookmarkUtility.resolveColumn(columnSet.getColumns(), colState.getClassName());
                if (col != null) {
                    sortColMap.put(colState.getSortOrder(), col);
                    sortColToColumnState.put(col, colState);
                    if (colState.isGroupingActive()) {
                        groupedCols.add(col);
                    }
                    if (col.getSortIndex() != colState.getSortOrder()) {
                        userSortValid = false;
                    }
                    if (col.isSortAscending() != colState.isSortAscending()) {
                        userSortValid = false;
                    }
                    if (col.isGroupingActive() != colState.isGroupingActive()) {
                        userSortValid = false;
                    }
                }
            }
        }
        if (!sortColMap.values().containsAll(columnSet.getUserSortColumns())) {
            userSortValid = false;
        }
        if (userSortValid) {
            HashSet<IColumn<?>> existingGroupedUserSortCols = new HashSet<>();
            // check if grouping is valid also:
            for (IColumn<?> c : columnSet.getUserSortColumns()) {
                if (c.isGroupingActive()) {
                    existingGroupedUserSortCols.add(c);
                }
            }
            if (!groupedCols.containsAll(existingGroupedUserSortCols)) {
                userSortValid = false;
            }
        }
        if (!userSortValid) {
            columnSet.clearSortColumns();
            boolean groupingPossible = true;
            for (IColumn<?> headSortColumn : columnSet.getPermanentHeadSortColumns()) {
                if (!headSortColumn.isVisible() || !headSortColumn.isGroupingActive()) {
                    TableColumnState state = sortColToColumnState.get(headSortColumn);
                    if (state != null && !state.isGroupingActive()) {
                        groupingPossible = false;
                        break;
                    }
                }
            }
            for (IColumn<?> col : sortColMap.values()) {
                TableColumnState state = sortColToColumnState.get(col);
                if (groupingPossible) {
                    if (state.isGroupingActive()) {
                        columnSet.addGroupingColumn(col, state.isSortAscending());
                    } else {
                        columnSet.addSortColumn(col, state.isSortAscending());
                        groupingPossible = false;
                    }
                } else {
                    columnSet.addSortColumn(col, state.isSortAscending());
                }
            }
            table.sort();
        }
        ClientUIPreferences.getInstance().setAllTableColumnPreferences(table);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ColumnSet(org.eclipse.scout.rt.client.ui.basic.table.ColumnSet) TreeMap(java.util.TreeMap) TableColumnState(org.eclipse.scout.rt.shared.services.common.bookmark.TableColumnState) INumberColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.INumberColumn) IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) HashSet(java.util.HashSet)

Example 3 with TableColumnState

use of org.eclipse.scout.rt.shared.services.common.bookmark.TableColumnState in project scout.rt by eclipse.

the class BookmarkUtility method bmStoreTablePage.

private static TablePageState bmStoreTablePage(IPageWithTable page, IPage<?> childPage) {
    ITable table = page.getTable();
    TablePageState state = new TablePageState();
    state.setPageClassName(page.getClass().getName());
    IBookmarkAdapter bookmarkAdapter = getBookmarkAdapter(page);
    state.setBookmarkIdentifier(bookmarkAdapter.getIdentifier());
    state.setLabel(bookmarkAdapter.getText());
    state.setExpanded(page.isExpanded());
    IForm searchForm = page.getSearchFormInternal();
    if (searchForm != null) {
        state.setSearchFormState(searchForm.storeToXmlString());
        state.setSearchFilterState(searchForm.getSearchFilter().isCompleted(), "" + createSearchFilterCRC(searchForm.getSearchFilter()));
    }
    if (page.getTable().getTableCustomizer() != null) {
        state.setTableCustomizerData(page.getTable().getTableCustomizer().getSerializedData());
    }
    if (page.getTable().getUserFilterManager() != null) {
        state.setUserFilterData(page.getTable().getUserFilterManager().getSerializedData());
    }
    List<TableColumnState> allColumns = backupTableColumns(page.getTable());
    state.setAvailableColumns(allColumns);
    // 
    ArrayList<CompositeObject> pkList = new ArrayList<CompositeObject>();
    for (ITableRow row : table.getSelectedRows()) {
        pkList.add(new CompositeObject(BookmarkUtility.makeSerializableKeys(row.getKeyValues(), false)));
    }
    state.setSelectedChildrenPrimaryKeys(pkList);
    // 
    if (childPage != null) {
        for (int j = 0; j < table.getRowCount(); j++) {
            if (page.getChildNode(j) == childPage) {
                ITableRow childRow = table.getRow(j);
                state.setExpandedChildPrimaryKey(new CompositeObject(BookmarkUtility.makeSerializableKeys(childRow.getKeyValues(), false)));
                break;
            }
        }
    }
    return state;
}
Also used : CompositeObject(org.eclipse.scout.rt.platform.util.CompositeObject) IBookmarkAdapter(org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter) ArrayList(java.util.ArrayList) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) IForm(org.eclipse.scout.rt.client.ui.form.IForm) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) TablePageState(org.eclipse.scout.rt.shared.services.common.bookmark.TablePageState) TableColumnState(org.eclipse.scout.rt.shared.services.common.bookmark.TableColumnState)

Aggregations

ArrayList (java.util.ArrayList)3 TableColumnState (org.eclipse.scout.rt.shared.services.common.bookmark.TableColumnState)3 ColumnSet (org.eclipse.scout.rt.client.ui.basic.table.ColumnSet)2 INumberColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.INumberColumn)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 IBookmarkAdapter (org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter)1 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)1 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)1 IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)1 IForm (org.eclipse.scout.rt.client.ui.form.IForm)1 CompositeObject (org.eclipse.scout.rt.platform.util.CompositeObject)1 TablePageState (org.eclipse.scout.rt.shared.services.common.bookmark.TablePageState)1