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 /client | |
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 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/grid/Grid.java | 60 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/grid/GridConnector.java | 12 |
2 files changed, 72 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/grid/Grid.java b/client/src/com/vaadin/client/ui/grid/Grid.java index d76424ae31..90c8b60474 100644 --- a/client/src/com/vaadin/client/ui/grid/Grid.java +++ b/client/src/com/vaadin/client/ui/grid/Grid.java @@ -83,6 +83,8 @@ public class Grid<T> extends Composite { */ 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. @@ -560,6 +562,12 @@ public class Grid<T> extends Composite { ColumnConfiguration conf = escalator.getColumnConfiguration(); conf.insertColumns(index, 1); + + if (lastFrozenColumn != null + && ((AbstractGridColumn<T>) lastFrozenColumn) + .findIndexOfColumn() < index) { + refreshFrozenColumns(); + } } /** @@ -578,6 +586,12 @@ public class Grid<T> extends Composite { ColumnConfiguration conf = escalator.getColumnConfiguration(); conf.removeColumns(columnIndex, 1); + + if (column.equals(lastFrozenColumn)) { + setLastFrozenColumn(null); + } else { + refreshFrozenColumns(); + } } /** @@ -861,4 +875,50 @@ public class Grid<T> extends Composite { 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; + } } diff --git a/client/src/com/vaadin/client/ui/grid/GridConnector.java b/client/src/com/vaadin/client/ui/grid/GridConnector.java index 896a9998fb..befbc5a50b 100644 --- a/client/src/com/vaadin/client/ui/grid/GridConnector.java +++ b/client/src/com/vaadin/client/ui/grid/GridConnector.java @@ -125,6 +125,18 @@ public class GridConnector extends AbstractComponentConnector { 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); + } + } } /** |