@Override public void onStateChanged(final StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); initialChange = stateChangeEvent.isInitialStateChange(); // Column updates if (stateChangeEvent.hasPropertyChanged("columns")) { // Remove old columns purgeRemovedColumns(); // Add new columns for (GridColumnState state : getState().columns) { if (!columnIdToColumn.containsKey(state.id)) { addColumnFromStateChangeEvent(state); } updateColumnFromStateChangeEvent(state); } } if (stateChangeEvent.hasPropertyChanged("columnOrder")) { if (orderNeedsUpdate(getState().columnOrder)) { updateColumnOrderFromState(getState().columnOrder); } } // Header and footer if (stateChangeEvent.hasPropertyChanged("header")) { updateHeaderFromState(getState().header); } if (stateChangeEvent.hasPropertyChanged("footer")) { updateFooterFromState(getState().footer); } // Sorting if (stateChangeEvent.hasPropertyChanged("sortColumns") || stateChangeEvent.hasPropertyChanged("sortDirs")) { onSortStateChange(); } // Editor if (stateChangeEvent.hasPropertyChanged("editorEnabled")) { getWidget().setEditorEnabled(getState().editorEnabled); } // Frozen columns if (stateChangeEvent.hasPropertyChanged("frozenColumnCount")) { getWidget().setFrozenColumnCount(getState().frozenColumnCount); } // Theme features String activeTheme = getConnection().getUIConnector().getActiveTheme(); if (lastKnownTheme == null) { lastKnownTheme = activeTheme; } else if (!lastKnownTheme.equals(activeTheme)) { getWidget().resetSizesFromDom(); lastKnownTheme = activeTheme; } }
@Override protected void init() { super.init(); // All scroll RPC calls are executed finally to avoid issues on init registerRpc( GridClientRpc.class, new GridClientRpc() { @Override public void scrollToStart() { /* * no need for lazyDetailsScrollAdjuster, because the start is * always 0, won't change a bit. */ Scheduler.get() .scheduleFinally( new ScheduledCommand() { @Override public void execute() { getWidget().scrollToStart(); } }); } @Override public void scrollToEnd() { Scheduler.get() .scheduleFinally( new ScheduledCommand() { @Override public void execute() { getWidget().scrollToEnd(); // Scrolls further if details opens. lazyDetailsScroller.scrollToRow( dataSource.size() - 1, ScrollDestination.END); } }); } @Override public void scrollToRow(final int row, final ScrollDestination destination) { Scheduler.get() .scheduleFinally( new ScheduledCommand() { @Override public void execute() { getWidget().scrollToRow(row, destination); // Scrolls a bit further if details opens. lazyDetailsScroller.scrollToRow(row, destination); } }); } @Override public void recalculateColumnWidths() { getWidget().recalculateColumnWidths(); } }); /* Item click events */ getWidget().addBodyClickHandler(itemClickHandler); getWidget().addBodyDoubleClickHandler(itemClickHandler); /* Style Generators */ getWidget().setCellStyleGenerator(styleGenerator); getWidget().setRowStyleGenerator(styleGenerator); getWidget() .addSortHandler( new SortHandler<JsonObject>() { @Override public void sort(SortEvent<JsonObject> event) { List<SortOrder> order = event.getOrder(); String[] columnIds = new String[order.size()]; SortDirection[] directions = new SortDirection[order.size()]; for (int i = 0; i < order.size(); i++) { SortOrder sortOrder = order.get(i); CustomGridColumn column = (CustomGridColumn) sortOrder.getColumn(); columnIds[i] = column.id; directions[i] = sortOrder.getDirection(); } if (!Arrays.equals(columnIds, getState().sortColumns) || !Arrays.equals(directions, getState().sortDirs)) { // Report back to server if changed getRpcProxy(GridServerRpc.class) .sort(columnIds, directions, event.isUserOriginated()); } } }); getWidget().setEditorHandler(editorHandler); getWidget().addColumnReorderHandler(columnReorderHandler); getWidget().addColumnVisibilityChangeHandler(columnVisibilityChangeHandler); getWidget().addColumnResizeHandler(columnResizeHandler); ConnectorFocusAndBlurHandler.addHandlers(this); getWidget().setDetailsGenerator(customDetailsGenerator); getLayoutManager().registerDependency(this, getWidget().getElement()); layout(); }