com.vaadin.ui.components.grid.
Class GridMultiSelect<T>
- java.lang.Object
-
- com.vaadin.ui.components.grid.GridMultiSelect<T>
-
Type Parameters:
T
- the bean type of gridAll 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:
-
-
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 Modifier and Type Method Description Registration
addMultiSelectionListener(MultiSelectionListener<T> listener)
Adds a selection listener that will be called when the selection is changed either by the user or programmatically.
Registration
addSelectionListener(MultiSelectionListener<T> listener)
Adds a selection listener that will be called when the selection is changed either by the user or programmatically.
Registration
addSelectionListener(SelectionListener<T> listener)
Adds a generic listener to this selection model, accepting both single and multiselection events.
Registration
addValueChangeListener(HasValue.ValueChangeListener<Set<T>> listener)
Adds a value change listener.
void
deselect(T item)
Selects the given item.
void
deselectAll()
Deselects all currently selected items, if any.
void
deselectItems(T... items)
Removes the given items from the set of currently selected items.
Optional<T>
getFirstSelectedItem()
Get first selected data item.
MultiSelectionModel.SelectAllCheckBoxVisibility
getSelectAllCheckBoxVisibility()
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.
boolean
isAllSelected()
Returns whether all items are selected or not.
boolean
isReadOnly()
Returns whether this
HasValue
is in read-only mode or not.boolean
isRequiredIndicatorVisible()
Checks whether the required indicator is visible.
boolean
isSelectAllCheckBoxVisible()
Returns whether the select all checkbox will be visible with the current setting of
setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)
.boolean
isUserSelectionAllowed()
Checks if the user is allowed to change the selection.
void
select(T item)
Selects the given item.
void
selectAll()
Selects all available the items.
void
selectItems(T... items)
Adds the given items to the set of currently selected items.
void
setReadOnly(boolean readOnly)
Sets the read-only mode of this
HasValue
to given mode.void
setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets the required indicator visible or not.
void
setSelectAllCheckBoxVisibility(MultiSelectionModel.SelectAllCheckBoxVisibility visibility)
Sets the select all checkbox visibility mode.
void
setUserSelectionAllowed(boolean allowed)
Sets whether the user is allowed to change the selection.
void
setValue(Set<T> value)
Sets the value of this object.
void
updateSelection(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:
deselectAll
in 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 useSee Also:
-
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 of
setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)
.Returns:
true
if the checkbox will be visible with the current settingsSee 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
-true
if the user is allowed to change the selection,false
otherwise
-
isAllSelected
public boolean isAllSelected()
Returns whether all items are selected or not.
This is only
true
if user has selected all rows with the select all checkbox on client side, or ifselectAll()
has been used from server side.Returns:
true
if all selected,false
if notSince:
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:
true
if the user is allowed to change the selection,false
otherwise
-
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 addReturns:
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:
HasValue
Sets the value of this object. If the new value is not equal to
getValue()
, fires a value change event. May throwIllegalArgumentException
if 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:
HasValue
Returns 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:
HasValue
Adds a value change listener. The listener is called when the value of this
HasValue
is changed either by the user or programmatically.Specified by:
addValueChangeListener
in interfaceHasValue<T>
Parameters:
listener
- the value change listener, not nullReturns:
a registration for the listener
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Description copied from interface:
HasValue
Sets the required indicator visible or not.
If set visible, it is visually indicated in the user interface.
Specified by:
setRequiredIndicatorVisible
in interfaceHasValue<T>
Parameters:
requiredIndicatorVisible
-true
to make the required indicator visible,false
if not
-
isRequiredIndicatorVisible
public boolean isRequiredIndicatorVisible()
Description copied from interface:
HasValue
Checks whether the required indicator is visible.
Specified by:
isRequiredIndicatorVisible
in interfaceHasValue<T>
Returns:
true
if visible,false
if not
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from interface:
HasValue
Sets the read-only mode of this
HasValue
to given mode. The user can't change the value when in read-only mode.A
HasValue
with a visual component in read-only mode typically looks visually different to signal to the user that the value cannot be edited.Specified by:
setReadOnly
in 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:
HasValue
Returns whether this
HasValue
is in read-only mode or not.Specified by:
isReadOnly
in interfaceHasValue<T>
Returns:
false
if the user can modify the value,true
if not.
-
updateSelection
public void updateSelection(Set<T> addedItems, Set<T> removedItems)
Description copied from interface:
MultiSelect
Updates 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:
updateSelection
in interfaceMultiSelect<T>
Parameters:
addedItems
- the items to add, notnull
removedItems
- the items to remove, notnull
-
getSelectedItems
public Set<T> getSelectedItems()
Description copied from interface:
MultiSelect
Returns an immutable set of the currently selected items. It is safe to invoke other
SelectionModel
methods 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:
getSelectedItems
in interfaceMultiSelect<T>
Returns:
the items in the current selection, not null
-
addSelectionListener
public Registration addSelectionListener(MultiSelectionListener<T> listener)
Description copied from interface:
MultiSelect
Adds a selection listener that will be called when the selection is changed either by the user or programmatically.
Specified by:
addSelectionListener
in interfaceMultiSelect<T>
Parameters:
listener
- the value change listener, notnull
Returns:
a registration for the listener
-
-