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