Class GridMultiSelect<T>
- java.lang.Object
-
- com.vaadin.ui.components.grid.GridMultiSelect<T>
-
- Type Parameters:
T- the bean type of grid
- All Implemented Interfaces:
HasValue<Set<T>>,MultiSelect<T>,Serializable
public class GridMultiSelect<T> extends Object implements MultiSelect<T>
Wrapper class to wrap Grid into a MultiSelect. This class also provides useful access to API of MultiSelectionModel.- Since:
- 8.6.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.data.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
-
-
Constructor Summary
Constructors Constructor Description GridMultiSelect(Grid<T> grid)Constructs a MultiSelect wrapper for given Grid.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistrationaddMultiSelectionListener(MultiSelectionListener<T> listener)Adds a selection listener that will be called when the selection is changed either by the user or programmatically.RegistrationaddSelectionListener(MultiSelectionListener<T> listener)Adds a selection listener that will be called when the selection is changed either by the user or programmatically.RegistrationaddSelectionListener(SelectionListener<T> listener)Adds a generic listener to this selection model, accepting both single and multiselection events.RegistrationaddValueChangeListener(HasValue.ValueChangeListener<Set<T>> listener)Adds a value change listener.voiddeselect(T item)Selects the given item.voiddeselectAll()Deselects all currently selected items, if any.voiddeselectItems(T... items)Removes the given items from the set of currently selected items.Optional<T>getFirstSelectedItem()Get first selected data item.MultiSelectionModel.SelectAllCheckBoxVisibilitygetSelectAllCheckBoxVisibility()Gets the current mode for the select all checkbox visibility.Set<T>getSelectedItems()Returns an immutable set of the currently selected items.Set<T>getValue()Returns the current value of this object.booleanisAllSelected()Returns whether all items are selected or not.booleanisReadOnly()Returns whether thisHasValueis in read-only mode or not.booleanisRequiredIndicatorVisible()Checks whether the required indicator is visible.booleanisSelectAllCheckBoxVisible()Returns whether the select all checkbox will be visible with the current setting ofsetSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility).booleanisUserSelectionAllowed()Checks if the user is allowed to change the selection.voidselect(T item)Selects the given item.voidselectAll()Selects all available the items.voidselectItems(T... items)Adds the given items to the set of currently selected items.voidsetReadOnly(boolean readOnly)Sets the read-only mode of thisHasValueto given mode.voidsetRequiredIndicatorVisible(boolean requiredIndicatorVisible)Sets the required indicator visible or not.voidsetSelectAllCheckBoxVisibility(MultiSelectionModel.SelectAllCheckBoxVisibility visibility)Sets the select all checkbox visibility mode.voidsetUserSelectionAllowed(boolean allowed)Sets whether the user is allowed to change the selection.voidsetValue(Set<T> value)Sets the value of this object.voidupdateSelection(Set<T> addedItems, Set<T> removedItems)Updates the selection by adding and removing the given items from it.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.data.HasValue
clear, getDefaultValidator, getOptionalValue, isEmpty
-
Methods inherited from interface com.vaadin.ui.MultiSelect
deselect, getEmptyValue, isSelected, select
-
-
-
-
Method Detail
-
getFirstSelectedItem
public Optional<T> getFirstSelectedItem()
Get first selected data item.- Returns:
- the first selected item.
-
selectAll
public void selectAll()
Selects all available the items.
-
deselect
public void deselect(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
-
select
public void select(T item)
Selects the given item. If another item was already selected, that item is deselected.- Parameters:
item- the item to select
-
deselectAll
public void deselectAll()
Deselects all currently selected items, if any.- Specified by:
deselectAllin interfaceMultiSelect<T>
-
selectItems
public void selectItems(T... items)
Adds the given items to the set of currently selected items.By default this does not clear any previous selection. To do that, use
deselectAll().If the all the items were already selected, this is a NO-OP.
This is a short-hand for
updateSelection(Set, Set)with nothing to deselect.- Parameters:
items- to add to selection, notnull
-
deselectItems
public void deselectItems(T... items)
Removes the given items from the set of currently selected items.If the none of the items were selected, this is a NO-OP.
This is a short-hand for
updateSelection(Set, Set)with nothing to select.- Parameters:
items- to remove from selection, notnull
-
setSelectAllCheckBoxVisibility
public void setSelectAllCheckBoxVisibility(MultiSelectionModel.SelectAllCheckBoxVisibility visibility)
Sets the select all checkbox visibility mode.The default value is
MultiSelectionModel.SelectAllCheckBoxVisibility.DEFAULT, which means that the checkbox is only visible if the grid's data provider is in- memory.- Parameters:
visibility- the visiblity mode to use- See Also:
MultiSelectionModel.SelectAllCheckBoxVisibility
-
getSelectAllCheckBoxVisibility
public MultiSelectionModel.SelectAllCheckBoxVisibility getSelectAllCheckBoxVisibility()
Gets the current mode for the select all checkbox visibility.- Returns:
- the select all checkbox visibility mode
- See Also:
MultiSelectionModel.SelectAllCheckBoxVisibility,isSelectAllCheckBoxVisible()
-
isSelectAllCheckBoxVisible
public boolean isSelectAllCheckBoxVisible()
Returns whether the select all checkbox will be visible with the current setting ofsetSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility).- Returns:
trueif the checkbox will be visible with the current settings- See Also:
MultiSelectionModel.SelectAllCheckBoxVisibility,setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)
-
setUserSelectionAllowed
public void setUserSelectionAllowed(boolean allowed)
Sets whether the user is allowed to change the selection.The check is done only for the client side actions. It doesn't affect selection requests sent from the server side.
- Parameters:
allowed-trueif the user is allowed to change the selection,falseotherwise
-
isAllSelected
public boolean isAllSelected()
Returns whether all items are selected or not.This is only
trueif user has selected all rows with the select all checkbox on client side, or ifselectAll()has been used from server side.- Returns:
trueif all selected,falseif not- Since:
- 8.12.0
-
isUserSelectionAllowed
public boolean isUserSelectionAllowed()
Checks if the user is allowed to change the selection.The check is done only for the client side actions. It doesn't affect selection requests sent from the server side.
- Returns:
trueif the user is allowed to change the selection,falseotherwise
-
addSelectionListener
public 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
-
addMultiSelectionListener
public Registration addMultiSelectionListener(MultiSelectionListener<T> listener)
Adds a selection listener that will be called when the selection is changed either by the user or programmatically.- Parameters:
listener- the value change listener, notnull- Returns:
- a registration for the listener
-
setValue
public void setValue(Set<T> value)
Description copied from interface:HasValueSets the value of this object. If the new value is not equal togetValue(), fires a value change event. May throwIllegalArgumentExceptionif the value is not acceptable.Implementation note: the implementing class should document whether null values are accepted or not.
-
getValue
public Set<T> getValue()
Description copied from interface:HasValueReturns the current value of this object.Implementation note: the implementing class should document whether null values may be returned or not.
-
addValueChangeListener
public Registration addValueChangeListener(HasValue.ValueChangeListener<Set<T>> listener)
Description copied from interface:HasValueAdds a value change listener. The listener is called when the value of thisHasValueis changed either by the user or programmatically.- Specified by:
addValueChangeListenerin interfaceHasValue<T>- Parameters:
listener- the value change listener, not null- Returns:
- a registration for the listener
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Description copied from interface:HasValueSets the required indicator visible or not.If set visible, it is visually indicated in the user interface.
- Specified by:
setRequiredIndicatorVisiblein interfaceHasValue<T>- Parameters:
requiredIndicatorVisible-trueto make the required indicator visible,falseif not
-
isRequiredIndicatorVisible
public boolean isRequiredIndicatorVisible()
Description copied from interface:HasValueChecks whether the required indicator is visible.- Specified by:
isRequiredIndicatorVisiblein interfaceHasValue<T>- Returns:
trueif visible,falseif not
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from interface:HasValueSets the read-only mode of thisHasValueto given mode. The user can't change the value when in read-only mode.A
HasValuewith a visual component in read-only mode typically looks visually different to signal to the user that the value cannot be edited.- Specified by:
setReadOnlyin interfaceHasValue<T>- Parameters:
readOnly- a boolean value specifying whether the component is put read-only mode or not
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:HasValueReturns whether thisHasValueis in read-only mode or not.- Specified by:
isReadOnlyin interfaceHasValue<T>- Returns:
falseif the user can modify the value,trueif not.
-
updateSelection
public void updateSelection(Set<T> addedItems, Set<T> removedItems)
Description copied from interface:MultiSelectUpdates the selection by adding and removing the given items from it.If all the added items were already selected and the removed items were not selected, this is a NO-OP.
Duplicate items (in both add & remove sets) are ignored and removed from the sets.
- Specified by:
updateSelectionin interfaceMultiSelect<T>- Parameters:
addedItems- the items to add, notnullremovedItems- the items to remove, notnull
-
getSelectedItems
public Set<T> getSelectedItems()
Description copied from interface:MultiSelectReturns 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.
- Specified by:
getSelectedItemsin interfaceMultiSelect<T>- Returns:
- the items in the current selection, not null
-
addSelectionListener
public Registration addSelectionListener(MultiSelectionListener<T> listener)
Description copied from interface:MultiSelectAdds a selection listener that will be called when the selection is changed either by the user or programmatically.- Specified by:
addSelectionListenerin interfaceMultiSelect<T>- Parameters:
listener- the value change listener, notnull- Returns:
- a registration for the listener
-
-