aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/data/SelectionModel.java
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2016-11-07 09:16:37 +0200
committerIlia Motornyi <elmot@vaadin.com>2016-11-10 07:49:08 +0000
commit39c15034076015a16cd056adf9dc422335985543 (patch)
tree8bb235b285e69cb48b83de067152f06d7c076e8d /server/src/main/java/com/vaadin/data/SelectionModel.java
parent0f42869ce1f81270141e94f169f1447febaff446 (diff)
downloadvaadin-framework-39c15034076015a16cd056adf9dc422335985543.tar.gz
vaadin-framework-39c15034076015a16cd056adf9dc422335985543.zip
Remove HasValue from Grid
Extracts grid single selection into separate class, which is an extension like in V7. Using an extension makes it possible to easily add multiselect and no-select modes back, and support custom selection models. Adds Grid:asSingleSelect() SingleSelect so that grid can be used as a Select in a binder. Removes all remaining references to SelectionModels in Listings. Renames SingleSelectionChangeEvent to SingleSelectionEvent, because then it is unified with selection listener and MultiSelectionEvent. Fixes vaadin/framework8-issues#424 Fixes vaadin/framework8-issues#425 Change-Id: Ie22bef29cfd4336c3f65d4e63531c578b8dd76a3
Diffstat (limited to 'server/src/main/java/com/vaadin/data/SelectionModel.java')
-rw-r--r--server/src/main/java/com/vaadin/data/SelectionModel.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/data/SelectionModel.java b/server/src/main/java/com/vaadin/data/SelectionModel.java
index eca43e6c8d..98a068993a 100644
--- a/server/src/main/java/com/vaadin/data/SelectionModel.java
+++ b/server/src/main/java/com/vaadin/data/SelectionModel.java
@@ -90,6 +90,11 @@ public interface SelectionModel<T> extends Serializable {
return getSelectedItem().map(Collections::singleton)
.orElse(Collections.emptySet());
}
+
+ @Override
+ default Optional<T> getFirstSelectedItem() {
+ return getSelectedItem();
+ }
}
/**
@@ -173,6 +178,11 @@ public interface SelectionModel<T> extends Serializable {
* the items to remove, not {@code null}
*/
public void updateSelection(Set<T> addedItems, Set<T> removedItems);
+
+ @Override
+ default Optional<T> getFirstSelectedItem() {
+ return getSelectedItems().stream().findFirst();
+ }
}
/**
@@ -188,6 +198,17 @@ public interface SelectionModel<T> extends Serializable {
public Set<T> getSelectedItems();
/**
+ * Get first selected data item.
+ * <p>
+ * This is the same as {@link Single#getSelectedItem()} in case of single
+ * selection and the first selected item from
+ * {@link Multi#getSelectedItems()} in case of multiselection.
+ *
+ * @return the first selected item.
+ */
+ Optional<T> getFirstSelectedItem();
+
+ /**
* Selects the given item. Depending on the implementation, may cause other
* items to be deselected. If the item is already selected, does nothing.
*