Search in sources :

Example 26 with IColumn

use of org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn in project scout.rt by eclipse.

the class JsonTableTest method testIgnorableRowOrderChangedEvent.

/**
 * Response must not contain the row_order_changed event if the sort was triggered by the request
 */
@Test
public void testIgnorableRowOrderChangedEvent() throws JSONException {
    Table table = createTableFixture(5);
    JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
    jsonTable.toJson();
    IColumn column = table.getColumnSet().getFirstVisibleColumn();
    // ----------
    JsonEvent event = createJsonRowsSortedEvent(jsonTable.getColumnId(column), !column.isSortAscending());
    jsonTable.handleUiEvent(event);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "rowOrderChanged");
    assertTrue(responseEvents.size() == 0);
}
Also used : Table(org.eclipse.scout.rt.ui.html.json.table.fixtures.Table) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ListBoxTable(org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable) IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) Test(org.junit.Test)

Example 27 with IColumn

use of org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn 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 28 with IColumn

use of org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn in project scout.rt by eclipse.

the class AbstractTable method createColumnsInternal.

private void createColumnsInternal() {
    List<Class<? extends IColumn>> ca = getConfiguredColumns();
    OrderedCollection<IColumn<?>> columns = new OrderedCollection<IColumn<?>>();
    // configured columns
    for (Class<? extends IColumn> clazz : ca) {
        IColumn<?> column = ConfigurationUtility.newInnerInstance(this, clazz);
        columns.addOrdered(column);
    }
    // contributed columns
    List<IColumn> contributedColumns = m_contributionHolder.getContributionsByClass(IColumn.class);
    for (IColumn c : contributedColumns) {
        columns.addOrdered(c);
    }
    // dynamically injected columns
    injectColumnsInternal(columns);
    // move columns
    ExtensionUtility.moveModelObjects(columns);
    m_columnSet = new ColumnSet(this, columns.getOrderedList());
    if (getConfiguredCheckableColumn() != null) {
        AbstractBooleanColumn checkableColumn = getColumnSet().getColumnByClass(getConfiguredCheckableColumn());
        setCheckableColumn(checkableColumn);
    }
    PropertyChangeListener columnVisibleListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            // disable ui sort possible property if needed
            checkIfColumnPreventsUiSortForTable();
            // prevent invisible context column (because the UI does not know of invisible columns)
            checkIfContextColumnIsVisible();
        }
    };
    for (IColumn column : m_columnSet.getColumns()) {
        column.addPropertyChangeListener(IColumn.PROP_VISIBLE, columnVisibleListener);
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) AbstractBooleanColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractBooleanColumn) PropertyChangeListener(java.beans.PropertyChangeListener) IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) OrderedCollection(org.eclipse.scout.rt.platform.util.collection.OrderedCollection)

Example 29 with IColumn

use of org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn in project scout.rt by eclipse.

the class AbstractTable method resetColumnsInternal.

private void resetColumnsInternal(Set<String> options) {
    if (options.contains(IResetColumnsOption.SORTING)) {
        setSortValid(false);
    }
    if (options.contains(IResetColumnsOption.ORDER)) {
        TreeMap<CompositeObject, IColumn<?>> orderMap = new TreeMap<CompositeObject, IColumn<?>>();
        int index = 0;
        for (IColumn<?> col : getColumns()) {
            if (col.isDisplayable()) {
                orderMap.put(new CompositeObject(col.getOrder(), index), col);
                index++;
            }
        }
        getColumnSet().setVisibleColumns(orderMap.values());
    }
    if (options.contains(IResetColumnsOption.VISIBILITY)) {
        ArrayList<IColumn<?>> list = new ArrayList<IColumn<?>>();
        for (IColumn<?> col : getColumnSet().getAllColumnsInUserOrder()) {
            if (col.isDisplayable()) {
                boolean configuredVisible = ((AbstractColumn<?>) col).isInitialVisible();
                if (configuredVisible) {
                    list.add(col);
                }
            }
        }
        getColumnSet().setVisibleColumns(list);
    }
    if (options.contains(IResetColumnsOption.SORTING)) {
        getColumnSet().resetSortingAndGrouping();
    }
    if (options.contains(IResetColumnsOption.WIDTHS)) {
        for (IColumn<?> col : getColumns()) {
            if (col.isDisplayable()) {
                col.setWidth(col.getInitialWidth());
            }
        }
    }
    if (options.contains(IResetColumnsOption.BACKGROUND_EFFECTS)) {
        for (IColumn<?> col : getColumns()) {
            if (col instanceof INumberColumn) {
                ((INumberColumn) col).setBackgroundEffect(((INumberColumn) col).getInitialBackgroundEffect());
            }
        }
    }
    if (options.contains(IResetColumnsOption.FILTERS)) {
        removeUserRowFilters();
    }
}
Also used : CompositeObject(org.eclipse.scout.rt.platform.util.CompositeObject) INumberColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.INumberColumn) IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) AbstractColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractColumn)

Example 30 with IColumn

use of org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn in project scout.rt by eclipse.

the class AbstractTable method applyRowDecorations.

@SuppressWarnings("unchecked")
private void applyRowDecorations(Set<ITableRow> rows) {
    try {
        for (ITableRow tableRow : rows) {
            tableRow.setRowChanging(true);
            this.decorateRow(tableRow);
        }
        for (IColumn col : getColumns()) {
            col.decorateCells(CollectionUtility.arrayList(rows));
            // cell decorator on table
            for (ITableRow row : rows) {
                this.decorateCell(row, col);
            }
        }
    } catch (Exception ex) {
        LOG.error("Error occured while applying row decoration", ex);
    } finally {
        for (ITableRow tableRow : rows) {
            tableRow.setRowPropertiesChanged(false);
            tableRow.setRowChanging(false);
        }
    }
}
Also used : IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)

Aggregations

IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)49 ArrayList (java.util.ArrayList)10 TreeMap (java.util.TreeMap)8 CompositeObject (org.eclipse.scout.rt.platform.util.CompositeObject)7 Test (org.junit.Test)6 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)5 JSONObject (org.json.JSONObject)5 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)4 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)4 INumberColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.INumberColumn)3 HashMap (java.util.HashMap)2 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 ClientUIPreferences (org.eclipse.scout.rt.client.ui.ClientUIPreferences)1 IKeyStroke (org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke)1