summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java31
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/SingleSelectionModelConnector.java75
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/selection/AbstractSelectionConnector.java81
-rw-r--r--client/src/main/java/com/vaadin/client/data/SelectionModel.java23
4 files changed, 96 insertions, 114 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
index ef715acfad..f5d95dfa80 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
@@ -21,7 +21,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Set;
import java.util.stream.Collectors;
import com.google.gwt.dom.client.Element;
@@ -40,7 +39,6 @@ import com.vaadin.client.annotations.OnStateChange;
import com.vaadin.client.connectors.AbstractListingConnector;
import com.vaadin.client.connectors.grid.ColumnConnector.CustomColumn;
import com.vaadin.client.data.DataSource;
-import com.vaadin.client.data.SelectionModel;
import com.vaadin.client.ui.SimpleManagedLayout;
import com.vaadin.client.widget.grid.CellReference;
import com.vaadin.client.widget.grid.EventCellReference;
@@ -58,8 +56,6 @@ import com.vaadin.client.widgets.Grid.FooterRow;
import com.vaadin.client.widgets.Grid.HeaderCell;
import com.vaadin.client.widgets.Grid.HeaderRow;
import com.vaadin.shared.MouseEventDetails;
-import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionServerRpc;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.grid.GridConstants;
@@ -204,33 +200,6 @@ public class GridConnector extends AbstractListingConnector
/* Item click events */
getWidget().addBodyClickHandler(itemClickHandler);
getWidget().addBodyDoubleClickHandler(itemClickHandler);
- getWidget().setSelectionModel(new SelectionModel<JsonObject>() {
-
- @Override
- public void select(JsonObject item) {
- getRpcProxy(SelectionServerRpc.class)
- .select(item.getString(DataCommunicatorConstants.KEY));
- }
-
- @Override
- public void deselect(JsonObject item) {
- getRpcProxy(SelectionServerRpc.class).deselect(
- item.getString(DataCommunicatorConstants.KEY));
- }
-
- @Override
- public Set<JsonObject> getSelectedItems() {
- throw new UnsupportedOperationException(
- "Selected item not known on the client side");
- }
-
- @Override
- public boolean isSelected(JsonObject item) {
- return item.hasKey(DataCommunicatorConstants.SELECTED)
- && item.getBoolean(DataCommunicatorConstants.SELECTED);
- }
-
- });
layout();
}
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/SingleSelectionModelConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/SingleSelectionModelConnector.java
new file mode 100644
index 0000000000..0a30dfa070
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/SingleSelectionModelConnector.java
@@ -0,0 +1,75 @@
+/*
+ * 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.client.connectors.grid;
+
+import java.util.Set;
+
+import com.vaadin.client.ServerConnector;
+import com.vaadin.client.data.SelectionModel;
+import com.vaadin.client.extensions.AbstractExtensionConnector;
+import com.vaadin.shared.data.DataCommunicatorConstants;
+import com.vaadin.shared.data.selection.SelectionServerRpc;
+import com.vaadin.shared.ui.Connect;
+
+import elemental.json.JsonObject;
+
+/**
+ * Client side connector for grid single selection model.
+ *
+ * @author Vaadin Ltd.
+ *
+ * @since 8.0
+ */
+@Connect(com.vaadin.ui.components.grid.SingleSelectionModel.class)
+public class SingleSelectionModelConnector extends AbstractExtensionConnector {
+
+ @Override
+ protected void extend(ServerConnector target) {
+ getParent().getWidget()
+ .setSelectionModel(new SelectionModel<JsonObject>() {
+
+ @Override
+ public void select(JsonObject item) {
+ getRpcProxy(SelectionServerRpc.class).select(
+ item.getString(DataCommunicatorConstants.KEY));
+ }
+
+ @Override
+ public void deselect(JsonObject item) {
+ getRpcProxy(SelectionServerRpc.class).deselect(
+ item.getString(DataCommunicatorConstants.KEY));
+ }
+
+ @Override
+ public Set<JsonObject> getSelectedItems() {
+ throw new UnsupportedOperationException(
+ "Selected item not known on the client side");
+ }
+
+ @Override
+ public boolean isSelected(JsonObject item) {
+ return SelectionModel.isItemSelected(item);
+ }
+
+ });
+ }
+
+ @Override
+ public GridConnector getParent() {
+ return (GridConnector) super.getParent();
+ }
+
+}
diff --git a/client/src/main/java/com/vaadin/client/connectors/selection/AbstractSelectionConnector.java b/client/src/main/java/com/vaadin/client/connectors/selection/AbstractSelectionConnector.java
deleted file mode 100644
index 55ce2dee7b..0000000000
--- a/client/src/main/java/com/vaadin/client/connectors/selection/AbstractSelectionConnector.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.client.connectors.selection;
-
-import com.vaadin.client.ServerConnector;
-import com.vaadin.client.connectors.AbstractListingConnector;
-import com.vaadin.client.extensions.AbstractExtensionConnector;
-import com.vaadin.shared.data.DataCommunicatorConstants;
-
-import elemental.json.JsonObject;
-
-/**
- * The client-side connector for selection extensions.
- *
- * @author Vaadin Ltd.
- *
- * @since 8.0
- */
-public abstract class AbstractSelectionConnector
- extends AbstractExtensionConnector {
-
- @Override
- @SuppressWarnings("unchecked")
- protected void extend(ServerConnector target) {
- if (!(target instanceof AbstractListingConnector)) {
- throw new IllegalArgumentException(
- "Cannot extend a connector that is not an "
- + AbstractListingConnector.class.getSimpleName());
- }
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public AbstractListingConnector getParent() {
- return (AbstractListingConnector) super.getParent();
- }
-
- /**
- * Gets the selected state from a given json object. This is a helper method
- * for selection model connectors.
- *
- * @param item
- * a json object
- * @return {@code true} if the json object is marked as selected;
- * {@code false} if not
- */
- public static boolean isItemSelected(JsonObject item) {
- return item.hasKey(DataCommunicatorConstants.SELECTED)
- && item.getBoolean(DataCommunicatorConstants.SELECTED);
- }
-
- /**
- * Gets the item key from given json object. This is a helper method for
- * selection model connectors.
- *
- * @param item
- * a json object
- * @return item key; {@code null} if there is no key
- */
- public static String getKey(JsonObject item) {
- if (item.hasKey(DataCommunicatorConstants.KEY)) {
- return item.getString(DataCommunicatorConstants.KEY);
- } else {
- return null;
- }
- }
-
-}
diff --git a/client/src/main/java/com/vaadin/client/data/SelectionModel.java b/client/src/main/java/com/vaadin/client/data/SelectionModel.java
index 80eb20fef1..4079140128 100644
--- a/client/src/main/java/com/vaadin/client/data/SelectionModel.java
+++ b/client/src/main/java/com/vaadin/client/data/SelectionModel.java
@@ -17,6 +17,10 @@ package com.vaadin.client.data;
import java.util.Set;
+import com.vaadin.shared.data.DataCommunicatorConstants;
+
+import elemental.json.JsonObject;
+
/**
* Models the selection logic of a {@code Grid} component. Determines how items
* can be selected and deselected.
@@ -32,7 +36,7 @@ public interface SelectionModel<T> {
/**
* Selects the given item. If another item was already selected, that item
* is deselected.
- *
+ *
* @param item
* the item to select, not null
*/
@@ -50,7 +54,7 @@ public interface SelectionModel<T> {
/**
* Returns a set of the currently selected items. It is safe to invoke other
* {@code SelectionModel} methods while iterating over the set.
- *
+ *
* @return the items in the current selection, not null
*/
Set<T> getSelectedItems();
@@ -70,4 +74,19 @@ public interface SelectionModel<T> {
default void deselectAll() {
getSelectedItems().forEach(this::deselect);
}
+
+ /**
+ * Gets the selected state from a given grid row json object. This is a
+ * helper method for grid selection models.
+ *
+ * @param item
+ * a json object
+ * @return {@code true} if the json object is marked as selected;
+ * {@code false} if not
+ */
+ public static boolean isItemSelected(JsonObject item) {
+ return item.hasKey(DataCommunicatorConstants.SELECTED)
+ && item.getBoolean(DataCommunicatorConstants.SELECTED);
+ }
+
}