use of org.eclipse.scout.rt.client.ui.basic.table.ColumnSet 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.ColumnSet 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.ColumnSet in project scout.rt by eclipse.
the class ShowInvisibleColumnsFormTest method before.
@Before
public void before() {
m_column1 = mockColumn("column1", false);
m_column2 = mockColumn("column2", true);
m_column3 = mockColumn("column3", false);
m_column4 = mockColumn("column4", true);
m_tableMock = Mockito.mock(ITable.class);
ColumnSet mockColumnSet = Mockito.mock(ColumnSet.class);
Mockito.when(mockColumnSet.getAllColumnsInUserOrder()).thenReturn(CollectionUtility.arrayList(m_column3, m_column4, m_column1, m_column2));
Mockito.when(mockColumnSet.getColumns()).thenReturn(CollectionUtility.arrayList(m_column1, m_column2, m_column3, m_column4));
Mockito.when(m_tableMock.getColumnSet()).thenReturn(mockColumnSet);
}
Aggregations