diff options
author | Henrik Paul <henrik@vaadin.com> | 2013-11-24 16:38:16 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-11-24 15:16:21 +0000 |
commit | cff79054fb76f472eaf3d53d4da27fff6d1a95f7 (patch) | |
tree | e3576d537ce095493b868b2a9bd8f53bfbb04a69 /server/src | |
parent | 69e0aac03c38f6cef4ef68f86b9450b5935c99a6 (diff) | |
download | vaadin-framework-cff79054fb76f472eaf3d53d4da27fff6d1a95f7.tar.gz vaadin-framework-cff79054fb76f472eaf3d53d4da27fff6d1a95f7.zip |
Add server-side API for column freezing (#3087)
Change-Id: I4704ab2bd2b1af31b4586e26cf89f03d97f136a4
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/com/vaadin/ui/components/grid/Grid.java | 82 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/components/grid/GridColumn.java | 12 |
2 files changed, 94 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/components/grid/Grid.java b/server/src/com/vaadin/ui/components/grid/Grid.java index 79cc05e1a0..1fb0692104 100644 --- a/server/src/com/vaadin/ui/components/grid/Grid.java +++ b/server/src/com/vaadin/ui/components/grid/Grid.java @@ -105,6 +105,12 @@ public class Grid extends AbstractComponent { appendColumn(propertyId); } } + + Object frozenPropertyId = columnKeys + .get(getState(false).lastFrozenColumnId); + if (!columns.containsKey(frozenPropertyId)) { + setLastFrozenPropertyId(null); + } } }; @@ -158,6 +164,7 @@ public class Grid extends AbstractComponent { } getState().columns.clear(); + setLastFrozenPropertyId(null); // Add columns for (Object propertyId : datasource.getContainerPropertyIds()) { @@ -362,4 +369,79 @@ public class Grid extends AbstractComponent { 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); + } } diff --git a/server/src/com/vaadin/ui/components/grid/GridColumn.java b/server/src/com/vaadin/ui/components/grid/GridColumn.java index dde0669238..8dae9428e5 100644 --- a/server/src/com/vaadin/ui/components/grid/GridColumn.java +++ b/server/src/com/vaadin/ui/components/grid/GridColumn.java @@ -192,4 +192,16 @@ public class GridColumn implements Serializable { 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); + } } |