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:
Tree.TreeMultiSelectionModel
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:
- Serialized Form
-
-
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 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.MultiSelect<T>asMultiSelect()Gets a wrapper for using this grid as a multiselect in a binder.voidbeforeClientResponse(boolean initial)Called before the shared state and RPC invocations are sent to the client.voiddeselectAll()Deselects all currently selected items, if any.MultiSelectionModel.SelectAllCheckBoxVisibilitygetSelectAllCheckBoxVisibility()Gets the current mode for the select all checkbox visibility.Set<T>getSelectedItems()Returns an immutable set of the currently selected items.protected MultiSelectionModelStategetState()Returns the shared state for this connector.protected MultiSelectionModelStategetState(boolean markAsDirty)Returns the shared state for this connector.protected voidinit()Initializes the selection model after it has been attached to a grid.booleanisAllSelected()Returns whether all items are selected or not.booleanisSelectAllCheckBoxVisible()Returns whether the select all checkbox will be visible with the current setting ofMultiSelectionModel.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility).booleanisSelected(T item)Returns whether the given item is currently selected.protected voidonDeselectAll(boolean userOriginated)Triggered when the user unchecks the select all checkbox.protected voidonSelectAll(boolean userOriginated)Triggered when the user checks the select all checkbox.voidrefreshData(T item)Informs theDataGeneratorthat a data object has been updated.voidselectAll()Selects all available the items.protected booleanselectionContainsId(Object id)Returns if the given id belongs to one of the selected items.voidsetSelectAllCheckBoxVisibility(MultiSelectionModel.SelectAllCheckBoxVisibility selectAllCheckBoxVisibility)Sets the select all checkbox visibility mode.protected voidupdateCanSelectAll()Controls whether the select all checkbox is visible in the grid default header, or not.voidupdateSelection(Set<T> addedItems, Set<T> removedItems)Updates the selection by adding and removing the given items from it.protected voidupdateSelection(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:AbstractSelectionModelInitializes the selection model after it has been attached to a grid.- Specified by:
initin classAbstractSelectionModel<T>
-
getState
protected MultiSelectionModelState getState()
Description copied from class:AbstractClientConnectorReturns 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:
getStatein classAbstractSelectionModel<T>- Returns:
- The shared state for this connector. Never null.
-
getState
protected MultiSelectionModelState getState(boolean markAsDirty)
Description copied from class:AbstractClientConnectorReturns the shared state for this connector.- Overrides:
getStatein classAbstractSelectionModel<T>- Parameters:
markAsDirty- true if the connector should automatically be marked dirty, false otherwise- Returns:
- The shared state for this connector. Never null.
- See Also:
AbstractClientConnector.getState()
-
setSelectAllCheckBoxVisibility
public void setSelectAllCheckBoxVisibility(MultiSelectionModel.SelectAllCheckBoxVisibility selectAllCheckBoxVisibility)
Description copied from interface:MultiSelectionModelSets 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:
setSelectAllCheckBoxVisibilityin interfaceMultiSelectionModel<T>- Parameters:
selectAllCheckBoxVisibility- the visiblity mode to use- See Also:
MultiSelectionModel.SelectAllCheckBoxVisibility
-
getSelectAllCheckBoxVisibility
public MultiSelectionModel.SelectAllCheckBoxVisibility getSelectAllCheckBoxVisibility()
Description copied from interface:MultiSelectionModelGets the current mode for the select all checkbox visibility.- Specified by:
getSelectAllCheckBoxVisibilityin interfaceMultiSelectionModel<T>- Returns:
- the select all checkbox visibility mode
- See Also:
MultiSelectionModel.SelectAllCheckBoxVisibility,MultiSelectionModel.isSelectAllCheckBoxVisible()
-
isSelectAllCheckBoxVisible
public boolean isSelectAllCheckBoxVisible()
Description copied from interface:MultiSelectionModelReturns whether the select all checkbox will be visible with the current setting ofMultiSelectionModel.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility).- Specified by:
isSelectAllCheckBoxVisiblein interfaceMultiSelectionModel<T>- Returns:
trueif the checkbox will be visible with the current settings- See Also:
MultiSelectionModel.SelectAllCheckBoxVisibility,MultiSelectionModel.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)
-
isAllSelected
public boolean isAllSelected()
Description copied from interface:MultiSelectionModelReturns 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 ifSelectionModel.Multi.selectAll()has been used from server side.- Specified by:
isAllSelectedin interfaceMultiSelectionModel<T>- Returns:
trueif all selected,falseif not
-
isSelected
public boolean isSelected(T item)
Description copied from interface:SelectionModelReturns whether the given item is currently selected.- Specified by:
isSelectedin interfaceSelectionModel<T>- Parameters:
item- the item to check, not null- Returns:
trueif the item is selected,falseotherwise
-
selectionContainsId
protected boolean selectionContainsId(Object id)
Returns if the given id belongs to one of the selected items.- Parameters:
id- the id to check for- Returns:
trueif id is selected,falseif not
-
beforeClientResponse
public void beforeClientResponse(boolean initial)
Description copied from interface:ClientConnectorCalled 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:
beforeClientResponsein interfaceClientConnector- Overrides:
beforeClientResponsein classAbstractClientConnector- Parameters:
initial-trueif the client-side connector will be created and initialized after this method has been invoked.falseif 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:MultiSelectionModelAdds a selection listener that will be called when the selection is changed either by the user or programmatically.- Specified by:
addMultiSelectionListenerin interfaceMultiSelectionModel<T>- Parameters:
listener- the value change listener, notnull- Returns:
- a registration for the listener
-
getSelectedItems
public Set<T> getSelectedItems()
Description copied from interface:SelectionModelReturns 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 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.MultiUpdates 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:
updateSelectionin interfaceSelectionModel.Multi<T>- Parameters:
addedItems- the items to add, notnullremovedItems- the items to remove, notnull
-
selectAll
public void selectAll()
Description copied from interface:SelectionModel.MultiSelects all available the items.- Specified by:
selectAllin interfaceSelectionModel.Multi<T>
-
deselectAll
public void deselectAll()
Description copied from interface:SelectionModelDeselects all currently selected items, if any.- Specified by:
deselectAllin interfaceSelectionModel<T>
-
asMultiSelect
public MultiSelect<T> asMultiSelect()
Gets a wrapper for using this grid as a multiselect in a binder.- Specified by:
asMultiSelectin 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-trueif originated from client side by user
-
onDeselectAll
protected void onDeselectAll(boolean userOriginated)
Triggered when the user unchecks the select all checkbox.- Parameters:
userOriginated-trueif 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-trueif this was used originated,falseif not
-
refreshData
public void refreshData(T item)
Description copied from interface:DataGeneratorInforms theDataGeneratorthat a data object has been updated. This method should update any unneeded information stored for given item.- Specified by:
refreshDatain interfaceDataGenerator<T>- Parameters:
item- the updated item
-
-