summaryrefslogtreecommitdiffstats
path: root/shared/src
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2016-09-22 14:19:34 +0300
committerVaadin Code Review <review@vaadin.com>2016-09-27 07:23:36 +0000
commit7e78d52dfe72678cf275585bc552b1612844da44 (patch)
treea6d3454fdb59f6a2e69c0bab125c228dca93a169 /shared/src
parent0052d59a318075a3ce8202b2eab84e9d643fc544 (diff)
downloadvaadin-framework-7e78d52dfe72678cf275585bc552b1612844da44.tar.gz
vaadin-framework-7e78d52dfe72678cf275585bc552b1612844da44.zip
TwinColSelect with new databinding API
Removes feature for adding new items. Introduces a AbstractMultiSelect-abstraction layer, which is used in server side by TwinColSelect & CheckBoxGroup and on client side only TwinColSelect for now. Plan is to use it for ListSelect too. Further improvement would be to make AbstractMultiSelect use SelectionModel that extends AbstractSelectionModel and is thus used as an extension both as client & server side. Updates to JUnit 4.12 for easier use of @Parameterized test.. Change-Id: I64258c2229b9514d382693748e2ca562a1e448d4
Diffstat (limited to 'shared/src')
-rw-r--r--shared/src/main/java/com/vaadin/shared/data/selection/MultiSelectServerRpc.java41
-rw-r--r--shared/src/main/java/com/vaadin/shared/data/selection/SelectionModel.java81
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/ListingJsonConstants.java (renamed from shared/src/main/java/com/vaadin/shared/ui/optiongroup/CheckBoxGroupConstants.java)6
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/twincolselect/TwinColSelectState.java (renamed from shared/src/main/java/com/vaadin/shared/ui/optiongroup/RadioButtonGroupConstants.java)27
4 files changed, 135 insertions, 20 deletions
diff --git a/shared/src/main/java/com/vaadin/shared/data/selection/MultiSelectServerRpc.java b/shared/src/main/java/com/vaadin/shared/data/selection/MultiSelectServerRpc.java
new file mode 100644
index 0000000000..a924f00d11
--- /dev/null
+++ b/shared/src/main/java/com/vaadin/shared/data/selection/MultiSelectServerRpc.java
@@ -0,0 +1,41 @@
+/*
+ * 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.util.Set;
+
+import com.vaadin.shared.communication.ServerRpc;
+
+/**
+ * Transmits SelectionModel selection changes from the client to the server.
+ *
+ * @author Vaadin Ltd
+ *
+ * @since 8.0
+ */
+public interface MultiSelectServerRpc extends ServerRpc {
+
+ /**
+ * Updates the selected items based on their keys.
+ *
+ * @param addedItemKeys
+ * the item keys added to selection
+ * @param removedItemKeys
+ * the item keys removed from selection
+ */
+ void updateSelection(Set<String> addedItemKeys,
+ Set<String> removedItemKeys);
+}
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
index 8711d6a9c8..c56fe8c4d9 100644
--- a/shared/src/main/java/com/vaadin/shared/data/selection/SelectionModel.java
+++ b/shared/src/main/java/com/vaadin/shared/data/selection/SelectionModel.java
@@ -16,9 +16,13 @@
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
@@ -60,7 +64,7 @@ public interface SelectionModel<T> extends Serializable {
/**
* 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
*/
@@ -78,11 +82,11 @@ public interface SelectionModel<T> extends Serializable {
*
* @return a singleton set of the selected item if any, an empty set
* otherwise
- *
+ *
* @see #getSelectedItem()
*/
@Override
- default Set<T> getSelectedItems() {
+ public default Set<T> getSelectedItems() {
return getSelectedItem().map(Collections::singleton)
.orElse(Collections.emptySet());
}
@@ -98,10 +102,77 @@ public interface SelectionModel<T> extends Serializable {
public interface Multi<T> extends SelectionModel<T> {
/**
- * Adds the given items to the set of currently selected items.
+ * 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 void select(T item);
+ 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);
}
/**
diff --git a/shared/src/main/java/com/vaadin/shared/ui/optiongroup/CheckBoxGroupConstants.java b/shared/src/main/java/com/vaadin/shared/ui/ListingJsonConstants.java
index 6bca43852a..82431bf7f1 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/optiongroup/CheckBoxGroupConstants.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/ListingJsonConstants.java
@@ -13,18 +13,16 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.vaadin.shared.ui.optiongroup;
+package com.vaadin.shared.ui;
import java.io.Serializable;
-public class CheckBoxGroupConstants implements Serializable {
+public class ListingJsonConstants implements Serializable {
public static final String JSONKEY_ITEM_DISABLED = "d";
public static final String JSONKEY_ITEM_ICON = "i";
public static final String JSONKEY_ITEM_VALUE = "v";
- public static final String JSONKEY_ITEM_KEY = "k";
-
public static final String JSONKEY_ITEM_SELECTED = "s";
}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/optiongroup/RadioButtonGroupConstants.java b/shared/src/main/java/com/vaadin/shared/ui/twincolselect/TwinColSelectState.java
index 5278d211de..a6b09c0e91 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/optiongroup/RadioButtonGroupConstants.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/twincolselect/TwinColSelectState.java
@@ -13,18 +13,23 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.vaadin.shared.ui.optiongroup;
+package com.vaadin.shared.ui.twincolselect;
-import java.io.Serializable;
+import com.vaadin.shared.annotations.DelegateToWidget;
+import com.vaadin.shared.ui.TabIndexState;
-public class RadioButtonGroupConstants implements Serializable {
- public static final String JSONKEY_ITEM_DISABLED = "d";
-
- public static final String JSONKEY_ITEM_ICON = "i";
-
- public static final String JSONKEY_ITEM_VALUE = "v";
-
- public static final String JSONKEY_ITEM_KEY = "k";
+/**
+ * Shared state for the TwinColSelect component.
+ *
+ * @since 7.0
+ */
+public class TwinColSelectState extends TabIndexState {
+ {
+ primaryStyleName = "v-select-twincol";
+ }
+ @DelegateToWidget
+ public int rows;
- public static final String JSONKEY_ITEM_SELECTED = "s";
+ public String leftColumnCaption;
+ public String rightColumnCaption;
}