T
- the type of the selected item in grid.public class MultiSelectionModelImpl<T> extends AbstractSelectionModel<T> implements MultiSelectionModel<T>
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.
MultiSelectionModel.SelectAllCheckBoxVisibility
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
SelectionModel.Multi<T>, SelectionModel.Single<T>
Constructor and Description |
---|
MultiSelectionModelImpl() |
Modifier and Type | Method and 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.
|
destroyAllData, extend, generateData, getGrid, isUserSelectionAllowed, remove, setUserSelectionAllowed
addComponentToGrid, getInternalIdForColumn, getParent, removeComponentFromGrid
getData, refresh
extend, getSupportedParentType, setParent
addAttachListener, addDetachListener, addExtension, 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, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addSelectionListener
isUserSelectionAllowed, remove, setUserSelectionAllowed
addAttachListener, addDetachListener, attach, detach, encodeState, getErrorHandler, getExtensions, getParent, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
deselect, deselectItems, getFirstSelectedItem, select, selectItems
destroyData
protected void init()
AbstractSelectionModel
init
in class AbstractSelectionModel<T>
protected MultiSelectionModelState getState()
AbstractClientConnector
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.
getState
in class AbstractSelectionModel<T>
protected MultiSelectionModelState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractSelectionModel<T>
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public void setSelectAllCheckBoxVisibility(MultiSelectionModel.SelectAllCheckBoxVisibility selectAllCheckBoxVisibility)
MultiSelectionModel
The default value is MultiSelectionModel.SelectAllCheckBoxVisibility.DEFAULT
, which
means that the checkbox is only visible if the grid's data provider is
in- memory.
setSelectAllCheckBoxVisibility
in interface MultiSelectionModel<T>
selectAllCheckBoxVisibility
- the visiblity mode to useMultiSelectionModel.SelectAllCheckBoxVisibility
public MultiSelectionModel.SelectAllCheckBoxVisibility getSelectAllCheckBoxVisibility()
MultiSelectionModel
getSelectAllCheckBoxVisibility
in interface MultiSelectionModel<T>
MultiSelectionModel.SelectAllCheckBoxVisibility
,
MultiSelectionModel.isSelectAllCheckBoxVisible()
public boolean isSelectAllCheckBoxVisible()
MultiSelectionModel
MultiSelectionModel.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)
.isSelectAllCheckBoxVisible
in interface MultiSelectionModel<T>
true
if the checkbox will be visible with the current
settingsMultiSelectionModel.SelectAllCheckBoxVisibility
,
MultiSelectionModel.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)
public boolean isAllSelected()
This is only true
if user has selected all rows with the select
all checkbox on client side, or if selectAll()
has been used
from server side.
true
if all selected, false
if notpublic boolean isSelected(T item)
SelectionModel
isSelected
in interface SelectionModel<T>
item
- the item to check, not nulltrue
if the item is selected, false
otherwiseprotected boolean selectionContainsId(Object id)
id
- the id to check fortrue
if id is selected, false
if notpublic void beforeClientResponse(boolean initial)
ClientConnector
beforeClientResponse
in interface ClientConnector
beforeClientResponse
in class AbstractClientConnector
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.protected void updateCanSelectAll()
This is updated as a part of beforeClientResponse(boolean)
,
since the data provider for grid can be changed on the fly.
SelectAllCheckBoxVisibility
public Registration addMultiSelectionListener(MultiSelectionListener<T> listener)
MultiSelectionModel
addMultiSelectionListener
in interface MultiSelectionModel<T>
listener
- the value change listener, not null
public Set<T> getSelectedItems()
SelectionModel
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.
getSelectedItems
in interface SelectionModel<T>
public void updateSelection(Set<T> addedItems, Set<T> removedItems)
SelectionModel.Multi
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.
updateSelection
in interface SelectionModel.Multi<T>
addedItems
- the items to add, not null
removedItems
- the items to remove, not null
public void selectAll()
SelectionModel.Multi
selectAll
in interface SelectionModel.Multi<T>
public void deselectAll()
SelectionModel
deselectAll
in interface SelectionModel<T>
public MultiSelect<T> asMultiSelect()
asMultiSelect
in interface MultiSelectionModel<T>
protected void onSelectAll(boolean userOriginated)
userOriginated
- true
if originated from client side by userprotected void onDeselectAll(boolean userOriginated)
userOriginated
- true
if originated from client side by userprotected void updateSelection(Set<T> addedItems, Set<T> removedItems, boolean userOriginated)
All selection updates should go through this method, since it handles incorrect parameters, removing duplicates, notifying data communicator and and firing events.
addedItems
- the items added to selection, not nullremovedItems
- the items removed from selection, not nulluserOriginated
- true
if this was used originated, false
if notpublic void refreshData(T item)
DataGenerator
DataGenerator
that a data object has been updated.
This method should update any unneeded information stored for given item.refreshData
in interface DataGenerator<T>
item
- the updated itemCopyright © 2020 Vaadin Ltd. All rights reserved.