com.vaadin.ui.components.grid.
Class MultiSelectionModelImpl<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.server.AbstractExtension
-
- com.vaadin.ui.AbstractListing.AbstractListingExtension<T>
-
- com.vaadin.ui.Grid.AbstractGridExtension<T>
-
- com.vaadin.ui.components.grid.AbstractSelectionModel<T>
-
- com.vaadin.ui.components.grid.MultiSelectionModelImpl<T>
-
Type Parameters:
T
- the type of the selected item in grid.All Implemented Interfaces:
DataGenerator<T>
,SelectionModel<T>
,SelectionModel.Multi<T>
,MethodEventSource
,ClientConnector
,Extension
,Connector
,GridSelectionModel<T>
,MultiSelectionModel<T>
,Serializable
Direct Known Subclasses:
public class MultiSelectionModelImpl<T> extends AbstractSelectionModel<T> implements MultiSelectionModel<T>
Multiselection model for grid.
Shows a column of checkboxes as the first column of grid. Each checkbox triggers the selection for that row.
Implementation detail: The Grid selection is updated immediately after user selection on client side, without waiting for the server response.
Since:
8.0
Author:
Vaadin Ltd.
See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.ui.components.grid.MultiSelectionModel
MultiSelectionModel.SelectAllCheckBoxVisibility
-
Nested classes/interfaces inherited from interface com.vaadin.data.SelectionModel
SelectionModel.Multi<T>, SelectionModel.Single<T>
-
-
Constructor Summary
Constructors Constructor Description MultiSelectionModelImpl()
-
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.
MultiSelect<T>
asMultiSelect()
Gets a wrapper for using this grid as a multiselect in a binder.
void
beforeClientResponse(boolean initial)
Called before the shared state and RPC invocations are sent to the client.
void
deselectAll()
Deselects all currently selected items, if any.
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.
protected MultiSelectionModelState
getState()
Returns the shared state for this connector.
protected MultiSelectionModelState
getState(boolean markAsDirty)
Returns the shared state for this connector.
protected void
init()
Initializes the selection model after it has been attached to a grid.
boolean
isAllSelected()
Returns whether all items are selected or not.
boolean
isSelectAllCheckBoxVisible()
Returns whether the select all checkbox will be visible with the current setting of
MultiSelectionModel.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)
.boolean
isSelected(T item)
Returns whether the given item is currently selected.
protected void
onDeselectAll(boolean userOriginated)
Triggered when the user unchecks the select all checkbox.
protected void
onSelectAll(boolean userOriginated)
Triggered when the user checks the select all checkbox.
void
refreshData(T item)
Informs the
DataGenerator
that a data object has been updated.void
selectAll()
Selects all available the items.
protected boolean
selectionContainsId(Object id)
Returns if the given id belongs to one of the selected items.
void
setSelectAllCheckBoxVisibility(MultiSelectionModel.SelectAllCheckBoxVisibility selectAllCheckBoxVisibility)
Sets the select all checkbox visibility mode.
protected void
updateCanSelectAll()
Controls whether the select all checkbox is visible in the grid default header, or not.
void
updateSelection(Set<T> addedItems, Set<T> removedItems)
Updates the selection by adding and removing the given items from it.
protected void
updateSelection(Set<T> addedItems, Set<T> removedItems, boolean userOriginated)
Updates the selection by adding and removing the given items.
-
Methods inherited from class com.vaadin.ui.components.grid.AbstractSelectionModel
destroyAllData, extend, generateData, getGrid, isUserSelectionAllowed, remove, setUserSelectionAllowed
-
Methods inherited from class com.vaadin.ui.Grid.AbstractGridExtension
addComponentToGrid, getInternalIdForColumn, getParent, removeComponentFromGrid
-
Methods inherited from class com.vaadin.ui.AbstractListing.AbstractListingExtension
getData, refresh
-
Methods inherited from class com.vaadin.server.AbstractExtension
extend, getSupportedParentType, setParent
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, attach, createState, detach, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isConnectorEnabled, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, attach, detach, encodeState, getErrorHandler, getExtensions, getParent, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
Methods inherited from interface com.vaadin.data.provider.DataGenerator
destroyData
-
Methods inherited from interface com.vaadin.ui.components.grid.GridSelectionModel
isUserSelectionAllowed, remove, setUserSelectionAllowed
-
Methods inherited from interface com.vaadin.ui.components.grid.MultiSelectionModel
addSelectionListener
-
Methods inherited from interface com.vaadin.data.SelectionModel.Multi
deselect, deselectItems, getFirstSelectedItem, select, selectItems
-
-
-
-
Method Detail
-
init
protected void init()
Description copied from class:
AbstractSelectionModel
Initializes the selection model after it has been attached to a grid.
Specified by:
init
in classAbstractSelectionModel<T>
-
getState
protected MultiSelectionModelState getState()
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector. The shared state object is shared between the server connector and the client connector. Changes are only communicated from the server to the client and not in the other direction.
As a side effect, marks the connector dirty so any changes done to the state will be sent to the client. Use
getState(false)
to avoid marking the connector as dirty.Overrides:
getState
in classAbstractSelectionModel<T>
Returns:
The shared state for this connector. Never null.
-
getState
protected MultiSelectionModelState getState(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
getState
in classAbstractSelectionModel<T>
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
setSelectAllCheckBoxVisibility
public void setSelectAllCheckBoxVisibility(MultiSelectionModel.SelectAllCheckBoxVisibility selectAllCheckBoxVisibility)
Description copied from interface:
MultiSelectionModel
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.Specified by:
setSelectAllCheckBoxVisibility
in interfaceMultiSelectionModel<T>
Parameters:
selectAllCheckBoxVisibility
- the visiblity mode to useSee Also:
-
getSelectAllCheckBoxVisibility
public MultiSelectionModel.SelectAllCheckBoxVisibility getSelectAllCheckBoxVisibility()
Description copied from interface:
MultiSelectionModel
Gets the current mode for the select all checkbox visibility.
Specified by:
getSelectAllCheckBoxVisibility
in interfaceMultiSelectionModel<T>
Returns:
the select all checkbox visibility mode
See Also:
MultiSelectionModel.SelectAllCheckBoxVisibility
,MultiSelectionModel.isSelectAllCheckBoxVisible()
-
isSelectAllCheckBoxVisible
public boolean isSelectAllCheckBoxVisible()
Description copied from interface:
MultiSelectionModel
Returns whether the select all checkbox will be visible with the current setting of
MultiSelectionModel.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)
.Specified by:
isSelectAllCheckBoxVisible
in interfaceMultiSelectionModel<T>
Returns:
true
if the checkbox will be visible with the current settingsSee Also:
MultiSelectionModel.SelectAllCheckBoxVisibility
,MultiSelectionModel.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)
-
isAllSelected
public boolean isAllSelected()
Description copied from interface:
MultiSelectionModel
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 ifSelectionModel.Multi.selectAll()
has been used from server side.Specified by:
isAllSelected
in interfaceMultiSelectionModel<T>
Returns:
true
if all selected,false
if not
-
isSelected
public boolean isSelected(T item)
Description copied from interface:
SelectionModel
Returns whether the given item is currently selected.
Specified by:
isSelected
in interfaceSelectionModel<T>
Parameters:
item
- the item to check, not nullReturns:
true
if the item is selected,false
otherwise
-
selectionContainsId
protected boolean selectionContainsId(Object id)
Returns if the given id belongs to one of the selected items.
Parameters:
id
- the id to check forReturns:
true
if id is selected,false
if not
-
beforeClientResponse
public void beforeClientResponse(boolean initial)
Description copied from interface:
ClientConnector
Called before the shared state and RPC invocations are sent to the client. Gives the connector an opportunity to set computed/dynamic state values or to invoke last minute RPC methods depending on other component features.
Specified by:
beforeClientResponse
in interfaceClientConnector
Overrides:
beforeClientResponse
in classAbstractClientConnector
Parameters:
initial
-true
if the client-side connector will be created and initialized after this method has been invoked.false
if there is already an initialized client-side connector.
-
updateCanSelectAll
protected void updateCanSelectAll()
Controls whether the select all checkbox is visible in the grid default header, or not.
This is updated as a part of
beforeClientResponse(boolean)
, since the data provider for grid can be changed on the fly.
-
addMultiSelectionListener
public Registration addMultiSelectionListener(MultiSelectionListener<T> listener)
Description copied from interface:
MultiSelectionModel
Adds a selection listener that will be called when the selection is changed either by the user or programmatically.
Specified by:
addMultiSelectionListener
in interfaceMultiSelectionModel<T>
Parameters:
listener
- the value change listener, notnull
Returns:
a registration for the listener
-
getSelectedItems
public Set<T> getSelectedItems()
Description copied from interface:
SelectionModel
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 interfaceSelectionModel<T>
Returns:
the items in the current selection, not null
-
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<T>
Parameters:
addedItems
- the items to add, notnull
removedItems
- the items to remove, notnull
-
selectAll
public void selectAll()
Description copied from interface:
SelectionModel.Multi
Selects all available the items.
Specified by:
selectAll
in interfaceSelectionModel.Multi<T>
-
deselectAll
public void deselectAll()
Description copied from interface:
SelectionModel
Deselects all currently selected items, if any.
Specified by:
deselectAll
in interfaceSelectionModel<T>
-
asMultiSelect
public MultiSelect<T> asMultiSelect()
Gets a wrapper for using this grid as a multiselect in a binder.
Specified by:
asMultiSelect
in interfaceMultiSelectionModel<T>
Returns:
a multiselect wrapper for grid
-
onSelectAll
protected void onSelectAll(boolean userOriginated)
Triggered when the user checks the select all checkbox.
Parameters:
userOriginated
-true
if originated from client side by user
-
onDeselectAll
protected void onDeselectAll(boolean userOriginated)
Triggered when the user unchecks the select all checkbox.
Parameters:
userOriginated
-true
if originated from client side by user
-
updateSelection
protected void updateSelection(Set<T> addedItems, Set<T> removedItems, boolean userOriginated)
Updates the selection by adding and removing the given items.
All selection updates should go through this method, since it handles incorrect parameters, removing duplicates, notifying data communicator and and firing events.
Parameters:
addedItems
- the items added to selection, not nullremovedItems
- the items removed from selection, not nulluserOriginated
-true
if this was used originated,false
if not
-
refreshData
public void refreshData(T item)
Description copied from interface:
DataGenerator
Informs the
DataGenerator
that a data object has been updated. This method should update any unneeded information stored for given item.Specified by:
refreshData
in interfaceDataGenerator<T>
Parameters:
item
- the updated item
-
-