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 protectedAbstractSingleSelect()Creates a newAbstractListingwith a default data communicator.protectedAbstractSingleSelect(DataCommunicator<T> dataCommunicator)Creates a newAbstractSingleSelectwith the given custom data communicator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistrationaddSelectionListener(SingleSelectionListener<T> listener)Adds a selection listener to this select.RegistrationaddValueChangeListener(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 AbstractSingleSelectStategetState()Returns the shared state bean with information to be sent from the server to the client.protected AbstractSingleSelectStategetState(boolean markAsDirty)Returns the shared state for this connector.TgetValue()Returns the current value of this object which is the currently selected item.booleanisReadOnly()Returns the read-only status from the state of thisAbstractComponent.booleanisRequiredIndicatorVisible()Checks whether the required indicator is visible or not.booleanisSelected(T item)Returns whether the given item is currently selected.protected TkeyToItem(String key)Returns the item that the given key is assigned to, ornullif there is no such item.protected TreadItem(org.jsoup.nodes.Element child, Set<T> selected, DesignContext context)Reads an Item from a design and inserts it into the data source.protected voidreadItems(org.jsoup.nodes.Element design, DesignContext context)Reads the data source items from thedesign.voidsetReadOnly(boolean readOnly)Sets the read-only status in the state of thisAbstractComponent.voidsetRequiredIndicatorVisible(boolean visible)Sets the visibility of the required indicator.voidsetSelectedItem(T item)Sets the current selection to the given item or clears selection if givennull.protected voidsetSelectedItem(T value, boolean userOriginated)This method updates the internal selection state of the server-side ofAbstractSingleSelect.voidsetValue(T value)Sets the value of this object which is an item to select.protected voidupdateSelectedItemState(T value)This method updates the shared selection state of theAbstractSingleSelect.protected org.jsoup.nodes.ElementwriteItem(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 newAbstractListingwith a default data communicator.
-
AbstractSingleSelect
protected AbstractSingleSelect(DataCommunicator<T> dataCommunicator)
Creates a newAbstractSingleSelectwith the given custom data communicator.Note: This method is for creating an
AbstractSingleSelectwith 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 ornullto 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:
getValuein 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 isnullthen it deselects currently selected item.The call is delegated to
setSelectedItem(Object).- Specified by:
setValuein interfaceHasValue<T>- Parameters:
value- the item to select ornullto clear selection- See Also:
setSelectedItem(Object),SelectionModel.Single.setSelectedItem(Object)
-
addValueChangeListener
public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener)
Description copied from interface:HasValueAdds a value change listener. The listener is called when the value of thisHasValueis changed either by the user or programmatically.- Specified by:
addValueChangeListenerin interfaceHasValue<T>- Parameters:
listener- the value change listener, not null- Returns:
- a registration for the listener
-
getState
protected AbstractSingleSelectState getState()
Description copied from class:AbstractComponentReturns 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:
getStatein classAbstractListing<T>- Returns:
- updated component shared state
-
getState
protected AbstractSingleSelectState getState(boolean markAsDirty)
Description copied from class:AbstractClientConnectorReturns the shared state for this connector.- Overrides:
getStatein 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:AbstractComponentSets 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()aspublicin the component and call this method.This method will throw a
IllegalStateExceptionif the component state (returned byAbstractComponent.getState()) does not inheritAbstractFieldState.- Specified by:
setRequiredIndicatorVisiblein interfaceHasValue<T>- Overrides:
setRequiredIndicatorVisiblein classAbstractComponent- Parameters:
visible-trueto make the required indicator visible,falseif not
-
isRequiredIndicatorVisible
public boolean isRequiredIndicatorVisible()
Description copied from class:AbstractComponentChecks whether the required indicator is visible or not. NOTE: Does not apply for all components!.This method will throw a
IllegalStateExceptionif the component state (returned byAbstractComponent.getState()) does not inheritAbstractFieldState.- Specified by:
isRequiredIndicatorVisiblein interfaceHasValue<T>- Overrides:
isRequiredIndicatorVisiblein classAbstractComponent- Returns:
trueif visible,falseif not- See Also:
AbstractComponent.setRequiredIndicatorVisible(boolean)
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from class:AbstractComponentSets the read-only status in the state of thisAbstractComponent. This method should be made public inComponentsthat implementHasValue.- Specified by:
setReadOnlyin interfaceHasValue<T>- Overrides:
setReadOnlyin 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:AbstractComponentReturns the read-only status from the state of thisAbstractComponent. This method should be made public inComponentsthat implementHasValue.- Specified by:
isReadOnlyin interfaceHasValue<T>- Overrides:
isReadOnlyin classAbstractComponent- Returns:
trueif state has read-only on;falseif not- See Also:
AbstractComponent.setReadOnly(boolean)
-
keyToItem
protected T keyToItem(String key)
Returns the item that the given key is assigned to, ornullif there is no such item.- Parameters:
key- the key whose item to return- Returns:
- the associated item if any,
nullotherwise.
-
isSelected
public boolean isSelected(T item)
Returns whether the given item is currently selected.- Parameters:
item- the item to check, not null- Returns:
trueif the item is selected,falseotherwise
-
writeItem
protected org.jsoup.nodes.Element writeItem(org.jsoup.nodes.Element design, T item, DesignContext context)Description copied from class:AbstractListingWrites a data source Item to a design. Hierarchical select components should override this method to recursively write any child items as well.- Overrides:
writeItemin 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:AbstractListingReads the data source items from thedesign.- Specified by:
readItemsin 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 thechildelement is notoption.
-
getCustomAttributes
protected Collection<String> getCustomAttributes()
Description copied from class:AbstractComponentReturns 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:
getCustomAttributesin 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-trueif selection was done by user,falseif 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
-
-