Class AbstractSingleSelect<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.ui.AbstractComponent
-
- com.vaadin.ui.AbstractListing<T>
-
- com.vaadin.ui.AbstractSingleSelect<T>
-
- Type Parameters:
T
- the item date type
- All Implemented Interfaces:
HasItems<T>
,HasValue<T>
,ContextClickEvent.ContextClickNotifier
,MethodEventSource
,ClientConnector
,Sizeable
,Connector
,Component
,Component.Focusable
,SingleSelect<T>
,Serializable
- Direct Known Subclasses:
ComboBox
,NativeSelect
,RadioButtonGroup
public abstract class AbstractSingleSelect<T> extends AbstractListing<T> implements SingleSelect<T>
An abstract base class for listing components that only support single selection and no lazy loading of data items.- Since:
- 8.0
- Author:
- Vaadin Ltd.
- See Also:
SelectionModel.Single
, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractListing
AbstractListing.AbstractListingExtension<T>
-
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.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
-
Nested classes/interfaces inherited from interface com.vaadin.data.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
-
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
-
-
Field Summary
-
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
-
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractSingleSelect()
Creates a newAbstractListing
with a default data communicator.protected
AbstractSingleSelect(DataCommunicator<T> dataCommunicator)
Creates a newAbstractSingleSelect
with the given custom data communicator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Registration
addSelectionListener(SingleSelectionListener<T> listener)
Adds a selection listener to this select.Registration
addValueChangeListener(HasValue.ValueChangeListener<T> listener)
Adds a value change listener.protected Collection<String>
getCustomAttributes()
Returns a collection of attributes that should not be handled by the basic implementation of theAbstractComponent.readDesign(Element, DesignContext)
andAbstractComponent.writeDesign(Element, DesignContext)
methods.Optional<T>
getSelectedItem()
Returns the currently selected item, or an empty optional if no item is selected.protected AbstractSingleSelectState
getState()
Returns the shared state bean with information to be sent from the server to the client.protected AbstractSingleSelectState
getState(boolean markAsDirty)
Returns the shared state for this connector.T
getValue()
Returns the current value of this object which is the currently selected item.boolean
isReadOnly()
Returns the read-only status from the state of thisAbstractComponent
.boolean
isRequiredIndicatorVisible()
Checks whether the required indicator is visible or not.boolean
isSelected(T item)
Returns whether the given item is currently selected.protected T
keyToItem(String key)
Returns the item that the given key is assigned to, ornull
if there is no such item.protected T
readItem(org.jsoup.nodes.Element child, Set<T> selected, DesignContext context)
Reads an Item from a design and inserts it into the data source.protected void
readItems(org.jsoup.nodes.Element design, DesignContext context)
Reads the data source items from thedesign
.void
setReadOnly(boolean readOnly)
Sets the read-only status in the state of thisAbstractComponent
.void
setRequiredIndicatorVisible(boolean visible)
Sets the visibility of the required indicator.void
setSelectedItem(T item)
Sets the current selection to the given item or clears selection if givennull
.protected void
setSelectedItem(T value, boolean userOriginated)
This method updates the internal selection state of the server-side ofAbstractSingleSelect
.void
setValue(T value)
Sets the value of this object which is an item to select.protected void
updateSelectedItemState(T value)
This method updates the shared selection state of theAbstractSingleSelect
.protected org.jsoup.nodes.Element
writeItem(org.jsoup.nodes.Element design, T item, DesignContext context)
Writes a data source Item to a design.-
Methods inherited from class com.vaadin.ui.AbstractListing
addDataGenerator, deserializeDeclarativeRepresentation, doReadDesign, doWriteDesign, focus, getDataCommunicator, getItemCaptionGenerator, getItemIconGenerator, getTabIndex, internalGetDataProvider, internalSetDataProvider, internalSetDataProvider, readDesign, readItem, removeDataGenerator, serializeDeclarativeRepresentation, setItemCaptionGenerator, setItemIconGenerator, setTabIndex, writeDesign, writeItems
-
Methods inherited from class com.vaadin.ui.AbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeight, setHeightFull, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthFull, setWidthUndefined
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, 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, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
Methods inherited from interface com.vaadin.data.HasItems
getDataProvider, setItems, setItems, setItems
-
Methods inherited from interface com.vaadin.data.HasValue
clear, getDefaultValidator, getEmptyValue, getOptionalValue, isEmpty
-
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefined
-
-
-
-
Constructor Detail
-
AbstractSingleSelect
protected AbstractSingleSelect()
Creates a newAbstractListing
with a default data communicator.
-
AbstractSingleSelect
protected AbstractSingleSelect(DataCommunicator<T> dataCommunicator)
Creates a newAbstractSingleSelect
with the given custom data communicator.Note: This method is for creating an
AbstractSingleSelect
with a custom communicator. In the common caseAbstractSingleSelect()
should be used.- Parameters:
dataCommunicator
- the data communicator to use, not null
-
-
Method Detail
-
addSelectionListener
public Registration addSelectionListener(SingleSelectionListener<T> listener)
Adds a selection listener to this select. The listener is called when the selection is changed either by the user or programmatically.- Parameters:
listener
- the selection listener, not null- Returns:
- a registration for the listener
-
getSelectedItem
public Optional<T> getSelectedItem()
Returns the currently selected item, or an empty optional if no item is selected.- Returns:
- an optional of the selected item if any, an empty optional otherwise
-
setSelectedItem
public void setSelectedItem(T item)
Sets the current selection to the given item or clears selection if givennull
.- Parameters:
item
- the item to select ornull
to clear selection
-
getValue
public T getValue()
Returns the current value of this object which is the currently selected item.The call is delegated to
getSelectedItem()
- Specified by:
getValue
in interfaceHasValue<T>
- Returns:
- the current selection, may be
null
- See Also:
getSelectedItem()
,SelectionModel.Single.getSelectedItem()
-
setValue
public void setValue(T value)
Sets the value of this object which is an item to select. If the new value is not equal togetValue()
, fires a value change event. If value isnull
then it deselects currently selected item.The call is delegated to
setSelectedItem(Object)
.- Specified by:
setValue
in interfaceHasValue<T>
- Parameters:
value
- the item to select ornull
to clear selection- See Also:
setSelectedItem(Object)
,SelectionModel.Single.setSelectedItem(Object)
-
addValueChangeListener
public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener)
Description copied from interface:HasValue
Adds a value change listener. The listener is called when the value of thisHasValue
is changed either by the user or programmatically.- Specified by:
addValueChangeListener
in interfaceHasValue<T>
- Parameters:
listener
- the value change listener, not null- Returns:
- a registration for the listener
-
getState
protected AbstractSingleSelectState getState()
Description copied from class:AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().- Overrides:
getState
in classAbstractListing<T>
- Returns:
- updated component shared state
-
getState
protected AbstractSingleSelectState getState(boolean markAsDirty)
Description copied from class:AbstractClientConnector
Returns the shared state for this connector.- Overrides:
getState
in classAbstractListing<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()
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean visible)
Description copied from class:AbstractComponent
Sets the visibility of the required indicator. NOTE: Does not apply for all components!.If the component supports the required indicator (state extends
AbstractFieldState
), then expose this method andAbstractComponent.isRequiredIndicatorVisible()
aspublic
in the component and call this method.This method will throw a
IllegalStateException
if the component state (returned byAbstractComponent.getState()
) does not inheritAbstractFieldState
.- Specified by:
setRequiredIndicatorVisible
in interfaceHasValue<T>
- Overrides:
setRequiredIndicatorVisible
in classAbstractComponent
- Parameters:
visible
-true
to make the required indicator visible,false
if not
-
isRequiredIndicatorVisible
public boolean isRequiredIndicatorVisible()
Description copied from class:AbstractComponent
Checks whether the required indicator is visible or not. NOTE: Does not apply for all components!.This method will throw a
IllegalStateException
if the component state (returned byAbstractComponent.getState()
) does not inheritAbstractFieldState
.- Specified by:
isRequiredIndicatorVisible
in interfaceHasValue<T>
- Overrides:
isRequiredIndicatorVisible
in classAbstractComponent
- Returns:
true
if visible,false
if not- See Also:
AbstractComponent.setRequiredIndicatorVisible(boolean)
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from class:AbstractComponent
Sets the read-only status in the state of thisAbstractComponent
. This method should be made public inComponents
that implementHasValue
.- Specified by:
setReadOnly
in interfaceHasValue<T>
- Overrides:
setReadOnly
in classAbstractComponent
- Parameters:
readOnly
- a boolean value specifying whether the component is put read-only mode or not
-
isReadOnly
public boolean isReadOnly()
Description copied from class:AbstractComponent
Returns the read-only status from the state of thisAbstractComponent
. This method should be made public inComponents
that implementHasValue
.- Specified by:
isReadOnly
in interfaceHasValue<T>
- Overrides:
isReadOnly
in classAbstractComponent
- Returns:
true
if state has read-only on;false
if not- See Also:
AbstractComponent.setReadOnly(boolean)
-
keyToItem
protected T keyToItem(String key)
Returns the item that the given key is assigned to, ornull
if there is no such item.- Parameters:
key
- the key whose item to return- Returns:
- the associated item if any,
null
otherwise.
-
isSelected
public boolean isSelected(T item)
Returns whether the given item is currently selected.- Parameters:
item
- the item to check, not null- Returns:
true
if the item is selected,false
otherwise
-
writeItem
protected org.jsoup.nodes.Element writeItem(org.jsoup.nodes.Element design, T item, DesignContext context)
Description copied from class:AbstractListing
Writes a data source Item to a design. Hierarchical select components should override this method to recursively write any child items as well.- Overrides:
writeItem
in classAbstractListing<T>
- Parameters:
design
- the element into which to insert the itemitem
- the item to writecontext
- the DesignContext instance used in writing- Returns:
- a JSOUP element representing the
item
-
readItems
protected void readItems(org.jsoup.nodes.Element design, DesignContext context)
Description copied from class:AbstractListing
Reads the data source items from thedesign
.- Specified by:
readItems
in classAbstractListing<T>
- Parameters:
design
- The element to obtain the state fromcontext
- The DesignContext instance used for parsing the design
-
readItem
protected T readItem(org.jsoup.nodes.Element child, Set<T> selected, DesignContext context)
Reads an Item from a design and inserts it into the data source. Hierarchical select components should override this method to recursively recursively read any child items as well.- Parameters:
child
- a child element representing the itemselected
- A set accumulating selected items. If the item that is read is marked as selected, its item id should be added to this set.context
- the DesignContext instance used in parsing- Returns:
- the item id of the new item
- Throws:
DesignException
- if the tag name of thechild
element is notoption
.
-
getCustomAttributes
protected Collection<String> getCustomAttributes()
Description copied from class:AbstractComponent
Returns a collection of attributes that should not be handled by the basic implementation of theAbstractComponent.readDesign(Element, DesignContext)
andAbstractComponent.writeDesign(Element, DesignContext)
methods. Typically these are handled in a custom way in the overridden versions of the above methods- Overrides:
getCustomAttributes
in classAbstractComponent
- Returns:
- the collection of attributes that are not handled by the basic implementation
-
setSelectedItem
protected void setSelectedItem(T value, boolean userOriginated)
This method updates the internal selection state of the server-side ofAbstractSingleSelect
.- Parameters:
value
- the value that should be selecteduserOriginated
-true
if selection was done by user,false
if not- Since:
- 8.5
-
updateSelectedItemState
protected void updateSelectedItemState(T value)
This method updates the shared selection state of theAbstractSingleSelect
.- Parameters:
value
- the value that is selected; may benull
- Since:
- 8.5
-
-