diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/src/main/java/com/vaadin/shared/data/selection/MultiSelectServerRpc.java | 41 | ||||
-rw-r--r-- | shared/src/main/java/com/vaadin/shared/data/selection/SelectionModel.java | 81 | ||||
-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; } |