*/
private boolean columnFootersVisible = false;
+ private GridColumn<T> lastFrozenColumn;
+
/**
* Base class for grid columns internally used by the Grid. The user should
* use {@link GridColumn} when creating new columns.
ColumnConfiguration conf = escalator.getColumnConfiguration();
conf.insertColumns(index, 1);
+
+ if (lastFrozenColumn != null
+ && ((AbstractGridColumn<T>) lastFrozenColumn)
+ .findIndexOfColumn() < index) {
+ refreshFrozenColumns();
+ }
}
/**
ColumnConfiguration conf = escalator.getColumnConfiguration();
conf.removeColumns(columnIndex, 1);
+
+ if (column.equals(lastFrozenColumn)) {
+ setLastFrozenColumn(null);
+ } else {
+ refreshFrozenColumns();
+ }
}
/**
escalator.getBody().insertRows(0, estimatedSize);
}
}
+
+ /**
+ * Sets the rightmost frozen column in the grid.
+ * <p>
+ * All columns up to and including the given column will be frozen in place
+ * when the grid is scrolled sideways.
+ *
+ * @param lastFrozenColumn
+ * the rightmost column to freeze, or <code>null</code> to not
+ * have any columns frozen
+ * @throws IllegalArgumentException
+ * if {@code lastFrozenColumn} is not a column from this grid
+ */
+ public void setLastFrozenColumn(GridColumn<T> lastFrozenColumn) {
+ this.lastFrozenColumn = lastFrozenColumn;
+ refreshFrozenColumns();
+ }
+
+ private void refreshFrozenColumns() {
+ final int frozenCount;
+ if (lastFrozenColumn != null) {
+ frozenCount = columns.indexOf(lastFrozenColumn) + 1;
+ if (frozenCount == 0) {
+ throw new IllegalArgumentException(
+ "The given column isn't attached to this grid");
+ }
+ } else {
+ frozenCount = 0;
+ }
+
+ escalator.getColumnConfiguration().setFrozenColumnCount(frozenCount);
+ }
+
+ /**
+ * Gets the rightmost frozen column in the grid.
+ * <p>
+ * <em>Note:</em> Most usually, this method returns the very value set with
+ * {@link #setLastFrozenColumn(GridColumn)}. This value, however, can be
+ * reset to <code>null</code> if the column is removed from this grid.
+ *
+ * @return the rightmost frozen column in the grid, or <code>null</code> if
+ * no columns are frozen.
+ */
+ public GridColumn<T> getLastFrozenColumn() {
+ return lastFrozenColumn;
+ }
}
if (stateChangeEvent.hasPropertyChanged("columnGroupRows")) {
updateColumnGroupsFromStateChangeEvent();
}
+
+ if (stateChangeEvent.hasPropertyChanged("lastFrozenColumnId")) {
+ String frozenColId = getState().lastFrozenColumnId;
+ if (frozenColId != null) {
+ CustomGridColumn column = columnIdToColumn.get(frozenColId);
+ assert column != null : "Column to be frozen could not be found (id:"
+ + frozenColId + ")";
+ getWidget().setLastFrozenColumn(column);
+ } else {
+ getWidget().setLastFrozenColumn(null);
+ }
+ }
}
/**
appendColumn(propertyId);
}
}
+
+ Object frozenPropertyId = columnKeys
+ .get(getState(false).lastFrozenColumnId);
+ if (!columns.containsKey(frozenPropertyId)) {
+ setLastFrozenPropertyId(null);
+ }
}
};
}
getState().columns.clear();
+ setLastFrozenPropertyId(null);
// Add columns
for (Object propertyId : datasource.getContainerPropertyIds()) {
return column;
}
+
+ /**
+ * Sets (or unsets) the rightmost frozen column in the grid.
+ * <p>
+ * All columns up to and including the given column will be frozen in place
+ * when the grid is scrolled sideways.
+ *
+ * @param lastFrozenColumn
+ * the rightmost column to freeze, or <code>null</code> to not
+ * have any columns frozen
+ * @throws IllegalArgumentException
+ * if {@code lastFrozenColumn} is not a column from this grid
+ */
+ void setLastFrozenColumn(GridColumn lastFrozenColumn) {
+ /*
+ * TODO: If and when Grid supports column reordering or insertion of
+ * columns before other columns, make sure to mention that adding
+ * columns before lastFrozenColumn will change the frozen column count
+ */
+
+ if (lastFrozenColumn == null) {
+ getState().lastFrozenColumnId = null;
+ } else if (columns.containsValue(lastFrozenColumn)) {
+ getState().lastFrozenColumnId = lastFrozenColumn.getState().id;
+ } else {
+ throw new IllegalArgumentException(
+ "The given column isn't attached to this grid");
+ }
+ }
+
+ /**
+ * Sets (or unsets) the rightmost frozen column in the grid.
+ * <p>
+ * All columns up to and including the indicated property will be frozen in
+ * place when the grid is scrolled sideways.
+ * <p>
+ * <em>Note:</em> If the container used by this grid supports a propertyId
+ * <code>null</code>, it can never be defined as the last frozen column, as
+ * a <code>null</code> parameter will always reset the frozen columns in
+ * Grid.
+ *
+ * @param propertyId
+ * the property id corresponding to the column that should be the
+ * last frozen column, or <code>null</code> to not have any
+ * columns frozen.
+ * @throws IllegalArgumentException
+ * if {@code lastFrozenColumn} is not a column from this grid
+ */
+ public void setLastFrozenPropertyId(Object propertyId) {
+ final GridColumn column;
+ if (propertyId == null) {
+ column = null;
+ } else {
+ column = getColumn(propertyId);
+ if (column == null) {
+ throw new IllegalArgumentException(
+ "property id does not exist.");
+ }
+ }
+ setLastFrozenColumn(column);
+ }
+
+ /**
+ * Gets the rightmost frozen column in the grid.
+ * <p>
+ * <em>Note:</em> Most often, this method returns the very value set with
+ * {@link #setLastFrozenPropertyId(Object)}. This value, however, can be
+ * reset to <code>null</code> if the column is detached from this grid.
+ *
+ * @return the rightmost frozen column in the grid, or <code>null</code> if
+ * no columns are frozen.
+ */
+ public Object getLastFrozenPropertyId() {
+ return columnKeys.get(getState().lastFrozenColumnId);
+ }
}
throw new IllegalStateException("Column no longer exists.");
}
}
+
+ /**
+ * Sets this column as the last frozen column in its grid.
+ *
+ * @throws IllegalArgumentException
+ * if the column is no longer attached to any grid
+ * @see Grid#setLastFrozenColumn(GridColumn)
+ */
+ public void setLastFrozenColumn() {
+ checkColumnIsAttached();
+ grid.setLastFrozenColumn(this);
+ }
}
assertTrue(state.columnGroupRows.size() == 3);
}
+ @Test
+ public void testFrozenColumnByPropertyId() {
+ assertNull("Grid should not start with a frozen column",
+ grid.getLastFrozenPropertyId());
+
+ Object propertyId = grid.getContainerDatasource()
+ .getContainerPropertyIds().iterator().next();
+ grid.setLastFrozenPropertyId(propertyId);
+ assertEquals(propertyId, grid.getLastFrozenPropertyId());
+
+ grid.getContainerDatasource().removeContainerProperty(propertyId);
+ assertNull(grid.getLastFrozenPropertyId());
+ }
+
private GridColumnState getColumnState(Object propertyId) {
String columnId = columnIdMapper.key(propertyId);
for (GridColumnState columnState : state.columns) {
* The column groups added to the grid
*/
public List<ColumnGroupRowState> columnGroupRows = new ArrayList<ColumnGroupRowState>();
+
+ /**
+ * The id for the last frozen column.
+ *
+ * @see GridColumnState#id
+ */
+ public String lastFrozenColumnId = null;
+
}
}
}, null, c);
+ createClickAction("Freeze", "Column" + c,
+ new Command<Grid, String>() {
+
+ @Override
+ public void execute(Grid grid, String value, Object data) {
+ grid.setLastFrozenPropertyId("Column" + data);
+ }
+ }, null, c);
+
}
}