Package com.vaadin.data
Interface SelectionModel<T>
-
- Type Parameters:
T- the type of the items to select
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
GridSelectionModel<T>,MultiSelectionModel<T>,SelectionModel.Multi<T>,SelectionModel.Single<T>,SingleSelectionModel<T>
- All Known Implementing Classes:
AbstractSelectionModel,MultiSelectionModelImpl,NoSelectionModel,SingleSelectionModelImpl,Tree.TreeMultiSelectionModel
public interface SelectionModel<T> extends Serializable
Models the selection logic of aListingcomponent. Determines how items can be selected and deselected.- Since:
- 8.0
- Author:
- Vaadin Ltd.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceSelectionModel.Multi<T>A selection model in which multiple items can be selected at the same time.static interfaceSelectionModel.Single<T>A selection model in which at most one item can be selected at a time.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description RegistrationaddSelectionListener(SelectionListener<T> listener)Adds a generic listener to this selection model, accepting both single and multiselection events.voiddeselect(T item)Deselects the given item.voiddeselectAll()Deselects all currently selected items, if any.Optional<T>getFirstSelectedItem()Get first selected data item.Set<T>getSelectedItems()Returns an immutable set of the currently selected items.default booleanisSelected(T item)Returns whether the given item is currently selected.voidselect(T item)Selects the given item.
-
-
-
Method Detail
-
getSelectedItems
Set<T> getSelectedItems()
Returns an immutable set of the currently selected items. It is safe to invoke otherSelectionModelmethods while iterating over the set.Implementation note: the iteration order of the items in the returned set should be well-defined and documented by the implementing class.
- Returns:
- the items in the current selection, not null
-
getFirstSelectedItem
Optional<T> getFirstSelectedItem()
Get first selected data item.This is the same as
SelectionModel.Single.getSelectedItem()in case of single selection and the first selected item fromgetSelectedItems()in case of multiselection.- Returns:
- the first selected item.
-
select
void select(T item)
Selects the given item. Depending on the implementation, may cause other items to be deselected. If the item is already selected, does nothing.- Parameters:
item- the item to select, not null
-
deselect
void deselect(T item)
Deselects the given item. If the item is not currently selected, does nothing.- Parameters:
item- the item to deselect, not null
-
deselectAll
void deselectAll()
Deselects all currently selected items, if any.
-
isSelected
default boolean isSelected(T item)
Returns whether the given item is currently selected.- Parameters:
item- the item to check, not null- Returns:
trueif the item is selected,falseotherwise
-
addSelectionListener
Registration addSelectionListener(SelectionListener<T> listener)
Adds a generic listener to this selection model, accepting both single and multiselection events.- Parameters:
listener- the listener to add- Returns:
- a registration handle for removing the listener
-
-