com.vaadin.ui.components.grid.
Class SingleSelectionModelImpl<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.SingleSelectionModelImpl<T>
-
Type Parameters:
T
- the type of the selected item in grid.All Implemented Interfaces:
DataGenerator<T>
,SelectionModel<T>
,SelectionModel.Single<T>
,MethodEventSource
,ClientConnector
,Extension
,Connector
,GridSelectionModel<T>
,SingleSelectionModel<T>
,Serializable
public class SingleSelectionModelImpl<T> extends AbstractSelectionModel<T> implements SingleSelectionModel<T>
Single selection model for grid.
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.data.SelectionModel
SelectionModel.Multi<T>, SelectionModel.Single<T>
-
-
Constructor Summary
Constructors Constructor Description SingleSelectionModelImpl()
-
Method Summary
All Methods Modifier and Type Method Description Registration
addSingleSelectionListener(SingleSelectionListener<T> listener)
Adds a single selection listener that is called when the value of this select is changed either by the user or programmatically.
SingleSelect<T>
asSingleSelect()
Gets a wrapper for using this grid as a single select in a binder.
void
deselect(T item)
Deselects the given item.
protected void
doSetSelected(T item)
Sets the selected item.
Optional<T>
getSelectedItem()
Returns the currently selected item, or an empty optional if no item is selected.
Set<T>
getSelectedItems()
Returns an immutable set of the currently selected items.
protected SingleSelectionModelState
getState()
Returns the shared state for this connector.
protected SingleSelectionModelState
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
isDeselectAllowed()
Gets whether it's allowed to deselect the selected row through the UI.
protected boolean
isKeySelected(String key)
Returns whether the given key maps to the currently selected item.
boolean
isSelected(T item)
Returns whether the given item is currently selected.
void
refreshData(T item)
Informs the
DataGenerator
that a data object has been updated.void
select(T item)
Selects the given item.
void
setDeselectAllowed(boolean deselectAllowed)
Sets whether it's allowed to deselect the selected row through the UI.
protected void
setSelectedFromClient(String key)
Sets the selection based on a client request.
protected void
setSelectedFromServer(T item)
Sets the selection based on server API call.
-
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, beforeClientResponse, 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, beforeClientResponse, 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.data.SelectionModel.Single
deselectAll, getFirstSelectedItem, setSelectedItem
-
Methods inherited from interface com.vaadin.ui.components.grid.SingleSelectionModel
addSelectionListener
-
-
-
-
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 SingleSelectionModelState 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 SingleSelectionModelState 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:
-
addSingleSelectionListener
public Registration addSingleSelectionListener(SingleSelectionListener<T> listener)
Description copied from interface:
SingleSelectionModel
Adds a single selection listener that is called when the value of this select is changed either by the user or programmatically.
Specified by:
addSingleSelectionListener
in interfaceSingleSelectionModel<T>
Parameters:
listener
- the value change listener, notnull
Returns:
a registration for the listener
-
getSelectedItem
public Optional<T> getSelectedItem()
Description copied from interface:
SelectionModel.Single
Returns the currently selected item, or an empty optional if no item is selected.
Specified by:
getSelectedItem
in interfaceSelectionModel.Single<T>
Returns:
an optional of the selected item if any, an empty optional otherwise
-
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<T>
Parameters:
item
- the item to deselect, not null
-
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<T>
Specified by:
select
in interfaceSelectionModel.Single<T>
Parameters:
item
- the item to select, not null
-
isKeySelected
protected boolean isKeySelected(String key)
Returns whether the given key maps to the currently selected item.
Parameters:
key
- the key to test ornull
to test whether nothing is selectedReturns:
true
if the key equals the key of the currently selected item (ornull
if no selection),false
otherwise.
-
doSetSelected
protected void doSetSelected(T item)
Sets the selected item. If the item is
null
, clears the current selection if any.Parameters:
item
- the selected item ornull
to clear selectionSince:
8.1
-
setSelectedFromClient
protected void setSelectedFromClient(String key)
Sets the selection based on a client request. Does nothing if the select component is HasValue.isReadOnly() or if the selection would not change. Otherwise updates the selection and fires a selection change event with
isUserOriginated == true
.Parameters:
key
- the key of the item to select ornull
to clear selection
-
setSelectedFromServer
protected void setSelectedFromServer(T item)
Sets the selection based on server API call. Does nothing if the selection would not change; otherwise updates the selection and fires a selection change event with
isUserOriginated == false
.Parameters:
item
- the item to select ornull
to clear selection
-
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>
Specified by:
getSelectedItems
in interfaceSelectionModel.Single<T>
Returns:
the items in the current selection, not null
See Also:
-
setDeselectAllowed
public void setDeselectAllowed(boolean deselectAllowed)
Description copied from interface:
SelectionModel.Single
Sets whether it's allowed to deselect the selected row through the UI. Deselection is allowed by default.
Specified by:
setDeselectAllowed
in interfaceSelectionModel.Single<T>
Parameters:
deselectAllowed
-true
if the selected row can be deselected without selecting another row instead; otherwisefalse
.
-
isDeselectAllowed
public boolean isDeselectAllowed()
Description copied from interface:
SelectionModel.Single
Gets whether it's allowed to deselect the selected row through the UI.
Specified by:
isDeselectAllowed
in interfaceSelectionModel.Single<T>
Returns:
true
if deselection is allowed; otherwisefalse
-
asSingleSelect
public SingleSelect<T> asSingleSelect()
Gets a wrapper for using this grid as a single select in a binder.
Specified by:
asSingleSelect
in interfaceSingleSelectionModel<T>
Returns:
a single select wrapper for grid
-
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
-
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
-
-