Package 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:
- 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.data.SelectionModel
SelectionModel.Multi<T>, SelectionModel.Single<T>
-
-
Constructor Summary
Constructors Constructor Description SingleSelectionModelImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistrationaddSingleSelectionListener(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.voiddeselect(T item)Deselects the given item.protected voiddoSetSelected(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 SingleSelectionModelStategetState()Returns the shared state for this connector.protected SingleSelectionModelStategetState(boolean markAsDirty)Returns the shared state for this connector.protected voidinit()Initializes the selection model after it has been attached to a grid.booleanisDeselectAllowed()Gets whether it's allowed to deselect the selected row through the UI.protected booleanisKeySelected(String key)Returns whether the given key maps to the currently selected item.booleanisSelected(T item)Returns whether the given item is currently selected.voidrefreshData(T item)Informs theDataGeneratorthat a data object has been updated.voidselect(T item)Selects the given item.voidsetDeselectAllowed(boolean deselectAllowed)Sets whether it's allowed to deselect the selected row through the UI.protected voidsetSelectedFromClient(String key)Sets the selection based on a client request.protected voidsetSelectedFromServer(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:AbstractSelectionModelInitializes the selection model after it has been attached to a grid.- Specified by:
initin classAbstractSelectionModel<T>
-
getState
protected SingleSelectionModelState 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 SingleSelectionModelState 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()
-
addSingleSelectionListener
public Registration addSingleSelectionListener(SingleSelectionListener<T> listener)
Description copied from interface:SingleSelectionModelAdds a single selection listener that is called when the value of this select is changed either by the user or programmatically.- Specified by:
addSingleSelectionListenerin 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.SingleReturns the currently selected item, or an empty optional if no item is selected.- Specified by:
getSelectedItemin 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:SelectionModelDeselects the given item. If the item is not currently selected, does nothing.- Specified by:
deselectin interfaceSelectionModel<T>- Parameters:
item- the item to deselect, not null
-
select
public void select(T item)
Description copied from interface:SelectionModelSelects the given item. Depending on the implementation, may cause other items to be deselected. If the item is already selected, does nothing.- Specified by:
selectin interfaceSelectionModel<T>- Specified by:
selectin 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 ornullto test whether nothing is selected- Returns:
trueif the key equals the key of the currently selected item (ornullif no selection),falseotherwise.
-
doSetSelected
protected void doSetSelected(T item)
Sets the selected item. If the item isnull, clears the current selection if any.- Parameters:
item- the selected item ornullto clear selection- Since:
- 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 withisUserOriginated == true.- Parameters:
key- the key of the item to select ornullto 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 withisUserOriginated == false.- Parameters:
item- the item to select ornullto clear selection
-
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>- Specified by:
getSelectedItemsin interfaceSelectionModel.Single<T>- Returns:
- the items in the current selection, not null
- See Also:
SelectionModel.Single.getSelectedItem()
-
setDeselectAllowed
public void setDeselectAllowed(boolean deselectAllowed)
Description copied from interface:SelectionModel.SingleSets whether it's allowed to deselect the selected row through the UI. Deselection is allowed by default.- Specified by:
setDeselectAllowedin interfaceSelectionModel.Single<T>- Parameters:
deselectAllowed-trueif the selected row can be deselected without selecting another row instead; otherwisefalse.
-
isDeselectAllowed
public boolean isDeselectAllowed()
Description copied from interface:SelectionModel.SingleGets whether it's allowed to deselect the selected row through the UI.- Specified by:
isDeselectAllowedin interfaceSelectionModel.Single<T>- Returns:
trueif 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:
asSingleSelectin interfaceSingleSelectionModel<T>- Returns:
- a single select wrapper for grid
-
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
-
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
-
-