aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2016-11-29 16:43:25 +0200
committerPekka Hyvönen <pekka@vaadin.com>2016-11-30 14:24:12 +0200
commit2de9aca9e5f9fe0d637f05c7198a93f93e0689e1 (patch)
tree1e203674a81608526546d6b100ed231f0f979eef /server
parentc3ad14183d72ed48088b7a5bb528e896a9797e32 (diff)
downloadvaadin-framework-2de9aca9e5f9fe0d637f05c7198a93f93e0689e1.tar.gz
vaadin-framework-2de9aca9e5f9fe0d637f05c7198a93f93e0689e1.zip
Add AbstractSelectionModel for Grid
Also adds shared state for grid's selection models. This is mostly for making it possible later to modify the selection models, without breaking backwards API compatibility and having to duplicate code. Change-Id: If93720df282bf5ca3aff17a20b455d60b33f764c
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/AbstractSelectionModel.java62
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java22
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModelImpl.java34
3 files changed, 75 insertions, 43 deletions
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/AbstractSelectionModel.java b/server/src/main/java/com/vaadin/ui/components/grid/AbstractSelectionModel.java
new file mode 100644
index 0000000000..dc8ee18f3a
--- /dev/null
+++ b/server/src/main/java/com/vaadin/ui/components/grid/AbstractSelectionModel.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.ui.components.grid;
+
+import com.vaadin.shared.data.DataCommunicatorConstants;
+import com.vaadin.shared.ui.grid.AbstractSelectionModelState;
+import com.vaadin.ui.Grid.AbstractGridExtension;
+import com.vaadin.ui.Grid.GridSelectionModel;
+
+import elemental.json.JsonObject;
+
+/**
+ * Abstract selection model for grid.
+ *
+ * @author Vaadin Ltd
+ *
+ * @since 8.0
+ *
+ * @param <T>
+ * the type of the items in grid.
+ */
+public abstract class AbstractSelectionModel<T> extends AbstractGridExtension<T>
+ implements GridSelectionModel<T> {
+
+ @Override
+ public void generateData(T item, JsonObject jsonObject) {
+ if (isSelected(item)) {
+ jsonObject.put(DataCommunicatorConstants.SELECTED, true);
+ }
+ }
+
+ @Override
+ protected AbstractSelectionModelState getState() {
+ return (AbstractSelectionModelState) super.getState();
+ }
+
+ @Override
+ protected AbstractSelectionModelState getState(boolean markAsDirty) {
+ return (AbstractSelectionModelState) super.getState(markAsDirty);
+ }
+
+ @Override
+ public void remove() {
+ deselectAll();
+
+ super.remove();
+ }
+
+}
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java b/server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java
index 70a056f34c..465115d831 100644
--- a/server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java
+++ b/server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java
@@ -30,17 +30,13 @@ import com.vaadin.event.selection.MultiSelectionListener;
import com.vaadin.server.data.DataProvider;
import com.vaadin.server.data.Query;
import com.vaadin.shared.Registration;
-import com.vaadin.shared.data.DataCommunicatorConstants;
import com.vaadin.shared.data.selection.GridMultiSelectServerRpc;
import com.vaadin.shared.ui.grid.MultiSelectionModelState;
import com.vaadin.ui.Grid;
-import com.vaadin.ui.Grid.AbstractGridExtension;
import com.vaadin.ui.Grid.MultiSelectionModel;
import com.vaadin.ui.MultiSelect;
import com.vaadin.util.ReflectTools;
-import elemental.json.JsonObject;
-
/**
* Multiselection model for grid.
* <p>
@@ -56,7 +52,7 @@ import elemental.json.JsonObject;
* @param <T>
* the type of the selected item in grid.
*/
-public class MultiSelectionModelImpl<T> extends AbstractGridExtension<T>
+public class MultiSelectionModelImpl<T> extends AbstractSelectionModel<T>
implements MultiSelectionModel<T> {
/**
@@ -257,13 +253,6 @@ public class MultiSelectionModelImpl<T> extends AbstractGridExtension<T>
}
}
- @Override
- public void remove() {
- updateSelection(Collections.emptySet(), getSelectedItems(), false);
-
- super.remove();
- }
-
/**
* Adds a selection listener that will be called when the selection is
* changed either by the user or programmatically.
@@ -280,15 +269,6 @@ public class MultiSelectionModelImpl<T> extends AbstractGridExtension<T>
}
@Override
- public void generateData(T item, JsonObject jsonObject) {
- // in case of all items selected, don't write individual items as
- // seleted
- if (isSelected(item)) {
- jsonObject.put(DataCommunicatorConstants.SELECTED, true);
- }
- }
-
- @Override
public Set<T> getSelectedItems() {
return Collections.unmodifiableSet(new LinkedHashSet<>(selection));
}
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModelImpl.java b/server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModelImpl.java
index e68487f358..283b8edc50 100644
--- a/server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModelImpl.java
+++ b/server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModelImpl.java
@@ -26,17 +26,14 @@ import java.util.Set;
import com.vaadin.event.selection.SingleSelectionEvent;
import com.vaadin.event.selection.SingleSelectionListener;
import com.vaadin.shared.Registration;
-import com.vaadin.shared.data.DataCommunicatorConstants;
import com.vaadin.shared.data.selection.SelectionServerRpc;
+import com.vaadin.shared.ui.grid.SingleSelectionModelState;
import com.vaadin.ui.Component;
import com.vaadin.ui.Grid;
-import com.vaadin.ui.Grid.AbstractGridExtension;
import com.vaadin.ui.Grid.SingleSelectionModel;
import com.vaadin.ui.SingleSelect;
import com.vaadin.util.ReflectTools;
-import elemental.json.JsonObject;
-
/**
* Single selection model for grid.
*
@@ -46,7 +43,7 @@ import elemental.json.JsonObject;
* @param <T>
* the type of the selected item in grid.
*/
-public class SingleSelectionModelImpl<T> extends AbstractGridExtension<T>
+public class SingleSelectionModelImpl<T> extends AbstractSelectionModel<T>
implements SingleSelectionModel<T> {
private static final Method SELECTION_CHANGE_METHOD = ReflectTools
@@ -81,6 +78,16 @@ public class SingleSelectionModelImpl<T> extends AbstractGridExtension<T>
});
}
+ @Override
+ protected SingleSelectionModelState getState() {
+ return (SingleSelectionModelState) super.getState();
+ }
+
+ @Override
+ protected SingleSelectionModelState getState(boolean markAsDirty) {
+ return (SingleSelectionModelState) super.getState(markAsDirty);
+ }
+
/**
* Adds a selection listener to this select. The listener is called when the
* value of this select is changed either by the user or programmatically.
@@ -224,23 +231,6 @@ public class SingleSelectionModelImpl<T> extends AbstractGridExtension<T>
}
}
- @Override
- public void generateData(T item, JsonObject jsonObject) {
- if (isSelected(item)) {
- jsonObject.put(DataCommunicatorConstants.SELECTED, true);
- }
- }
-
- @Override
- public void remove() {
- // when selection model changes, firing an event for selection change
- // event fired before removing so that parent is still intact (in case
- // needed)
- setSelectedFromServer(null);
-
- super.remove();
- }
-
/**
* Gets a wrapper for using this grid as a single select in a binder.
*