summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2015-03-22 22:20:57 +0200
committerPekka Hyvönen <pekka@vaadin.com>2015-03-22 22:20:57 +0200
commit16c67cfab9b3dd2dbf324caa612fa3a2d15550d0 (patch)
tree028c2f0acd484b9cd93131d5972eae8d36c580bc /server
parent8d5b8042358e8eea8db30a3114cd02993244abb2 (diff)
downloadvaadin-framework-16c67cfab9b3dd2dbf324caa612fa3a2d15550d0.tar.gz
vaadin-framework-16c67cfab9b3dd2dbf324caa612fa3a2d15550d0.zip
Grid column hiding info from client to server #(17023)
Fixes mismatched client-server API regarding ColumnVisibilityChangeEvent Adds and removes the column hiding toggle as needed when columns added / removed. Known bug when a hidable column added, column toggle won't get the caption of column. Change-Id: I708e19432dc822f713bf11f5b8e6eadb528a3961
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/Grid.java65
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));
}