summaryrefslogtreecommitdiffstats
path: root/shared
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2016-09-13 16:48:39 +0300
committerJohannes Dahlström <johannesd@vaadin.com>2016-09-14 13:07:11 +0300
commit2a0c590bfae9b630838ae8f85637543c2a7d160f (patch)
tree3ed0220603a5be76ef9071b2992bdfde90414ffc /shared
parent41516b54350bdfb597d6f60961266d3c2c57b880 (diff)
downloadvaadin-framework-2a0c590bfae9b630838ae8f85637543c2a7d160f.tar.gz
vaadin-framework-2a0c590bfae9b630838ae8f85637543c2a7d160f.zip
Implement support for binding single-select components
Change-Id: I340e802e5c8e6e036b54f81ec46beeb5e1c34329
Diffstat (limited to 'shared')
-rw-r--r--shared/src/main/java/com/vaadin/shared/data/selection/SelectionModel.java23
1 files changed, 20 insertions, 3 deletions
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 115c43013b..8711d6a9c8 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
@@ -58,11 +58,28 @@ public interface SelectionModel<T> extends Serializable {
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
default Set<T> getSelectedItems() {
@@ -85,13 +102,13 @@ public interface SelectionModel<T> extends Serializable {
*/
@Override
public void select(T item);
-
}
/**
- * Returns an immutable set of the currently selected items.
+ * Returns an immutable set of the currently selected items. It is safe to
+ * invoke other {@code SelectionModel} methods while iterating over the set.
* <p>
- * <i>Implementation note:</i> the iteration order of the items in the
+ * <em>Implementation note:</em> the iteration order of the items in the
* returned set should be well-defined and documented by the implementing
* class.
*