summaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2015-02-18 10:05:25 +0200
committerPekka Hyvönen <pekka@vaadin.com>2015-02-18 12:23:23 +0200
commit9b2f51ca9ff48ad9484b8ee67770ab1a58352b35 (patch)
tree952a8f76a7e5003fd59daf0d1ebb17899ccd5f61 /server/src
parentf537b9fdb2ba3993090d22011adfe247e4e2b6bd (diff)
downloadvaadin-framework-9b2f51ca9ff48ad9484b8ee67770ab1a58352b35.tar.gz
vaadin-framework-9b2f51ca9ff48ad9484b8ee67770ab1a58352b35.zip
Update server side state when columns are reordered. (#16643)
Change-Id: I96c65dbb96614a5f5782b747fb8588647211cf4b
Diffstat (limited to 'server/src')
-rw-r--r--server/src/com/vaadin/ui/Grid.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index 764960606a..72a772713f 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -18,6 +18,7 @@ package com.vaadin.ui;
import java.io.Serializable;
import java.lang.reflect.Method;
+import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -70,6 +71,7 @@ import com.vaadin.event.SortEvent.SortListener;
import com.vaadin.event.SortEvent.SortNotifier;
import com.vaadin.server.AbstractClientConnector;
import com.vaadin.server.AbstractExtension;
+import com.vaadin.server.EncodeResult;
import com.vaadin.server.ErrorMessage;
import com.vaadin.server.JsonCodec;
import com.vaadin.server.KeyMapper;
@@ -3088,6 +3090,44 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
fireEvent(new ItemClickEvent(Grid.this, item, itemId,
propertyId, details));
}
+
+ @Override
+ public void columnsReordered(List<String> newColumnOrder,
+ List<String> oldColumnOrder) {
+ final String diffStateKey = "columnOrder";
+ ConnectorTracker connectorTracker = getUI()
+ .getConnectorTracker();
+ JsonObject diffState = connectorTracker.getDiffState(Grid.this);
+ // discard the change if the columns have been reordered from
+ // the server side, as the server side is always right
+ if (getState(false).columnOrder.equals(oldColumnOrder)) {
+ // Don't mark as dirty since client has the state already
+ getState(false).columnOrder = newColumnOrder;
+ // write changes to diffState so that possible reverting the
+ // column order is sent to client
+ 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).columnOrder, diffState, type,
+ connectorTracker);
+
+ diffState.put(diffStateKey, encodeResult.getEncodedValue());
+ // TODO fire column reorder event
+ } else {
+ // make sure the client is reverted to the order that the
+ // server thinks it is
+ diffState.remove(diffStateKey);
+ markAsDirty();
+ }
+ }
});
registerRpc(new EditorServerRpc() {