diff options
Diffstat (limited to 'server/src/com/vaadin/ui/Grid.java')
-rw-r--r-- | server/src/com/vaadin/ui/Grid.java | 65 |
1 files changed, 58 insertions, 7 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 4a52dba173..e093a99159 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -182,7 +182,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } /** - * An event that is fired when a column becomes hidden or unhidden. + * An event that is fired when a column's visibility changes. * * @since */ @@ -190,6 +190,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, private final Column column; private final boolean userOriginated; + private final boolean hidden; /** * Constructor for a column visibility change event. @@ -198,21 +199,25 @@ public class Grid extends AbstractComponent implements SelectionNotifier, * the grid from which this event originates * @param column * the column that changed its visibility + * @param hidden + * <code>true</code> if the column was hidden, + * <code>false</code> if it became visible * @param isUserOriginated * <code>true</code> iff the event was triggered by an UI * interaction */ public ColumnVisibilityChangeEvent(Grid source, Column column, - boolean isUserOriginated) { + boolean hidden, boolean isUserOriginated) { super(source); this.column = column; + this.hidden = hidden; userOriginated = isUserOriginated; } /** - * Gets the column that became hidden or unhidden. + * Gets the column that became hidden or visible. * - * @return the column that became hidden or unhidden. + * @return the column that became hidden or visible. * @see Column#isHidden() */ public Column getColumn() { @@ -220,6 +225,16 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } /** + * Was the column set hidden or visible. + * + * @return <code>true</code> if the column was hidden <code>false</code> + * if it was set visible + */ + public boolean isHidden() { + return hidden; + } + + /** * Returns <code>true</code> if the column reorder was done by the user, * <code>false</code> if not and it was triggered by server side code. * @@ -2828,7 +2843,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, if (hidden != getState().hidden) { getState().hidden = hidden; grid.markAsDirty(); - grid.fireColumnVisibilityChangeEvent(this, false); + grid.fireColumnVisibilityChangeEvent(this, hidden, false); } } @@ -3359,6 +3374,42 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } @Override + public void columnVisibilityChanged(String id, boolean hidden, + boolean userOriginated) { + final Column column = getColumnByColumnId(id); + final GridColumnState columnState = column.getState(); + + if (columnState.hidden != hidden) { + columnState.hidden = hidden; + + final String diffStateKey = "columns"; + ConnectorTracker connectorTracker = getUI() + .getConnectorTracker(); + JsonObject diffState = connectorTracker + .getDiffState(Grid.this); + + assert diffState.hasKey(diffStateKey) : "Field name has changed"; + Type type = null; + try { + type = (getState(false).getClass().getDeclaredField( + diffStateKey).getGenericType()); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } + EncodeResult encodeResult = JsonCodec.encode( + getState(false).columns, diffState, type, + connectorTracker); + + diffState.put(diffStateKey, encodeResult.getEncodedValue()); + + fireColumnVisibilityChangeEvent(column, hidden, + userOriginated); + } + } + + @Override public void sendDetailsComponents(int fetchId) { getRpcProxy(GridClientRpc.class).setDetailsConnectorChanges( detailComponentManager.getAndResetConnectorChanges(), @@ -5455,9 +5506,9 @@ public class Grid extends AbstractComponent implements SelectionNotifier, COLUMN_VISIBILITY_METHOD); } - private void fireColumnVisibilityChangeEvent(Column column, + private void fireColumnVisibilityChangeEvent(Column column, boolean hidden, boolean isUserOriginated) { - fireEvent(new ColumnVisibilityChangeEvent(this, column, + fireEvent(new ColumnVisibilityChangeEvent(this, column, hidden, isUserOriginated)); } |