Class AbstractGridMultiSelectionModel<T>
- java.lang.Object
-
- com.vaadin.flow.component.grid.Grid.AbstractGridExtension<T>
-
- com.vaadin.flow.component.grid.AbstractGridMultiSelectionModel<T>
-
- Type Parameters:
T
- the grid type
- All Implemented Interfaces:
GridMultiSelectionModel<T>
,GridSelectionModel<T>
,DataGenerator<T>
,SelectionModel<Grid<T>,T>
,SelectionModel.Multi<Grid<T>,T>
,Serializable
public abstract class AbstractGridMultiSelectionModel<T> extends Grid.AbstractGridExtension<T> implements GridMultiSelectionModel<T>
Abstract implementation of a GridMultiSelectionModel.- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.grid.GridMultiSelectionModel
GridMultiSelectionModel.SelectAllCheckboxVisibility
-
Nested classes/interfaces inherited from interface com.vaadin.flow.data.selection.SelectionModel
SelectionModel.Multi<C extends Component,T>, SelectionModel.Single<C extends Component,T>
-
-
Constructor Summary
Constructors Constructor Description AbstractGridMultiSelectionModel(Grid<T> grid)
Constructor for passing a reference of the grid to this implementation.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Registration
addMultiSelectionListener(MultiSelectionListener<Grid<T>,T> listener)
Adds a selection listener that will be called when the selection is changed either by the user or programmatically.Registration
addSelectionListener(SelectionListener<Grid<T>,T> listener)
Adds a generic listener to this selection model, accepting both single and multiselection events.MultiSelect<Grid<T>,T>
asMultiSelect()
Gets a wrapper to use this multiselection model as a multiselect inBinder
.void
deselect(T item)
Deselects the given item.void
deselectAll()
Deselects all currently selected items, if any.void
deselectFromClient(T item)
Handles the deselection of an item that originates from the client.protected abstract void
fireSelectionEvent(SelectionEvent<Grid<T>,T> event)
Method for handling the firing of selection events.void
generateData(T item, elemental.json.JsonObject jsonObject)
Adds custom data for the given item to its serializedJsonObject
representation.Optional<T>
getFirstSelectedItem()
Get first selected data item.GridMultiSelectionModel.SelectAllCheckboxVisibility
getSelectAllCheckboxVisibility()
Gets the current mode for the select all checkbox visibility.protected Set<Object>
getSelectedItemIds()
Returns an unmodifiable view of the selected item ids.Set<T>
getSelectedItems()
Returns an immutable set of the currently selected items.boolean
isDragSelect()
Gets whether grid drag select is enabled or not.boolean
isSelectAllCheckboxVisible()
Returns whether the select all checkbox will be visible with the current setting ofGridMultiSelectionModel.setSelectAllCheckboxVisibility(SelectAllCheckboxVisibility)
and the type of data set to the Grid (in-memory or lazy).boolean
isSelected(T item)
Returns whether the given item is currently selected.boolean
isSelectionColumnFrozen()
Gets the the selection column's frozen state.protected void
remove()
Remove this extension from its target.void
select(T item)
Selects the given item.void
selectAll()
Selects all available the items.void
selectFromClient(T item)
Handles the selection of an item that originates from the client.void
setDragSelect(boolean dragSelect)
Iftrue
, grid rows can be selected or deselected by dragging the mouse cursor over grid's selection column.void
setSelectAllCheckboxVisibility(GridMultiSelectionModel.SelectAllCheckboxVisibility selectAllCheckBoxVisibility)
Sets the select all checkbox visibility mode.void
setSelectionColumnFrozen(boolean frozen)
Sets the selection column's frozen state.void
updateSelection(Set<T> addedItems, Set<T> removedItems)
Updates the selection by adding and removing the given items from it.-
Methods inherited from class com.vaadin.flow.component.grid.Grid.AbstractGridExtension
extend, getGrid, refresh
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.data.provider.DataGenerator
destroyAllData, destroyData, refreshData
-
Methods inherited from interface com.vaadin.flow.data.selection.SelectionModel.Multi
deselectItems, selectItems
-
-
-
-
Method Detail
-
remove
protected void remove()
Description copied from class:Grid.AbstractGridExtension
Remove this extension from its target.- Overrides:
remove
in classGrid.AbstractGridExtension<T>
-
selectFromClient
public void selectFromClient(T item)
Description copied from interface:GridSelectionModel
Handles the selection of an item that originates from the client.- Specified by:
selectFromClient
in interfaceGridSelectionModel<T>
- Parameters:
item
- the item being selected
-
deselectFromClient
public void deselectFromClient(T item)
Description copied from interface:GridSelectionModel
Handles the deselection of an item that originates from the client.- Specified by:
deselectFromClient
in interfaceGridSelectionModel<T>
- Parameters:
item
- the item being deselected
-
getSelectedItems
public Set<T> getSelectedItems()
Description copied from interface:SelectionModel
Returns an immutable set of the currently selected items. It is safe to invoke otherSelectionModel
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 interfaceSelectionModel<Grid<T>,T>
- Returns:
- the items in the current selection, not null
-
getSelectedItemIds
protected Set<Object> getSelectedItemIds()
Returns an unmodifiable view of the selected item ids.Exposed to be overridden within subclasses.
The returned Set may be a direct view of the internal data structures of this class. A defensive copy should be made by callers when iterating over this Set and modifying the selection during iteration to avoid ConcurrentModificationExceptions.
- Returns:
- An unmodifiable view of the selected item ids. Updates in the selection may or may not be directly reflected in the Set.
-
getFirstSelectedItem
public Optional<T> getFirstSelectedItem()
Description copied from interface:SelectionModel
Get first selected data item.This is the same as
SelectionModel.Single.getSelectedItem()
in case of single selection and the first selected item fromSelectionModel.getSelectedItems()
in case of multiselection.- Specified by:
getFirstSelectedItem
in interfaceSelectionModel<Grid<T>,T>
- Specified by:
getFirstSelectedItem
in interfaceSelectionModel.Multi<Grid<T>,T>
- Returns:
- the first selected item.
-
select
public void select(T item)
Description copied from interface:SelectionModel
Selects the given item. Depending on the implementation, may cause other items to be deselected. If the item is already selected, does nothing.- Specified by:
select
in interfaceSelectionModel<Grid<T>,T>
- Specified by:
select
in interfaceSelectionModel.Multi<Grid<T>,T>
- Parameters:
item
- the item to select, not null
-
deselect
public void deselect(T item)
Description copied from interface:SelectionModel
Deselects the given item. If the item is not currently selected, does nothing.- Specified by:
deselect
in interfaceSelectionModel<Grid<T>,T>
- Specified by:
deselect
in interfaceSelectionModel.Multi<Grid<T>,T>
- Parameters:
item
- the item to deselect, not null
-
selectAll
public void selectAll()
Description copied from interface:SelectionModel.Multi
Selects all available the items.- Specified by:
selectAll
in interfaceSelectionModel.Multi<Grid<T>,T>
-
deselectAll
public void deselectAll()
Description copied from interface:SelectionModel
Deselects all currently selected items, if any.- Specified by:
deselectAll
in interfaceSelectionModel<Grid<T>,T>
-
updateSelection
public void updateSelection(Set<T> addedItems, Set<T> removedItems)
Description copied from interface:SelectionModel.Multi
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.
- Specified by:
updateSelection
in interfaceSelectionModel.Multi<Grid<T>,T>
- Parameters:
addedItems
- the items to add, notnull
removedItems
- the items to remove, notnull
-
isSelected
public boolean isSelected(T item)
Description copied from interface:SelectionModel
Returns whether the given item is currently selected.- Specified by:
isSelected
in interfaceSelectionModel<Grid<T>,T>
- Parameters:
item
- the item to check, not null- Returns:
true
if the item is selected,false
otherwise
-
asMultiSelect
public MultiSelect<Grid<T>,T> asMultiSelect()
Description copied from interface:GridMultiSelectionModel
Gets a wrapper to use this multiselection model as a multiselect inBinder
.- Specified by:
asMultiSelect
in interfaceGridMultiSelectionModel<T>
- Returns:
- the multiselect wrapper
-
addSelectionListener
public Registration addSelectionListener(SelectionListener<Grid<T>,T> listener)
Description copied from interface:SelectionModel
Adds a generic listener to this selection model, accepting both single and multiselection events.- Specified by:
addSelectionListener
in interfaceSelectionModel<Grid<T>,T>
- Parameters:
listener
- the listener to add, notnull
- Returns:
- a registration handle for removing the listener
-
addMultiSelectionListener
public Registration addMultiSelectionListener(MultiSelectionListener<Grid<T>,T> listener)
Description copied from interface:GridMultiSelectionModel
Adds a selection listener that will be called when the selection is changed either by the user or programmatically.- Specified by:
addMultiSelectionListener
in interfaceGridMultiSelectionModel<T>
- Parameters:
listener
- the multi selection listener, notnull
- Returns:
- a registration for the listener
-
setSelectAllCheckboxVisibility
public void setSelectAllCheckboxVisibility(GridMultiSelectionModel.SelectAllCheckboxVisibility selectAllCheckBoxVisibility)
Description copied from interface:GridMultiSelectionModel
Sets the select all checkbox visibility mode.The default value is
GridMultiSelectionModel.SelectAllCheckboxVisibility.DEFAULT
, which means that the checkbox is only visible if the grid's data provider is in-memory.The select all checkbox will never be shown if the Grid uses lazy loading with unknown item count, i.e. no items count query provided to it, and even setting
GridMultiSelectionModel.SelectAllCheckboxVisibility.VISIBLE
won't make it visible.- Specified by:
setSelectAllCheckboxVisibility
in interfaceGridMultiSelectionModel<T>
- Parameters:
selectAllCheckBoxVisibility
- the visiblity mode to use- See Also:
GridMultiSelectionModel.SelectAllCheckboxVisibility
-
getSelectAllCheckboxVisibility
public GridMultiSelectionModel.SelectAllCheckboxVisibility getSelectAllCheckboxVisibility()
Description copied from interface:GridMultiSelectionModel
Gets the current mode for the select all checkbox visibility.- Specified by:
getSelectAllCheckboxVisibility
in interfaceGridMultiSelectionModel<T>
- Returns:
- the select all checkbox visibility mode
- See Also:
GridMultiSelectionModel.SelectAllCheckboxVisibility
,GridMultiSelectionModel.isSelectAllCheckboxVisible()
-
isSelectAllCheckboxVisible
public boolean isSelectAllCheckboxVisible()
Description copied from interface:GridMultiSelectionModel
Returns whether the select all checkbox will be visible with the current setting ofGridMultiSelectionModel.setSelectAllCheckboxVisibility(SelectAllCheckboxVisibility)
and the type of data set to the Grid (in-memory or lazy).The select all checkbox will never be shown if the Grid uses lazy loading with unknown item count, meaning that no count callback has been provided.
- Specified by:
isSelectAllCheckboxVisible
in interfaceGridMultiSelectionModel<T>
- Returns:
true
if the checkbox will be visible with the current settings- See Also:
GridMultiSelectionModel.SelectAllCheckboxVisibility
,GridMultiSelectionModel.setSelectAllCheckboxVisibility(SelectAllCheckboxVisibility)
-
generateData
public void generateData(T item, elemental.json.JsonObject jsonObject)
Description copied from interface:DataGenerator
Adds custom data for the given item to its serializedJsonObject
representation. This JSON object will be sent to client-side DataProvider.- Specified by:
generateData
in interfaceDataGenerator<T>
- Parameters:
item
- the data item being serializedjsonObject
- the JSON object being sent to the client
-
setSelectionColumnFrozen
public void setSelectionColumnFrozen(boolean frozen)
Description copied from interface:GridMultiSelectionModel
Sets the selection column's frozen state.- Specified by:
setSelectionColumnFrozen
in interfaceGridMultiSelectionModel<T>
- Parameters:
frozen
- whether to freeze or unfreeze the selection column
-
isSelectionColumnFrozen
public boolean isSelectionColumnFrozen()
Description copied from interface:GridMultiSelectionModel
Gets the the selection column's frozen state.- Specified by:
isSelectionColumnFrozen
in interfaceGridMultiSelectionModel<T>
- Returns:
- whether the selection column is frozen
-
setDragSelect
public void setDragSelect(boolean dragSelect)
Description copied from interface:GridMultiSelectionModel
Iftrue
, grid rows can be selected or deselected by dragging the mouse cursor over grid's selection column.- Specified by:
setDragSelect
in interfaceGridMultiSelectionModel<T>
- Parameters:
dragSelect
-true
to enable drag select feature,false
for disabling it
-
isDragSelect
public boolean isDragSelect()
Description copied from interface:GridMultiSelectionModel
Gets whether grid drag select is enabled or not.- Specified by:
isDragSelect
in interfaceGridMultiSelectionModel<T>
- Returns:
true
if drag select feature is enabled,false
otherwise
-
fireSelectionEvent
protected abstract void fireSelectionEvent(SelectionEvent<Grid<T>,T> event)
Method for handling the firing of selection events.- Parameters:
event
- the selection event to fire
-
-