]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make SelectionModel API only server side.
authorDenis Anisimov <denis@vaadin.com>
Tue, 1 Nov 2016 13:27:28 +0000 (15:27 +0200)
committerDenis Anisimov <denis@vaadin.com>
Wed, 2 Nov 2016 12:37:30 +0000 (14:37 +0200)
Client side doesn't use selection model anymore.
Fixes vaadin/framework8-issues#421

Change-Id: If3ecb1c2f3a0024df9bfdfd182eaf8cf8625ac75

30 files changed:
client/src/main/java/com/vaadin/client/connectors/AbstractFocusableListingConnector.java
client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java
client/src/main/java/com/vaadin/client/connectors/AbstractMultiSelectConnector.java
client/src/main/java/com/vaadin/client/connectors/AbstractSingleSelectConnector.java
client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
client/src/main/java/com/vaadin/client/connectors/selection/AbstractSelectionConnector.java
client/src/main/java/com/vaadin/client/data/SelectionModel.java [new file with mode: 0644]
client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java
client/src/main/java/com/vaadin/client/ui/optiongroup/CheckBoxGroupConnector.java
client/src/main/java/com/vaadin/client/widget/grid/events/SelectAllEvent.java
client/src/main/java/com/vaadin/client/widget/grid/selection/SelectionModelWithSelectionColumn.java
client/src/main/java/com/vaadin/client/widgets/Grid.java
server/src/main/java/com/vaadin/data/Listing.java
server/src/main/java/com/vaadin/data/SelectionModel.java [new file with mode: 0644]
server/src/main/java/com/vaadin/data/selection/AbstractSelectionModel.java
server/src/main/java/com/vaadin/event/selection/MultiSelectionEvent.java
server/src/main/java/com/vaadin/event/selection/MultiSelectionListener.java
server/src/main/java/com/vaadin/ui/AbstractListing.java
server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java
server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java
server/src/test/java/com/vaadin/ui/AbstractMultiSelectTest.java
server/src/test/java/com/vaadin/ui/AbstractSingleSelectTest.java
server/src/test/java/com/vaadin/ui/RadioButtonGroupTest.java
shared/src/main/java/com/vaadin/shared/data/selection/SelectionModel.java [deleted file]
uitest/src/main/java/com/vaadin/tests/components/AbstractListingFocusBlurTest.java
uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractMultiSelectTestUI.java
uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupFocusBlur.java
uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java
uitest/src/main/java/com/vaadin/tests/data/DummyData.java
uitest/src/main/java/com/vaadin/tests/widgetset/client/data/DummyComponentConnector.java

index 996086d36d42f13c2df44b0d2a8318633a6c2a65..9ce7dc194c1271153e24a1bf5ec03e5d12fb1391 100644 (file)
@@ -18,7 +18,6 @@ package com.vaadin.client.connectors;
 import com.google.gwt.event.dom.client.HasAllFocusHandlers;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.client.ui.ConnectorFocusAndBlurHandler;
-import com.vaadin.shared.data.selection.SelectionModel;
 
 /**
  * Abstract class for listing widget connectors that contains focusable children
@@ -28,11 +27,9 @@ import com.vaadin.shared.data.selection.SelectionModel;
  *
  * @param <WIDGET>
  *            widget type which has to allow to register focus/blur handlers
- * @param <SELECTIONMODEL>
- *            the client-side selection model type
  */
-public abstract class AbstractFocusableListingConnector<WIDGET extends Widget & HasAllFocusHandlers, SELECTIONMODEL extends SelectionModel<?>>
-        extends AbstractListingConnector<SELECTIONMODEL> {
+public abstract class AbstractFocusableListingConnector<WIDGET extends Widget & HasAllFocusHandlers>
+        extends AbstractListingConnector {
 
     private ConnectorFocusAndBlurHandler handler;
 
index b89106307e76bdaa30e09c3b1a140ca0dc8c1051..88fccab32e43453447482a8184bb5ea9c5475184 100644 (file)
@@ -19,7 +19,6 @@ import com.vaadin.client.connectors.data.HasDataSource;
 import com.vaadin.client.data.DataSource;
 import com.vaadin.client.ui.AbstractFieldConnector;
 import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionModel;
 import com.vaadin.ui.AbstractListing;
 
 import elemental.json.JsonObject;
@@ -30,18 +29,13 @@ import elemental.json.JsonValue;
  *
  * @author Vaadin Ltd.
  *
- * @param <SELECTIONMODEL>
- *            the client-side selection model type
- *
  * @since 8.0
  */
-public abstract class AbstractListingConnector<SELECTIONMODEL extends SelectionModel<?>>
-        extends AbstractFieldConnector implements HasDataSource {
+public abstract class AbstractListingConnector extends AbstractFieldConnector
+        implements HasDataSource {
 
     private DataSource<JsonObject> dataSource = null;
 
-    private SELECTIONMODEL selectionModel = null;
-
     @Override
     public void setDataSource(DataSource<JsonObject> dataSource) {
         this.dataSource = dataSource;
@@ -52,25 +46,6 @@ public abstract class AbstractListingConnector<SELECTIONMODEL extends SelectionM
         return dataSource;
     }
 
-    /**
-     * Sets the selection model to use. Passing {@code null} disables selection.
-     *
-     * @param selectionModel
-     *            the selection model or null to disable
-     */
-    public void setSelectionModel(SELECTIONMODEL selectionModel) {
-        this.selectionModel = selectionModel;
-    }
-
-    /**
-     * Returns the selection model instance used.
-     *
-     * @return the selection model
-     */
-    public SELECTIONMODEL getSelectionModel() {
-        return selectionModel;
-    }
-
     /**
      * Returns the key of the given data row.
      *
index 60966c39a964835cb3f29f04c6d240e1348d670a..1550f862923a0578bf4a81558927a38123e5868f 100644 (file)
@@ -30,7 +30,6 @@ import com.vaadin.shared.AbstractFieldState;
 import com.vaadin.shared.Range;
 import com.vaadin.shared.Registration;
 import com.vaadin.shared.data.selection.MultiSelectServerRpc;
-import com.vaadin.shared.data.selection.SelectionModel;
 import com.vaadin.shared.ui.ListingJsonConstants;
 
 import elemental.json.JsonObject;
@@ -46,8 +45,7 @@ import elemental.json.JsonObject;
  * @since 8.0
  */
 public abstract class AbstractMultiSelectConnector
-        extends AbstractListingConnector<SelectionModel.Multi<?>>
-        implements HasRequiredIndicator {
+        extends AbstractListingConnector implements HasRequiredIndicator {
 
     /**
      * Abstraction layer to help populate different multiselect widgets based on
index 5554b8421ca62335f24251332353da29c9be639a..96ccf2f7c2f15c0c77379c76c8e998686d58ad4d 100644 (file)
@@ -18,7 +18,6 @@ package com.vaadin.client.connectors;
 import com.google.gwt.event.dom.client.HasAllFocusHandlers;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.client.ui.HasRequiredIndicator;
-import com.vaadin.shared.data.selection.SelectionModel;
 import com.vaadin.shared.ui.AbstractSingleSelectState;
 
 /**
@@ -28,8 +27,7 @@ import com.vaadin.shared.ui.AbstractSingleSelectState;
  * @since 8.0.0
  */
 public abstract class AbstractSingleSelectConnector<WIDGET extends Widget & HasAllFocusHandlers>
-        extends
-        AbstractFocusableListingConnector<WIDGET, SelectionModel.Single<?>>
+        extends AbstractFocusableListingConnector<WIDGET>
         implements HasRequiredIndicator {
 
     @Override
index ad5f8200ea07acb7dab5c2b107219781c30f2d3a..ef715acfad19cc9e8dca5395c7e883eb8ae7d3f4 100644 (file)
@@ -21,7 +21,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
-import java.util.Optional;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 import com.google.gwt.dom.client.Element;
@@ -40,6 +40,7 @@ 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,7 +59,6 @@ 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.SelectionModel;
 import com.vaadin.shared.data.selection.SelectionServerRpc;
 import com.vaadin.shared.data.sort.SortDirection;
 import com.vaadin.shared.ui.Connect;
@@ -79,8 +79,7 @@ import elemental.json.JsonObject;
  * @since 8.0
  */
 @Connect(com.vaadin.ui.Grid.class)
-public class GridConnector
-        extends AbstractListingConnector<SelectionModel<JsonObject>>
+public class GridConnector extends AbstractListingConnector
         implements HasComponentsConnector, SimpleManagedLayout, DeferredWorker {
 
     private class ItemClickHandler
@@ -205,7 +204,7 @@ public class GridConnector
         /* Item click events */
         getWidget().addBodyClickHandler(itemClickHandler);
         getWidget().addBodyDoubleClickHandler(itemClickHandler);
-        getWidget().setSelectionModel(new SelectionModel.Single<JsonObject>() {
+        getWidget().setSelectionModel(new SelectionModel<JsonObject>() {
 
             @Override
             public void select(JsonObject item) {
@@ -220,7 +219,7 @@ public class GridConnector
             }
 
             @Override
-            public Optional<JsonObject> getSelectedItem() {
+            public Set<JsonObject> getSelectedItems() {
                 throw new UnsupportedOperationException(
                         "Selected item not known on the client side");
             }
@@ -230,6 +229,7 @@ public class GridConnector
                 return item.hasKey(DataCommunicatorConstants.SELECTED)
                         && item.getBoolean(DataCommunicatorConstants.SELECTED);
             }
+
         });
 
         layout();
@@ -321,12 +321,6 @@ public class GridConnector
         getWidget().setDataSource(dataSource);
     }
 
-    @Override
-    public void setSelectionModel(SelectionModel<JsonObject> selectionModel) {
-        throw new UnsupportedOperationException(
-                "Cannot set a selection model for GridConnector");
-    }
-
     /**
      * Adds a column to the Grid widget. For each column a communication id
      * stored for client to server communication.
index 9d4604993dcb2b528b2da0c0df8e0424d99a9f0c..55ce2dee7b2d9a29c61e386fd3649848d51315ec 100644 (file)
@@ -19,7 +19,6 @@ import com.vaadin.client.ServerConnector;
 import com.vaadin.client.connectors.AbstractListingConnector;
 import com.vaadin.client.extensions.AbstractExtensionConnector;
 import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionModel;
 
 import elemental.json.JsonObject;
 
@@ -28,15 +27,11 @@ import elemental.json.JsonObject;
  *
  * @author Vaadin Ltd.
  * 
- * @param <SELECTIONMODEL>
- *            the supported client-side selection model
  * @since 8.0
  */
-public abstract class AbstractSelectionConnector<SELECTIONMODEL extends SelectionModel<?>>
+public abstract class AbstractSelectionConnector
         extends AbstractExtensionConnector {
 
-    private SELECTIONMODEL model = null;
-
     @Override
     @SuppressWarnings("unchecked")
     protected void extend(ServerConnector target) {
@@ -45,31 +40,12 @@ public abstract class AbstractSelectionConnector<SELECTIONMODEL extends Selectio
                     "Cannot extend a connector that is not an "
                             + AbstractListingConnector.class.getSimpleName());
         }
-        model = createSelectionModel();
-        ((AbstractListingConnector<SELECTIONMODEL>) target)
-                .setSelectionModel(model);
     }
 
-    /**
-     * Creates a selection model object to be used by the Connector.
-     *
-     * @return created selection model
-     */
-    protected abstract SELECTIONMODEL createSelectionModel();
-
     @Override
     @SuppressWarnings("unchecked")
-    public AbstractListingConnector<SELECTIONMODEL> getParent() {
-        return (AbstractListingConnector<SELECTIONMODEL>) super.getParent();
-    }
-
-    /**
-     * Returns the client-side selection model associated with this connector.
-     *
-     * @return the selection model in use
-     */
-    protected SELECTIONMODEL getSelectionModel() {
-        return model;
+    public AbstractListingConnector getParent() {
+        return (AbstractListingConnector) super.getParent();
     }
 
     /**
diff --git a/client/src/main/java/com/vaadin/client/data/SelectionModel.java b/client/src/main/java/com/vaadin/client/data/SelectionModel.java
new file mode 100644 (file)
index 0000000..80eb20f
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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.data;
+
+import java.util.Set;
+
+/**
+ * Models the selection logic of a {@code Grid} component. Determines how items
+ * can be selected and deselected.
+ *
+ * @author Vaadin Ltd.
+ *
+ * @param <T>
+ *            the type of the items to select
+ * @since 8.0
+ */
+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
+     */
+    void select(T item);
+
+    /**
+     * Deselects the given item. If the item is not currently selected, does
+     * nothing.
+     *
+     * @param item
+     *            the item to deselect, not null
+     */
+    void deselect(T item);
+
+    /**
+     * 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();
+
+    /**
+     * Returns whether the given item is currently selected.
+     *
+     * @param item
+     *            the item to check, not null
+     * @return {@code true} if the item is selected, {@code false} otherwise
+     */
+    boolean isSelected(T item);
+
+    /**
+     * Deselects all currently selected items.
+     */
+    default void deselectAll() {
+        getSelectedItems().forEach(this::deselect);
+    }
+}
index 97f382453f2cc72107b8fd56e1cb142a764cb9a2..8b56483e8f167dfe8aa06c41d8f83e2a8a11b77a 100644 (file)
@@ -30,7 +30,6 @@ import com.vaadin.shared.EventId;
 import com.vaadin.shared.Registration;
 import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc;
 import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionModel;
 import com.vaadin.shared.data.selection.SelectionServerRpc;
 import com.vaadin.shared.ui.Connect;
 import com.vaadin.shared.ui.combobox.ComboBoxConstants;
@@ -41,8 +40,7 @@ import com.vaadin.ui.ComboBox;
 import elemental.json.JsonObject;
 
 @Connect(ComboBox.class)
-public class ComboBoxConnector
-        extends AbstractListingConnector<SelectionModel.Single<?>>
+public class ComboBoxConnector extends AbstractListingConnector
         implements HasRequiredIndicator, HasDataSource, SimpleManagedLayout,
         HasErrorIndicator {
 
index 940287d583766c10db1e6301b367d6021d0cb93e..4262666943f83e5e3691398e1afc2c49ab8edbd0 100644 (file)
@@ -27,7 +27,6 @@ import com.vaadin.client.data.DataSource;
 import com.vaadin.client.ui.HasRequiredIndicator;
 import com.vaadin.client.ui.VCheckBoxGroup;
 import com.vaadin.shared.data.selection.MultiSelectServerRpc;
-import com.vaadin.shared.data.selection.SelectionModel;
 import com.vaadin.shared.ui.Connect;
 import com.vaadin.shared.ui.optiongroup.CheckBoxGroupState;
 import com.vaadin.ui.CheckBoxGroup;
@@ -38,8 +37,8 @@ import elemental.json.JsonObject;
 // We don't care about the framework-provided selection model at this point
 // TODO refactor to extend AbstractMultiSelectConnector, maybe when
 // SelectionModel is removed from client side framwork8-issues#421
-public class CheckBoxGroupConnector extends
-        AbstractFocusableListingConnector<VCheckBoxGroup, SelectionModel<?>>
+public class CheckBoxGroupConnector
+        extends AbstractFocusableListingConnector<VCheckBoxGroup>
         implements HasRequiredIndicator {
 
     @Override
index cd86dbe99313d2b9413046ab319bbdc559824f0a..2ac2f51e4b81a2c536c3c647198de5e806cd6507 100644 (file)
@@ -16,7 +16,7 @@
 package com.vaadin.client.widget.grid.events;
 
 import com.google.gwt.event.shared.GwtEvent;
-import com.vaadin.shared.data.selection.SelectionModel;
+import com.vaadin.client.data.SelectionModel;
 
 /**
  * A select all event, fired by the Grid when it needs all rows in data source
@@ -32,9 +32,9 @@ public class SelectAllEvent<T> extends GwtEvent<SelectAllHandler<T>> {
      */
     private final static Type<SelectAllHandler<?>> TYPE = new Type<>();;
 
-    private SelectionModel.Multi<T> selectionModel;
+    private SelectionModel selectionModel;
 
-    public SelectAllEvent(SelectionModel.Multi<T> selectionModel) {
+    public SelectAllEvent(SelectionModel selectionModel) {
         this.selectionModel = selectionModel;
     }
 
@@ -53,7 +53,7 @@ public class SelectAllEvent<T> extends GwtEvent<SelectAllHandler<T>> {
         handler.onSelectAll(this);
     }
 
-    public SelectionModel.Multi<T> getSelectionModel() {
+    public SelectionModel getSelectionModel() {
         return selectionModel;
     }
 }
index 5c57607e708360c60856093a536c8af45ec9483b..f6e55bf596564c669220f4bb9f99dec05af9cdc9 100644 (file)
@@ -16,7 +16,6 @@
 package com.vaadin.client.widget.grid.selection;
 
 import com.vaadin.client.renderers.Renderer;
-import com.vaadin.shared.data.selection.SelectionModel;
 
 /**
  * Interface for SelectionModels that wants Grid to display a selection column.
@@ -24,13 +23,9 @@ import com.vaadin.shared.data.selection.SelectionModel;
  * @author Vaadin Ltd
  * @since 8.0
  *
- * @param <T>
- *            selected item type
- *
  * @see Renderer
  */
-public interface SelectionModelWithSelectionColumn<T>
-        extends SelectionModel<T> {
+public interface SelectionModelWithSelectionColumn {
 
     /**
      * Returns a new instance of the Renderer for selection column.
index 7d6c1369b8dae0bd466e605250806d8fbca96841..276cde766624eeabd98ef1b61112dba1e086850c 100644 (file)
@@ -83,6 +83,7 @@ import com.vaadin.client.WidgetUtil;
 import com.vaadin.client.data.DataChangeHandler;
 import com.vaadin.client.data.DataSource;
 import com.vaadin.client.data.DataSource.RowHandle;
+import com.vaadin.client.data.SelectionModel;
 import com.vaadin.client.renderers.ComplexRenderer;
 import com.vaadin.client.renderers.Renderer;
 import com.vaadin.client.renderers.WidgetRenderer;
@@ -171,8 +172,6 @@ import com.vaadin.client.widgets.Grid.StaticSection.StaticCell;
 import com.vaadin.client.widgets.Grid.StaticSection.StaticRow;
 import com.vaadin.shared.Range;
 import com.vaadin.shared.Registration;
-import com.vaadin.shared.data.selection.SelectionModel;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
 import com.vaadin.shared.data.sort.SortDirection;
 import com.vaadin.shared.ui.grid.GridConstants;
 import com.vaadin.shared.ui.grid.GridConstants.Section;
@@ -2865,7 +2864,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
              * Later on this could be fixed so that it check such handlers
              * exist.
              */
-            final SelectionModel.Multi<T> model = (Multi<T>) getSelectionModel();
+            final SelectionModel<T> model = getSelectionModel();
 
             if (selectAllCheckBox == null) {
                 selectAllCheckBox = GWT.create(CheckBox.class);
@@ -5886,6 +5885,11 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
             public void deselect(T item) {
             }
 
+            @Override
+            public boolean isSelected(T item) {
+                return false;
+            }
+
         });
 
         escalator.getBody().setSpacerUpdater(gridSpacerUpdater);
@@ -7580,7 +7584,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
         this.selectionModel = selectionModel;
         if (selectionModel instanceof SelectionModelWithSelectionColumn) {
             setSelectColumnRenderer(
-                    ((SelectionModelWithSelectionColumn<T>) selectionModel)
+                    ((SelectionModelWithSelectionColumn) selectionModel)
                             .getRenderer());
         } else {
             setSelectColumnRenderer(null);
@@ -8227,8 +8231,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
 
         columnHider.updateTogglesOrder();
 
-        fireEvent(new ColumnReorderEvent<T>(oldOrder, newOrder,
-                isUserOriginated));
+        fireEvent(
+                new ColumnReorderEvent<>(oldOrder, newOrder, isUserOriginated));
     }
 
     /**
index 667d4f4aef86750f259461192bffb2cca2bf3995..397272a67787027c2c68fa4f8c502fc7a7fe1b44 100644 (file)
@@ -20,7 +20,6 @@ import java.util.Collection;
 import java.util.Set;
 
 import com.vaadin.server.data.DataSource;
-import com.vaadin.shared.data.selection.SelectionModel;
 
 /**
  * A generic interface for components that show a list of data.
diff --git a/server/src/main/java/com/vaadin/data/SelectionModel.java b/server/src/main/java/com/vaadin/data/SelectionModel.java
new file mode 100644 (file)
index 0000000..eca43e6
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * 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.data;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Stream;
+
+/**
+ * Models the selection logic of a {@code Listing} component. Determines how
+ * items can be selected and deselected.
+ *
+ * @author Vaadin Ltd.
+ *
+ * @param <T>
+ *            the type of the items to select
+ * @since 8.0
+ */
+public interface SelectionModel<T> extends Serializable {
+
+    /**
+     * A selection model in which at most one item can be selected at a time.
+     * Selecting another item deselects the originally selected item.
+     *
+     * @param <T>
+     *            the type of the items to select
+     */
+    public interface Single<T> extends SelectionModel<T> {
+
+        /**
+         * Selects the given item. If another item was already selected, that
+         * item is deselected.
+         */
+        @Override
+        public void select(T item);
+
+        /**
+         * Returns the currently selected item, or an empty optional if no item
+         * is selected.
+         *
+         * @return an optional of the selected item if any, an empty optional
+         *         otherwise
+         */
+        public Optional<T> getSelectedItem();
+
+        /**
+         * Sets the current selection to the given item, or clears selection if
+         * given {@code null}.
+         *
+         * @param item
+         *            the item to select or {@code null} to clear selection
+         */
+        public default void setSelectedItem(T item) {
+            if (item != null) {
+                select(item);
+            } else {
+                deselectAll();
+            }
+        }
+
+        /**
+         * Returns a singleton set of the currently selected item or an empty
+         * set if no item is selected.
+         *
+         * @return a singleton set of the selected item if any, an empty set
+         *         otherwise
+         *
+         * @see #getSelectedItem()
+         */
+        @Override
+        public default Set<T> getSelectedItems() {
+            return getSelectedItem().map(Collections::singleton)
+                    .orElse(Collections.emptySet());
+        }
+    }
+
+    /**
+     * A selection model in which multiple items can be selected at the same
+     * time. Selecting an item adds it to the selection.
+     *
+     * @param <T>
+     *            the type of the items to select
+     */
+    public interface Multi<T> extends SelectionModel<T> {
+
+        /**
+         * Adds the given item to the set of currently selected items.
+         * <p>
+         * By default this does not clear any previous selection. To do that,
+         * use {@link #deselectAll()}.
+         * <p>
+         * If the the item was already selected, this is a NO-OP.
+         *
+         * @param item
+         *            the item to add to selection, not {@code null}
+         */
+        @Override
+        public default void select(T item) {
+            Objects.requireNonNull(item);
+            selectItems(item);
+        };
+
+        /**
+         * Adds the given items to the set of currently selected items.
+         * <p>
+         * By default this does not clear any previous selection. To do that,
+         * use {@link #deselectAll()}.
+         * <p>
+         * If the all the items were already selected, this is a NO-OP.
+         * <p>
+         * This is a short-hand for {@link #updateSelection(Set, Set)} with
+         * nothing to deselect.
+         *
+         * @param items
+         *            to add to selection, not {@code null}
+         */
+        public default void selectItems(T... items) {
+            Objects.requireNonNull(items);
+            Stream.of(items).forEach(Objects::requireNonNull);
+
+            updateSelection(new LinkedHashSet<>(Arrays.asList(items)),
+                    Collections.emptySet());
+        }
+
+        /**
+         * Removes the given items from the set of currently selected items.
+         * <p>
+         * If the none of the items were selected, this is a NO-OP.
+         * <p>
+         * This is a short-hand for {@link #updateSelection(Set, Set)} with
+         * nothing to select.
+         *
+         * @param items
+         *            to remove from selection, not {@code null}
+         */
+        public default void deselectItems(T... items) {
+            Objects.requireNonNull(items);
+            Stream.of(items).forEach(Objects::requireNonNull);
+
+            updateSelection(Collections.emptySet(),
+                    new LinkedHashSet<>(Arrays.asList(items)));
+        }
+
+        /**
+         * Updates the selection by adding and removing the given items from it.
+         * <p>
+         * If all the added items were already selected and the removed items
+         * were not selected, this is a NO-OP.
+         * <p>
+         * Duplicate items (in both add & remove sets) are ignored.
+         *
+         * @param addedItems
+         *            the items to add, not {@code null}
+         * @param removedItems
+         *            the items to remove, not {@code null}
+         */
+        public void updateSelection(Set<T> addedItems, Set<T> removedItems);
+    }
+
+    /**
+     * Returns an immutable set of the currently selected items. It is safe to
+     * invoke other {@code SelectionModel} methods while iterating over the set.
+     * <p>
+     * <em>Implementation note:</em> the iteration order of the items in the
+     * returned set should be well-defined and documented by the implementing
+     * class.
+     *
+     * @return the items in the current selection, not null
+     */
+    public Set<T> getSelectedItems();
+
+    /**
+     * Selects the given item. Depending on the implementation, may cause other
+     * items to be deselected. If the item is already selected, does nothing.
+     *
+     * @param item
+     *            the item to select, not null
+     */
+    public void select(T item);
+
+    /**
+     * Deselects the given item. If the item is not currently selected, does
+     * nothing.
+     *
+     * @param item
+     *            the item to deselect, not null
+     */
+    public void deselect(T item);
+
+    /**
+     * Deselects all currently selected items.
+     */
+    public default void deselectAll() {
+        getSelectedItems().forEach(this::deselect);
+    }
+
+    /**
+     * Returns whether the given item is currently selected.
+     *
+     * @param item
+     *            the item to check, not null
+     * @return {@code true} if the item is selected, {@code false} otherwise
+     */
+    public default boolean isSelected(T item) {
+        return getSelectedItems().contains(item);
+    }
+}
index aa2457f589d130cace4cd7ae98ef5df160dd8a78..7e608476850ff1ee5695db2f1cac717262350106 100644 (file)
@@ -15,8 +15,8 @@
  */
 package com.vaadin.data.selection;
 
+import com.vaadin.data.SelectionModel;
 import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionModel;
 import com.vaadin.ui.AbstractListing.AbstractListingExtension;
 
 import elemental.json.JsonObject;
index d63f26d680158f5ce3dbe36e8bc0041eb7786e63..5fb91bbcbef94edf5a215262fd19dcad0741a6c3 100644 (file)
@@ -24,7 +24,7 @@ import com.vaadin.ui.AbstractMultiSelect;
 
 /**
  * Event fired when the the selection changes in a
- * {@link com.vaadin.shared.data.selection.SelectionModel.Multi}.
+ * {@link com.vaadin.data.SelectionModel.Multi}.
  *
  * @author Vaadin Ltd
  *
index c8de132341b8bae9aa30b9bdfbf1b16e6b80436c..d8005a396c898f03813ddb3a716da3ee49b82db8 100644 (file)
@@ -20,7 +20,7 @@ import java.util.function.Consumer;
 
 /**
  * Listens to changes from a
- * {@link com.vaadin.shared.data.selection.SelectionModel.Multi}.
+ * {@link com.vaadin.data.SelectionModel.Multi}.
  *
  * @author Vaadin Ltd
  *
index 0840e3fc304d8638137841e0560570a45b028d92..3892e55662a9bdfee436e626b3590ebb347403a3 100644 (file)
@@ -18,11 +18,11 @@ package com.vaadin.ui;
 import java.util.Objects;
 
 import com.vaadin.data.Listing;
+import com.vaadin.data.SelectionModel;
 import com.vaadin.server.AbstractExtension;
 import com.vaadin.server.data.DataCommunicator;
 import com.vaadin.server.data.DataGenerator;
 import com.vaadin.server.data.DataSource;
-import com.vaadin.shared.data.selection.SelectionModel;
 
 /**
  * A base class for listing components. Provides common handling for fetching
index bd1fc8937a5cb04bd0cc14191a1d69b6deb2297d..779cd959dd6031eec27cf38b49d6717f7da57d56 100644 (file)
@@ -26,6 +26,8 @@ import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
 import com.vaadin.data.HasValue;
+import com.vaadin.data.SelectionModel;
+import com.vaadin.data.SelectionModel.Multi;
 import com.vaadin.event.selection.MultiSelectionEvent;
 import com.vaadin.event.selection.MultiSelectionListener;
 import com.vaadin.server.Resource;
@@ -35,8 +37,6 @@ import com.vaadin.server.data.DataGenerator;
 import com.vaadin.shared.AbstractFieldState;
 import com.vaadin.shared.Registration;
 import com.vaadin.shared.data.selection.MultiSelectServerRpc;
-import com.vaadin.shared.data.selection.SelectionModel;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
 import com.vaadin.shared.ui.ListingJsonConstants;
 import com.vaadin.util.ReflectTools;
 
index c529ad3f26e52c1a7395239c57770b6b2fa9f8a4..cb72d52444c3cd37b491ab4a989738c48d49b12f 100644 (file)
@@ -20,12 +20,12 @@ import java.util.Objects;
 import java.util.Optional;
 
 import com.vaadin.data.HasValue;
+import com.vaadin.data.SelectionModel;
+import com.vaadin.data.SelectionModel.Single;
 import com.vaadin.event.selection.SingleSelectionChangeEvent;
 import com.vaadin.event.selection.SingleSelectionListener;
 import com.vaadin.server.data.DataCommunicator;
 import com.vaadin.shared.Registration;
-import com.vaadin.shared.data.selection.SelectionModel;
-import com.vaadin.shared.data.selection.SelectionModel.Single;
 import com.vaadin.shared.data.selection.SelectionServerRpc;
 import com.vaadin.shared.ui.AbstractSingleSelectState;
 import com.vaadin.util.ReflectTools;
@@ -39,7 +39,7 @@ import com.vaadin.util.ReflectTools;
  * @param <T>
  *            the item date type
  *
- * @see com.vaadin.shared.data.selection.SelectionModel.Single
+ * @see com.vaadin.data.SelectionModel.Single
  *
  * @since 8.0
  */
index e117d01b9e8fe2cd5712528e2af4d80e769d86dc..6d748f076ac77eaeaa4c534cbdfa695467c632ee 100644 (file)
@@ -37,12 +37,12 @@ import org.junit.runners.Parameterized.Parameters;
 import org.mockito.Mockito;
 
 import com.vaadin.data.HasValue.ValueChangeEvent;
+import com.vaadin.data.SelectionModel.Multi;
 import com.vaadin.event.selection.MultiSelectionEvent;
 import com.vaadin.event.selection.MultiSelectionListener;
 import com.vaadin.server.data.DataSource;
 import com.vaadin.shared.Registration;
 import com.vaadin.shared.data.selection.MultiSelectServerRpc;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
 
 @RunWith(Parameterized.class)
 public class AbstractMultiSelectTest {
index 258bf8d0bdf0b9665bb4d106392d3dcfe4efb31c..6ae5c91b968beb1c86d76d8cff213835a86fa874 100644 (file)
@@ -34,12 +34,12 @@ import org.junit.Test;
 import org.mockito.Mockito;
 
 import com.vaadin.data.HasValue.ValueChangeEvent;
+import com.vaadin.data.SelectionModel.Multi;
 import com.vaadin.event.selection.SingleSelectionChangeEvent;
 import com.vaadin.event.selection.SingleSelectionListener;
 import com.vaadin.server.data.datasource.bov.Person;
 import com.vaadin.shared.Registration;
 import com.vaadin.shared.data.DataCommunicatorClientRpc;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
 import com.vaadin.ui.AbstractSingleSelect.AbstractSingleSelection;
 
 /**
index 6bbd9a9438274554a55582ced207fb83aadbb29d..31bc2de27189a24f80162186d81f25bc1ccbd9d8 100644 (file)
@@ -23,9 +23,9 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.vaadin.data.SelectionModel;
+import com.vaadin.data.SelectionModel.Multi;
 import com.vaadin.server.data.DataSource;
-import com.vaadin.shared.data.selection.SelectionModel;
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
 import com.vaadin.shared.data.selection.SelectionServerRpc;
 
 public class RadioButtonGroupTest {
diff --git a/shared/src/main/java/com/vaadin/shared/data/selection/SelectionModel.java b/shared/src/main/java/com/vaadin/shared/data/selection/SelectionModel.java
deleted file mode 100644 (file)
index c56fe8c..0000000
+++ /dev/null
@@ -1,225 +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.shared.data.selection;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Stream;
-
-/**
- * Models the selection logic of a {@code Listing} component. Determines how
- * items can be selected and deselected.
- *
- * @author Vaadin Ltd.
- *
- * @param <T>
- *            the type of the items to select
- * @since 8.0
- */
-public interface SelectionModel<T> extends Serializable {
-
-    /**
-     * A selection model in which at most one item can be selected at a time.
-     * Selecting another item deselects the originally selected item.
-     *
-     * @param <T>
-     *            the type of the items to select
-     */
-    public interface Single<T> extends SelectionModel<T> {
-
-        /**
-         * Selects the given item. If another item was already selected, that
-         * item is deselected.
-         */
-        @Override
-        public void select(T item);
-
-        /**
-         * Returns the currently selected item, or an empty optional if no item
-         * is selected.
-         *
-         * @return an optional of the selected item if any, an empty optional
-         *         otherwise
-         */
-        public Optional<T> getSelectedItem();
-
-        /**
-         * Sets the current selection to the given item, or clears selection if
-         * given {@code null}.
-         *
-         * @param item
-         *            the item to select or {@code null} to clear selection
-         */
-        public default void setSelectedItem(T item) {
-            if (item != null) {
-                select(item);
-            } else {
-                deselectAll();
-            }
-        }
-
-        /**
-         * Returns a singleton set of the currently selected item or an empty
-         * set if no item is selected.
-         *
-         * @return a singleton set of the selected item if any, an empty set
-         *         otherwise
-         *
-         * @see #getSelectedItem()
-         */
-        @Override
-        public default Set<T> getSelectedItems() {
-            return getSelectedItem().map(Collections::singleton)
-                    .orElse(Collections.emptySet());
-        }
-    }
-
-    /**
-     * A selection model in which multiple items can be selected at the same
-     * time. Selecting an item adds it to the selection.
-     *
-     * @param <T>
-     *            the type of the items to select
-     */
-    public interface Multi<T> extends SelectionModel<T> {
-
-        /**
-         * Adds the given item to the set of currently selected items.
-         * <p>
-         * By default this does not clear any previous selection. To do that,
-         * use {@link #deselectAll()}.
-         * <p>
-         * If the the item was already selected, this is a NO-OP.
-         *
-         * @param item
-         *            the item to add to selection, not {@code null}
-         */
-        @Override
-        public default void select(T item) {
-            Objects.requireNonNull(item);
-            selectItems(item);
-        };
-
-        /**
-         * Adds the given items to the set of currently selected items.
-         * <p>
-         * By default this does not clear any previous selection. To do that,
-         * use {@link #deselectAll()}.
-         * <p>
-         * If the all the items were already selected, this is a NO-OP.
-         * <p>
-         * This is a short-hand for {@link #updateSelection(Set, Set)} with
-         * nothing to deselect.
-         *
-         * @param items
-         *            to add to selection, not {@code null}
-         */
-        public default void selectItems(T... items) {
-            Objects.requireNonNull(items);
-            Stream.of(items).forEach(Objects::requireNonNull);
-
-            updateSelection(new LinkedHashSet<>(Arrays.asList(items)),
-                    Collections.emptySet());
-        }
-
-        /**
-         * Removes the given items from the set of currently selected items.
-         * <p>
-         * If the none of the items were selected, this is a NO-OP.
-         * <p>
-         * This is a short-hand for {@link #updateSelection(Set, Set)} with
-         * nothing to select.
-         *
-         * @param items
-         *            to remove from selection, not {@code null}
-         */
-        public default void deselectItems(T... items) {
-            Objects.requireNonNull(items);
-            Stream.of(items).forEach(Objects::requireNonNull);
-
-            updateSelection(Collections.emptySet(),
-                    new LinkedHashSet<>(Arrays.asList(items)));
-        }
-
-        /**
-         * Updates the selection by adding and removing the given items from it.
-         * <p>
-         * If all the added items were already selected and the removed items
-         * were not selected, this is a NO-OP.
-         * <p>
-         * Duplicate items (in both add & remove sets) are ignored.
-         *
-         * @param addedItems
-         *            the items to add, not {@code null}
-         * @param removedItems
-         *            the items to remove, not {@code null}
-         */
-        public void updateSelection(Set<T> addedItems, Set<T> removedItems);
-    }
-
-    /**
-     * Returns an immutable set of the currently selected items. It is safe to
-     * invoke other {@code SelectionModel} methods while iterating over the set.
-     * <p>
-     * <em>Implementation note:</em> the iteration order of the items in the
-     * returned set should be well-defined and documented by the implementing
-     * class.
-     *
-     * @return the items in the current selection, not null
-     */
-    public Set<T> getSelectedItems();
-
-    /**
-     * Selects the given item. Depending on the implementation, may cause other
-     * items to be deselected. If the item is already selected, does nothing.
-     *
-     * @param item
-     *            the item to select, not null
-     */
-    public void select(T item);
-
-    /**
-     * Deselects the given item. If the item is not currently selected, does
-     * nothing.
-     *
-     * @param item
-     *            the item to deselect, not null
-     */
-    public void deselect(T item);
-
-    /**
-     * Deselects all currently selected items.
-     */
-    public default void deselectAll() {
-        getSelectedItems().forEach(this::deselect);
-    }
-
-    /**
-     * Returns whether the given item is currently selected.
-     *
-     * @param item
-     *            the item to check, not null
-     * @return {@code true} if the item is selected, {@code false} otherwise
-     */
-    public default boolean isSelected(T item) {
-        return getSelectedItems().contains(item);
-    }
-}
index 0b94b8fecbf75e76b170e24c56f1680ea4c57fb1..f953c3acac3ff7fa4b4d63df8137db17590931c1 100644 (file)
@@ -21,10 +21,10 @@ import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
 import com.googlecode.gentyref.GenericTypeReflector;
+import com.vaadin.data.SelectionModel;
 import com.vaadin.event.FieldEvents.BlurNotifier;
 import com.vaadin.event.FieldEvents.FocusNotifier;
 import com.vaadin.server.VaadinRequest;
-import com.vaadin.shared.data.selection.SelectionModel;
 import com.vaadin.ui.AbstractListing;
 
 /**
index 71fd0fd37dc3cc0383c6ecd83392281602dcc72c..ae69cbb6ff6163baaad3c69ebf2b7576805275f3 100644 (file)
@@ -5,7 +5,7 @@ import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
+import com.vaadin.data.SelectionModel.Multi;
 import com.vaadin.ui.AbstractMultiSelect;
 import com.vaadin.ui.ItemCaptionGenerator;
 
index 92efed09e722f24f1f0f07465aef94f44b56f648..b92132d9f7db67a0779044b3e7e7502951e20fff 100644 (file)
@@ -15,7 +15,7 @@
  */
 package com.vaadin.tests.components.checkboxgroup;
 
-import com.vaadin.shared.data.selection.SelectionModel.Multi;
+import com.vaadin.data.SelectionModel.Multi;
 import com.vaadin.tests.components.AbstractListingFocusBlurTest;
 import com.vaadin.ui.CheckBoxGroup;
 
index 036512a514eb572da3d6f7274bade61ee96fe755..3d8802c5ede90a25e7989fcede4ef00abcf878e0 100644 (file)
@@ -15,8 +15,8 @@
  */
 package com.vaadin.tests.components.radiobutton;
 
+import com.vaadin.data.SelectionModel;
 import com.vaadin.server.FontAwesome;
-import com.vaadin.shared.data.selection.SelectionModel;
 import com.vaadin.tests.components.abstractlisting.AbstractListingTestUI;
 import com.vaadin.ui.ItemCaptionGenerator;
 import com.vaadin.ui.RadioButtonGroup;
index 917eb39bbd70228a655e8e380c683c40b0a0c6f4..d0ba74a942438ba350797d6ebd4e9af1df9647e6 100644 (file)
@@ -8,12 +8,12 @@ import java.util.Set;
 import java.util.stream.Stream;
 
 import com.vaadin.annotations.Widgetset;
+import com.vaadin.data.SelectionModel;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.server.data.DataCommunicator;
 import com.vaadin.server.data.ListDataSource;
 import com.vaadin.server.data.Query;
 import com.vaadin.shared.data.DataCommunicatorConstants;
-import com.vaadin.shared.data.selection.SelectionModel;
 import com.vaadin.tests.components.AbstractTestUIWithLog;
 import com.vaadin.tests.widgetset.TestingWidgetSet;
 import com.vaadin.ui.AbstractListing;
index 228f5120e7cea174c33dcf16afa4bbe1b6d943cb..80ae0d972a164a02bb9dbc643ac21fd0a84f14f9 100644 (file)
@@ -4,15 +4,13 @@ import com.google.gwt.user.client.ui.FlowPanel;
 import com.vaadin.client.connectors.AbstractListingConnector;
 import com.vaadin.client.data.DataSource;
 import com.vaadin.client.ui.VLabel;
-import com.vaadin.shared.data.selection.SelectionModel;
 import com.vaadin.shared.ui.Connect;
 import com.vaadin.tests.data.DummyData.DummyComponent;
 
 import elemental.json.JsonObject;
 
 @Connect(DummyComponent.class)
-public class DummyComponentConnector extends
-        AbstractListingConnector<SelectionModel<?>> {
+public class DummyComponentConnector extends AbstractListingConnector {
 
     @Override
     public FlowPanel getWidget() {