T
- the type of the selected item in grid.public class SingleSelectionModelImpl<T> extends AbstractSelectionModel<T> implements SingleSelectionModel<T>
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
SelectionModel.Multi<T>, SelectionModel.Single<T>
Constructor and Description |
---|
SingleSelectionModelImpl() |
Modifier and Type | Method and 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.
|
destroyAllData, extend, generateData, getGrid, isUserSelectionAllowed, remove, setUserSelectionAllowed
addComponentToGrid, getInternalIdForColumn, getParent, removeComponentFromGrid
getData, refresh
extend, getSupportedParentType, setParent
addAttachListener, addDetachListener, addExtension, 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, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addSelectionListener
isUserSelectionAllowed, remove, setUserSelectionAllowed
addAttachListener, addDetachListener, attach, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getParent, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
deselectAll, getFirstSelectedItem, setSelectedItem
destroyData
protected void init()
AbstractSelectionModel
init
in class AbstractSelectionModel<T>
protected SingleSelectionModelState 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 SingleSelectionModelState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractSelectionModel<T>
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public Registration addSingleSelectionListener(SingleSelectionListener<T> listener)
SingleSelectionModel
addSingleSelectionListener
in interface SingleSelectionModel<T>
listener
- the value change listener, not null
public Optional<T> getSelectedItem()
SelectionModel.Single
getSelectedItem
in interface SelectionModel.Single<T>
public void deselect(T item)
SelectionModel
deselect
in interface SelectionModel<T>
item
- the item to deselect, not nullpublic void select(T item)
SelectionModel
select
in interface SelectionModel<T>
select
in interface SelectionModel.Single<T>
item
- the item to select, not nullprotected boolean isKeySelected(String key)
key
- the key to test or null
to test whether nothing is
selectedtrue
if the key equals the key of the currently selected
item (or null
if no selection), false
otherwise.protected void doSetSelected(T item)
null
, clears the current
selection if any.item
- the selected item or null
to clear selectionprotected void setSelectedFromClient(String key)
isUserOriginated == true
.key
- the key of the item to select or null
to clear
selectionprotected void setSelectedFromServer(T item)
isUserOriginated == false
.item
- the item to select or null
to clear selectionpublic 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>
getSelectedItems
in interface SelectionModel.Single<T>
SelectionModel.Single.getSelectedItem()
public void setDeselectAllowed(boolean deselectAllowed)
SelectionModel.Single
setDeselectAllowed
in interface SelectionModel.Single<T>
deselectAllowed
- true
if the selected row can be deselected
without selecting another row instead; otherwise
false
.public boolean isDeselectAllowed()
SelectionModel.Single
isDeselectAllowed
in interface SelectionModel.Single<T>
true
if deselection is allowed; otherwise
false
public SingleSelect<T> asSingleSelect()
asSingleSelect
in interface SingleSelectionModel<T>
public 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 itempublic boolean isSelected(T item)
SelectionModel
isSelected
in interface SelectionModel<T>
item
- the item to check, not nulltrue
if the item is selected, false
otherwiseCopyright © 2017 Vaadin Ltd. All rights reserved.