use of org.eclipse.scout.rt.client.ui.basic.table.columns.INumberColumn in project scout.rt by eclipse.
the class ColumnSet method applySortingAndGroupingInternal.
private void applySortingAndGroupingInternal(Map<IColumn, P_SortingAndGroupingConfig> columnConfigs) {
TreeMap<CompositeObject, IColumn> sortMap = new TreeMap<CompositeObject, IColumn>();
int index = 0;
for (IColumn col : getColumns()) {
int sortIndex = -1;
if (col.isInitialAlwaysIncludeSortAtBegin()) {
sortIndex = col.getInitialSortIndex();
if (sortIndex < 0) {
LOG.warn("AlwaysIncludeSortAtBegin is set but no sort index configured. Table: {}", m_table.getClass().getName());
}
} else if (col.isInitialAlwaysIncludeSortAtEnd()) {
sortIndex = col.getInitialSortIndex();
if (sortIndex < 0) {
LOG.warn("AlwaysIncludeSortAtEnd is set but no sort index configured. Table: {}", m_table.getClass().getName());
}
} else {
sortIndex = columnConfigs.get(col).getSortIndex();
}
if (sortIndex >= 0) {
sortMap.put(new CompositeObject(sortIndex, index), col);
}
// aggregation function:
if (col instanceof INumberColumn) {
((INumberColumn) col).setAggregationFunction(columnConfigs.get(col).getAggregationFunction());
}
index++;
}
clearSortColumns();
clearPermanentHeadSortColumns();
clearPermanentTailSortColumns();
boolean asc;
for (IColumn col : sortMap.values()) {
if (col.isInitialAlwaysIncludeSortAtBegin()) {
asc = col.isInitialSortAscending();
addPermanentHeadSortColumn(col, asc);
} else if (col.isInitialAlwaysIncludeSortAtEnd()) {
asc = col.isInitialSortAscending();
addPermanentTailSortColumn(col, asc);
} else {
asc = columnConfigs.get(col).isAscending();
addSortColumn(col, asc);
}
}
applyGrouping(columnConfigs);
}
use of org.eclipse.scout.rt.client.ui.basic.table.columns.INumberColumn in project scout.rt by eclipse.
the class ColumnSet method createSortingAndGroupingConfig.
private P_SortingAndGroupingConfig createSortingAndGroupingConfig(IColumn<?> col, String configName) {
if (col.isInitialAlwaysIncludeSortAtBegin() || col.isInitialAlwaysIncludeSortAtEnd()) {
return createSortingAndGroupingConfig(col);
}
P_SortingAndGroupingConfig config = new P_SortingAndGroupingConfig();
ClientUIPreferences prefs = ClientUIPreferences.getInstance();
config.setSortIndex(prefs.getTableColumnSortIndex(col, col.getInitialSortIndex(), configName));
config.setAscending(prefs.getTableColumnSortAscending(col, col.isInitialSortAscending(), configName));
config.setGrouped(prefs.getTableColumnGrouped(col, col.isInitialGrouped(), configName));
if (col instanceof INumberColumn) {
config.setAggregationFunction(prefs.getTableColumnAggregationFunction(col, ((INumberColumn) col).getInitialAggregationFunction(), configName));
}
return config;
}
use of org.eclipse.scout.rt.client.ui.basic.table.columns.INumberColumn 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;
}
use of org.eclipse.scout.rt.client.ui.basic.table.columns.INumberColumn 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);
}
}
use of org.eclipse.scout.rt.client.ui.basic.table.columns.INumberColumn 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();
}
}
Aggregations