summaryrefslogtreecommitdiffstats
path: root/compatibility-server
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2016-10-20 13:33:43 +0300
committerVaadin Code Review <review@vaadin.com>2016-10-24 10:29:06 +0000
commit6d75c88fcb8c37e4f588bdc09dc183f9d51e4a62 (patch)
tree0120d3580a0c6d36432d0cdf17bad0e919411ec8 /compatibility-server
parent09485d529d085a380b347a118b54df9ae30fefd0 (diff)
downloadvaadin-framework-6d75c88fcb8c37e4f588bdc09dc183f9d51e4a62.tar.gz
vaadin-framework-6d75c88fcb8c37e4f588bdc09dc183f9d51e4a62.zip
Move old SelectionEvent to V7 and create a new selection event supertype
Change-Id: I17496c803f81fdaa98e47cbfcc9bdc91625c134f
Diffstat (limited to 'compatibility-server')
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/event/SelectionEvent.java135
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java6
-rw-r--r--compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/GridSelectionTest.java4
-rw-r--r--compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/MultiSelectionModelTest.java4
-rw-r--r--compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/SingleSelectionModelTest.java4
5 files changed, 144 insertions, 9 deletions
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/event/SelectionEvent.java b/compatibility-server/src/main/java/com/vaadin/v7/event/SelectionEvent.java
new file mode 100644
index 0000000000..b2378b01f1
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/event/SelectionEvent.java
@@ -0,0 +1,135 @@
+/*
+ * 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.v7.event;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EventObject;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+/**
+ * An event that specifies what in a selection has changed, and where the
+ * selection took place.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Deprecated
+public class SelectionEvent extends EventObject {
+
+ private LinkedHashSet<Object> oldSelection;
+ private LinkedHashSet<Object> newSelection;
+
+ public SelectionEvent(Object source, Collection<Object> oldSelection,
+ Collection<Object> newSelection) {
+ super(source);
+ this.oldSelection = new LinkedHashSet<>(oldSelection);
+ this.newSelection = new LinkedHashSet<>(newSelection);
+ }
+
+ /**
+ * A {@link Collection} of all the itemIds that became selected.
+ * <p>
+ * <em>Note:</em> this excludes all itemIds that might have been previously
+ * selected.
+ *
+ * @return a Collection of the itemIds that became selected
+ */
+ public Set<Object> getAdded() {
+ return setDifference(newSelection, oldSelection);
+ }
+
+ /**
+ * A {@link Collection} of all the itemIds that became deselected.
+ * <p>
+ * <em>Note:</em> this excludes all itemIds that might have been previously
+ * deselected.
+ *
+ * @return a Collection of the itemIds that became deselected
+ */
+ public Set<Object> getRemoved() {
+ return setDifference(oldSelection, newSelection);
+ }
+
+ /**
+ * Slightly optimized set difference that can return the original set or a
+ * modified one.
+ *
+ * @param set1
+ * original set
+ * @param set2
+ * the set to subtract
+ * @return the difference set
+ */
+ private static <T> Set<T> setDifference(Set<T> set1, Set<T> set2) {
+ if (set2.isEmpty()) {
+ return set1;
+ } else {
+ LinkedHashSet<T> set = new LinkedHashSet<>(set1);
+ set.removeAll(set2);
+ return set;
+ }
+ }
+
+ /**
+ * A {@link Collection} of all the itemIds that are currently selected.
+ *
+ * @return a Collection of the itemIds that are currently selected
+ */
+ public Set<Object> getSelected() {
+ return Collections.unmodifiableSet(newSelection);
+ }
+
+ /**
+ * The listener interface for receiving {@link SelectionEvent
+ * SelectionEvents}.
+ */
+ @Deprecated
+ public interface SelectionListener extends Serializable {
+ /**
+ * Notifies the listener that the selection state has changed.
+ *
+ * @param event
+ * the selection change event
+ */
+ void select(SelectionEvent event);
+ }
+
+ /**
+ * The interface for adding and removing listeners for {@link SelectionEvent
+ * SelectionEvents}.
+ */
+ @Deprecated
+ public interface SelectionNotifier extends Serializable {
+ /**
+ * Registers a new selection listener
+ *
+ * @param listener
+ * the listener to register
+ */
+ void addSelectionListener(SelectionListener listener);
+
+ /**
+ * Removes a previously registered selection change listener
+ *
+ * @param listener
+ * the listener to remove
+ */
+ void removeSelectionListener(SelectionListener listener);
+ }
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java
index f7bcd8075f..e213d7d585 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java
@@ -45,9 +45,6 @@ import org.jsoup.select.Elements;
import com.vaadin.data.sort.Sort;
import com.vaadin.data.sort.SortOrder;
import com.vaadin.event.ContextClickEvent;
-import com.vaadin.event.SelectionEvent;
-import com.vaadin.event.SelectionEvent.SelectionListener;
-import com.vaadin.event.SelectionEvent.SelectionNotifier;
import com.vaadin.event.SortEvent;
import com.vaadin.event.SortEvent.SortListener;
import com.vaadin.event.SortEvent.SortNotifier;
@@ -92,8 +89,11 @@ import com.vaadin.v7.data.util.IndexedContainer;
import com.vaadin.v7.data.util.converter.Converter;
import com.vaadin.v7.data.util.converter.ConverterUtil;
import com.vaadin.v7.event.ItemClickEvent;
+import com.vaadin.v7.event.SelectionEvent;
import com.vaadin.v7.event.ItemClickEvent.ItemClickListener;
import com.vaadin.v7.event.ItemClickEvent.ItemClickNotifier;
+import com.vaadin.v7.event.SelectionEvent.SelectionListener;
+import com.vaadin.v7.event.SelectionEvent.SelectionNotifier;
import com.vaadin.v7.server.communication.data.DataGenerator;
import com.vaadin.v7.server.communication.data.RpcDataProviderExtension;
import com.vaadin.v7.shared.ui.grid.EditorClientRpc;
diff --git a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/GridSelectionTest.java b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/GridSelectionTest.java
index e3eb01e273..afc38a4201 100644
--- a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/GridSelectionTest.java
+++ b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/GridSelectionTest.java
@@ -24,9 +24,9 @@ import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
-import com.vaadin.event.SelectionEvent;
-import com.vaadin.event.SelectionEvent.SelectionListener;
import com.vaadin.v7.data.util.IndexedContainer;
+import com.vaadin.v7.event.SelectionEvent;
+import com.vaadin.v7.event.SelectionEvent.SelectionListener;
import com.vaadin.v7.ui.Grid;
import com.vaadin.v7.ui.Grid.SelectionMode;
import com.vaadin.v7.ui.Grid.SelectionModel;
diff --git a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/MultiSelectionModelTest.java b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/MultiSelectionModelTest.java
index 7a658fd31f..f30b5ea141 100644
--- a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/MultiSelectionModelTest.java
+++ b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/MultiSelectionModelTest.java
@@ -24,10 +24,10 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import com.vaadin.event.SelectionEvent;
-import com.vaadin.event.SelectionEvent.SelectionListener;
import com.vaadin.v7.data.Container;
import com.vaadin.v7.data.util.IndexedContainer;
+import com.vaadin.v7.event.SelectionEvent;
+import com.vaadin.v7.event.SelectionEvent.SelectionListener;
import com.vaadin.v7.ui.Grid;
import com.vaadin.v7.ui.Grid.MultiSelectionModel;
import com.vaadin.v7.ui.Grid.SelectionMode;
diff --git a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/SingleSelectionModelTest.java b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/SingleSelectionModelTest.java
index d81bf62c02..e18c5bbe8b 100644
--- a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/SingleSelectionModelTest.java
+++ b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/grid/SingleSelectionModelTest.java
@@ -20,10 +20,10 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import com.vaadin.event.SelectionEvent;
-import com.vaadin.event.SelectionEvent.SelectionListener;
import com.vaadin.v7.data.Container;
import com.vaadin.v7.data.util.IndexedContainer;
+import com.vaadin.v7.event.SelectionEvent;
+import com.vaadin.v7.event.SelectionEvent.SelectionListener;
import com.vaadin.v7.ui.Grid;
import com.vaadin.v7.ui.Grid.SelectionMode;
import com.vaadin.v7.ui.Grid.SingleSelectionModel;