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;
}
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);
}
}
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;
}
Aggregations