com.vaadin.ui.
Class ComboBox<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.ui.AbstractComponent
-
- com.vaadin.ui.AbstractListing<T>
-
- com.vaadin.ui.AbstractSingleSelect<T>
-
- com.vaadin.ui.ComboBox<T>
-
Type Parameters:
T
- item (bean) type in ComboBoxAll Implemented Interfaces:
HasFilterableDataProvider<T,String>
,HasItems<T>
,HasValue<T>
,ContextClickEvent.ContextClickNotifier
,FieldEvents.BlurNotifier
,FieldEvents.FocusNotifier
,MethodEventSource
,ClientConnector
,Sizeable
,Connector
,Component
,Component.Focusable
,SingleSelect<T>
,Serializable
public class ComboBox<T> extends AbstractSingleSelect<T> implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, HasFilterableDataProvider<T,String>
A filtering dropdown single-select. Items are filtered based on user input. Supports the creation of new items when a handler is set by the user.
Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ComboBox.CaptionFilter
Predicate to check
ComboBox
item captions against user typed strings.protected static class
ComboBox.DeclarativeStyleGenerator<T>
Item style generator class for declarative support.
static interface
ComboBox.FetchItemsCallback<T>
A callback method for fetching items.
static interface
ComboBox.NewItemHandler
Deprecated.
Since 8.4 replaced byComboBox.NewItemProvider
.static interface
ComboBox.NewItemProvider<T>
Provider function that adds a new item based on user input when the new items allowed mode is active.
-
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 ComboBox()
Constructs an empty combo box without a caption.
protected
ComboBox(DataCommunicator<T> dataCommunicator)
Constructs and initializes an empty combo box.
ComboBox(String caption)
Constructs an empty combo box, whose content can be set with
HasFilterableDataProvider.setDataProvider(DataProvider)
orsetItems(Collection)
.ComboBox(String caption, Collection<T> options)
Constructs a combo box with a static in-memory data provider with the given options.
-
Method Summary
All Methods Modifier and Type Method Description Registration
addBlurListener(FieldEvents.BlurListener listener)
Adds a
BlurListener
to the Component which gets fired when aField
loses keyboard focus.Registration
addFocusListener(FieldEvents.FocusListener listener)
Adds a
FocusListener
to the Component which gets fired when aField
receives keyboard focus.Registration
addValueChangeListener(HasValue.ValueChangeListener<T> listener)
Adds a value change listener.
void
attach()
Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).
void
detach()
Notifies the connector that it is detached from its VaadinSession.
DataProvider<T,?>
getDataProvider()
Returns the source of data items used by this listing.
String
getEmptySelectionCaption()
Returns the empty selection caption.
ItemCaptionGenerator<T>
getItemCaptionGenerator()
Gets the item caption generator that is used to produce the strings shown in the combo box for each item.
IconGenerator<T>
getItemIconGenerator()
Gets the currently used item icon generator.
ComboBox.NewItemHandler
getNewItemHandler()
Deprecated.
Since 8.4 usegetNewItemProvider()
instead.ComboBox.NewItemProvider<T>
getNewItemProvider()
Returns the provider function that is called when the user enters a new item (not present in the data provider).
int
getPageLength()
Returns the page length of the suggestion popup.
String
getPlaceholder()
Gets the current placeholder text shown when the combo box would be empty.
String
getPopupWidth()
Returns the suggestion pop-up's width as a CSS string.
protected ComboBoxState
getState()
Returns the shared state bean with information to be sent from the server to the client.
protected ComboBoxState
getState(boolean markAsDirty)
Returns the shared state for this connector.
StyleGenerator<T>
getStyleGenerator()
Gets the currently used style generator that is used to generate CSS class names for items.
boolean
isEmptySelectionAllowed()
Returns whether the user is allowed to select nothing in the combo box.
boolean
isScrollToSelectedItem()
Returns true if the select should find the page with the selected item when opening the popup.
boolean
isTextInputAllowed()
Returns true if the user can enter text into the field to either filter the selections or enter a new value if new item provider or handler is set (see
setNewItemProvider(NewItemProvider)
(recommended) andsetNewItemHandler(NewItemHandler)
(deprecated)).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 the
design
.<C> void
setDataProvider(DataProvider<T,C> dataProvider, SerializableFunction<String,C> filterConverter)
Sets the data provider and filter converter for this listing.
void
setDataProvider(ListDataProvider<T> listDataProvider)
Sets a list data provider as the data provider of this combo box.
void
setDataProvider(ComboBox.CaptionFilter captionFilter, ListDataProvider<T> listDataProvider)
Sets a list data provider with an item caption filter as the data provider of this combo box.
void
setDataProvider(ComboBox.FetchItemsCallback<T> fetchItems, SerializableToIntFunction<String> sizeCallback)
Sets a CallbackDataProvider using the given fetch items callback and a size callback.
void
setEmptySelectionAllowed(boolean emptySelectionAllowed)
Sets whether the user is allowed to select nothing in the combo box.
void
setEmptySelectionCaption(String caption)
Sets the empty selection caption.
void
setItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator)
Sets the item caption generator that is used to produce the strings shown in the combo box for each item.
void
setItemIconGenerator(IconGenerator<T> itemIconGenerator)
Sets the item icon generator that is used to produce custom icons for shown items.
void
setItems(ComboBox.CaptionFilter captionFilter, Collection<T> items)
Sets the data items of this listing and a simple string filter with which the item string and the text the user has input are compared.
void
setItems(ComboBox.CaptionFilter captionFilter, T... items)
Sets the data items of this listing and a simple string filter with which the item string and the text the user has input are compared.
void
setItems(Collection<T> items)
Sets the data items of this component provided as a collection.
void
setItems(Stream<T> streamOfItems)
Sets the data items of this listing provided as a stream.
void
setItems(T... items)
Sets the data items of this listing.
void
setNewItemHandler(ComboBox.NewItemHandler newItemHandler)
Deprecated.
Since 8.4 usesetNewItemProvider(NewItemProvider)
instead.void
setNewItemProvider(ComboBox.NewItemProvider<T> newItemProvider)
Sets the provider function that is called when user types a new item.
void
setPageLength(int pageLength)
Sets the page length for the suggestion popup.
void
setPlaceholder(String placeholder)
Sets the placeholder string - a textual prompt that is displayed when the select would otherwise be empty, to prompt the user for input.
void
setPopupWidth(String width)
Sets the suggestion pop-up's width as a CSS string.
void
setScrollToSelectedItem(boolean scrollToSelectedItem)
Sets whether to scroll the selected item visible (directly open the page on which it is) when opening the combo box popup or not.
void
setStyleGenerator(StyleGenerator<T> itemStyleGenerator)
Sets the style generator that is used to produce custom class names for items visible in the popup.
void
setTextInputAllowed(boolean textInputAllowed)
Sets whether it is possible to input text into the field or whether the field area of the component is just used to show what is selected.
protected void
updateSelectedItemState(T value)
This method updates the shared selection state of the
AbstractSingleSelect
.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.AbstractSingleSelect
addSelectionListener, getCustomAttributes, getSelectedItem, getValue, isReadOnly, isRequiredIndicatorVisible, isSelected, keyToItem, setReadOnly, setRequiredIndicatorVisible, setSelectedItem, setSelectedItem, setValue
-
Methods inherited from class com.vaadin.ui.AbstractListing
addDataGenerator, deserializeDeclarativeRepresentation, doReadDesign, doWriteDesign, focus, getDataCommunicator, getTabIndex, internalGetDataProvider, internalSetDataProvider, internalSetDataProvider, readDesign, readItem, removeDataGenerator, serializeDeclarativeRepresentation, setTabIndex, writeDesign, writeItems
-
Methods inherited from class com.vaadin.ui.AbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, beforeClientResponse, 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, 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, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, readDesign, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible, writeDesign
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
Methods inherited from interface com.vaadin.data.HasFilterableDataProvider
setDataProvider
-
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
-
ComboBox
public ComboBox()
Constructs an empty combo box without a caption. The content of the combo box can be set with
HasFilterableDataProvider.setDataProvider(DataProvider)
orsetItems(Collection)
-
ComboBox
public ComboBox(String caption)
Constructs an empty combo box, whose content can be set with
HasFilterableDataProvider.setDataProvider(DataProvider)
orsetItems(Collection)
.Parameters:
caption
- the caption to show in the containing layout, null for no caption
-
ComboBox
public ComboBox(String caption, Collection<T> options)
Constructs a combo box with a static in-memory data provider with the given options.
Parameters:
caption
- the caption to show in the containing layout, null for no captionoptions
- collection of options, not null
-
ComboBox
protected ComboBox(DataCommunicator<T> dataCommunicator)
Constructs and initializes an empty combo box.
Parameters:
dataCommunicator
- the data comnunicator to use with this ComboBoxSince:
8.5
-
-
Method Detail
-
setItems
public void setItems(Collection<T> items)
Sets the data items of this component provided as a collection.
The provided items are wrapped into a
ListDataProvider
and this instance is used as a data provider for theHasDataProvider.setDataProvider(DataProvider)
method. It means that the items collection can be accessed later on viaListDataProvider.getItems()
:HasDataProvider<String> listing = new CheckBoxGroup<>(); listing.setItems(Arrays.asList("a","b")); ... Collection<String> collection = ((ListDataProvider<String>)listing.getDataProvider()).getItems();
The provided collection instance may be used as-is. Subsequent modification of the collection might cause inconsistent data to be shown in the component unless it is explicitly instructed to read the data again.
Filtering will use a case insensitive match to show all items where the filter text is a substring of the caption displayed for that item.
-
setItems
public void setItems(Stream<T> streamOfItems)
Sets the data items of this listing provided as a stream.
This is just a shorthand for
HasItems.setItems(Collection)
, that collects objects in the stream to a list. Thus, using this method, instead of its array and Collection variations, doesn't save any memory. If you have a large data set to bind, using a lazy data provider is recommended. SeeBackEndDataProvider
for more info.The provided items are wrapped into a
ListDataProvider
and this instance is used as a data provider for theHasDataProvider.setDataProvider(DataProvider)
method. It means that the items collection can be accessed later on viaListDataProvider.getItems()
:HasDataProvider<String> listing = new CheckBoxGroup<>(); listing.setItems(Stream.of("a","b")); ... Collection<String> collection = ((ListDataProvider<String>)listing.getDataProvider()).getItems();
Filtering will use a case insensitive match to show all items where the filter text is a substring of the caption displayed for that item.
-
setItems
public void setItems(T... items)
Sets the data items of this listing.
The provided items are wrapped into a
ListDataProvider
and this instance is used as a data provider for theHasDataProvider.setDataProvider(DataProvider)
method. It means that the items collection can be accessed later on viaListDataProvider.getItems()
:HasDataProvider<String> listing = new CheckBoxGroup<>(); listing.setItems("a","b"); ... Collection<String> collection = ((ListDataProvider<String>)listing.getDataProvider()).getItems();
Filtering will use a case insensitive match to show all items where the filter text is a substring of the caption displayed for that item.
-
setDataProvider
public void setDataProvider(ListDataProvider<T> listDataProvider)
Sets a list data provider as the data provider of this combo box. Filtering will use a case insensitive match to show all items where the filter text is a substring of the caption displayed for that item.
Note that this is a shorthand that calls
HasFilterableDataProvider.setDataProvider(DataProvider)
with a wrapper of the provided list data provider. This means thatgetDataProvider()
will return the wrapper instead of the original list data provider.Parameters:
listDataProvider
- the list data provider to use, notnull
Since:
8.0
-
setItems
public void setItems(ComboBox.CaptionFilter captionFilter, Collection<T> items)
Sets the data items of this listing and a simple string filter with which the item string and the text the user has input are compared.
Note that unlike
setItems(Collection)
, no automatic case conversion is performed before the comparison.Parameters:
captionFilter
- filter to check if an item is shown when user typed some text into the ComboBoxitems
- the data items to displaySince:
8.0
-
setDataProvider
public void setDataProvider(ComboBox.CaptionFilter captionFilter, ListDataProvider<T> listDataProvider)
Sets a list data provider with an item caption filter as the data provider of this combo box. The caption filter is used to compare the displayed caption of each item to the filter text entered by the user.
Parameters:
captionFilter
- filter to check if an item is shown when user typed some text into the ComboBoxlistDataProvider
- the list data provider to use, notnull
Since:
8.0
-
setItems
public void setItems(ComboBox.CaptionFilter captionFilter, T... items)
Sets the data items of this listing and a simple string filter with which the item string and the text the user has input are compared.
Note that unlike
setItems(Collection)
, no automatic case conversion is performed before the comparison.Parameters:
captionFilter
- filter to check if an item is shown when user typed some text into the ComboBoxitems
- the data items to displaySince:
8.0
-
getPlaceholder
public String getPlaceholder()
Gets the current placeholder text shown when the combo box would be empty.
Returns:
the current placeholder string, or null if not enabled
Since:
8.0
See Also:
-
setPlaceholder
public void setPlaceholder(String placeholder)
Sets the placeholder string - a textual prompt that is displayed when the select would otherwise be empty, to prompt the user for input.
Parameters:
placeholder
- the desired placeholder, or null to disableSince:
8.0
-
setTextInputAllowed
public void setTextInputAllowed(boolean textInputAllowed)
Sets whether it is possible to input text into the field or whether the field area of the component is just used to show what is selected. By disabling text input, the comboBox will work in the same way as a
NativeSelect
Parameters:
textInputAllowed
- true to allow entering text, false to just show the current selectionSee Also:
-
isTextInputAllowed
public boolean isTextInputAllowed()
Returns true if the user can enter text into the field to either filter the selections or enter a new value if new item provider or handler is set (see
setNewItemProvider(NewItemProvider)
(recommended) andsetNewItemHandler(NewItemHandler)
(deprecated)). If text input is disabled, the comboBox will work in the same way as aNativeSelect
Returns:
true if text input is allowed
-
addBlurListener
public Registration addBlurListener(FieldEvents.BlurListener listener)
Description copied from interface:
FieldEvents.BlurNotifier
Adds a
BlurListener
to the Component which gets fired when aField
loses keyboard focus.Specified by:
addBlurListener
in interfaceFieldEvents.BlurNotifier
Parameters:
listener
- the blur listener to add, not nullReturns:
a registration object for removing the listener
See Also:
-
addFocusListener
public Registration addFocusListener(FieldEvents.FocusListener listener)
Description copied from interface:
FieldEvents.FocusNotifier
Adds a
FocusListener
to the Component which gets fired when aField
receives keyboard focus.Specified by:
addFocusListener
in interfaceFieldEvents.FocusNotifier
Parameters:
listener
- the focus listener to add, not nullReturns:
a registration object for removing the listener
See Also:
-
getPageLength
public int getPageLength()
Returns the page length of the suggestion popup.
Returns:
the pageLength
-
getPopupWidth
public String getPopupWidth()
Returns the suggestion pop-up's width as a CSS string. By default this width is set to "100%".
Returns:
explicitly set popup width as CSS size string or null if not set
Since:
7.7
See Also:
-
setPageLength
public void setPageLength(int pageLength)
Sets the page length for the suggestion popup. Setting the page length to 0 will disable suggestion popup paging (all items visible).
Parameters:
pageLength
- the pageLength to set
-
isEmptySelectionAllowed
public boolean isEmptySelectionAllowed()
Returns whether the user is allowed to select nothing in the combo box.
Returns:
true if empty selection is allowed, false otherwise
Since:
8.0
-
setEmptySelectionAllowed
public void setEmptySelectionAllowed(boolean emptySelectionAllowed)
Sets whether the user is allowed to select nothing in the combo box. When true, a special empty item is shown to the user.
Parameters:
emptySelectionAllowed
- true to allow not selecting anything, false to require selectionSince:
8.0
-
getEmptySelectionCaption
public String getEmptySelectionCaption()
Returns the empty selection caption.
The empty string
""
is the default empty selection caption.Returns:
the empty selection caption, not
null
Since:
8.0
See Also:
setEmptySelectionAllowed(boolean)
,isEmptySelectionAllowed()
,setEmptySelectionCaption(String)
,AbstractSingleSelect.isSelected(Object)
-
setEmptySelectionCaption
public void setEmptySelectionCaption(String caption)
Sets the empty selection caption.
The empty string
""
is the default empty selection caption.If empty selection is allowed via the
setEmptySelectionAllowed(boolean)
method (it is by default) then the empty item will be shown with the given caption.Parameters:
caption
- the caption to set, notnull
Since:
8.0
See Also:
-
setPopupWidth
public void setPopupWidth(String width)
Sets the suggestion pop-up's width as a CSS string. By using relative units (e.g. "50%") it's possible to set the popup's width relative to the ComboBox itself.
By default this width is set to "100%" so that the pop-up's width is equal to the width of the combobox. By setting width to null the pop-up's width will automatically expand beyond 100% relative width to fit the content of all displayed items.
Parameters:
width
- the widthSince:
7.7
See Also:
-
setScrollToSelectedItem
public void setScrollToSelectedItem(boolean scrollToSelectedItem)
Sets whether to scroll the selected item visible (directly open the page on which it is) when opening the combo box popup or not.
This requires finding the index of the item, which can be expensive in many large lazy loading containers.
Parameters:
scrollToSelectedItem
- true to find the page with the selected item when opening the selection popup
-
isScrollToSelectedItem
public boolean isScrollToSelectedItem()
Returns true if the select should find the page with the selected item when opening the popup.
Returns:
true if the page with the selected item will be shown when opening the popup
See Also:
-
getItemCaptionGenerator
public ItemCaptionGenerator<T> getItemCaptionGenerator()
Description copied from class:
AbstractListing
Gets the item caption generator that is used to produce the strings shown in the combo box for each item.
Overrides:
getItemCaptionGenerator
in classAbstractListing<T>
Returns:
the item caption generator used, not null
-
setItemCaptionGenerator
public void setItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator)
Description copied from class:
AbstractListing
Sets the item caption generator that is used to produce the strings shown in the combo box for each item. By default,
String.valueOf(Object)
is used.Overrides:
setItemCaptionGenerator
in classAbstractListing<T>
Parameters:
itemCaptionGenerator
- the item caption provider to use, not null
-
setStyleGenerator
public void setStyleGenerator(StyleGenerator<T> itemStyleGenerator)
Sets the style generator that is used to produce custom class names for items visible in the popup. The CSS class name that will be added to the item is v-filterselect-item-[style name]. Returning null from the generator results in no custom style name being set.
Parameters:
itemStyleGenerator
- the item style generator to set, not nullThrows:
NullPointerException
- ifitemStyleGenerator
isnull
Since:
8.0
See Also:
-
getStyleGenerator
public StyleGenerator<T> getStyleGenerator()
Gets the currently used style generator that is used to generate CSS class names for items. The default item style provider returns null for all items, resulting in no custom item class names being set.
Returns:
the currently used item style generator, not null
Since:
8.0
See Also:
-
setItemIconGenerator
public void setItemIconGenerator(IconGenerator<T> itemIconGenerator)
Description copied from class:
AbstractListing
Sets the item icon generator that is used to produce custom icons for shown items. The generator can return null for items with no icon.
Implementations that support item icons make this method public.
Overrides:
setItemIconGenerator
in classAbstractListing<T>
Parameters:
itemIconGenerator
- the item icon generator to set, not nullSee Also:
-
getItemIconGenerator
public IconGenerator<T> getItemIconGenerator()
Description copied from class:
AbstractListing
Gets the currently used item icon generator. The default item icon provider returns null for all items, resulting in no icons being used.
Implementations that support item icons make this method public.
Overrides:
getItemIconGenerator
in classAbstractListing<T>
Returns:
the currently used item icon generator, not null
See Also:
IconGenerator
,AbstractListing.setItemIconGenerator(IconGenerator)
-
setNewItemHandler
@Deprecated public void setNewItemHandler(ComboBox.NewItemHandler newItemHandler)
Deprecated.Since 8.4 usesetNewItemProvider(NewItemProvider)
instead.Sets the handler that is called when user types a new item. The creation of new items is allowed when a new item handler has been set. If new item provider is also set, the new item handler is ignored.
Parameters:
newItemHandler
- handler called for new items, null to only permit the selection of existing items, all options ignored if new item provider is setSince:
8.0
-
setNewItemProvider
public void setNewItemProvider(ComboBox.NewItemProvider<T> newItemProvider)
Sets the provider function that is called when user types a new item. The creation of new items is allowed when a new item provider has been set. If a deprecated new item handler is also set it is ignored in favor of new item provider.
Parameters:
newItemProvider
- provider function that is called for new items, null to only permit the selection of existing items or to use a deprecated new item handler if setSince:
8.4
-
getNewItemHandler
@Deprecated public ComboBox.NewItemHandler getNewItemHandler()
Deprecated.Since 8.4 usegetNewItemProvider()
instead.Returns the handler called when the user enters a new item (not present in the data provider).
Returns:
new item handler or null if none specified
-
getNewItemProvider
public ComboBox.NewItemProvider<T> getNewItemProvider()
Returns the provider function that is called when the user enters a new item (not present in the data provider).
Returns:
new item provider or null if none specified
Since:
8.4
-
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 this
HasValue
is changed either by the user or programmatically.Specified by:
addValueChangeListener
in interfaceHasValue<T>
Overrides:
addValueChangeListener
in classAbstractSingleSelect<T>
Parameters:
listener
- the value change listener, not nullReturns:
a registration for the listener
-
getState
protected ComboBoxState 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 classAbstractSingleSelect<T>
Returns:
updated component shared state
-
getState
protected ComboBoxState getState(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
getState
in classAbstractSingleSelect<T>
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
updateSelectedItemState
protected void updateSelectedItemState(T value)
Description copied from class:
AbstractSingleSelect
This method updates the shared selection state of the
AbstractSingleSelect
.Overrides:
updateSelectedItemState
in classAbstractSingleSelect<T>
Parameters:
value
- the value that is selected; may benull
-
attach
public void attach()
Description copied from interface:
ClientConnector
Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).
The caller of this method is
Component.setParent(HasComponents)
if the parent is itself already attached to the session. If not, the parent will call theClientConnector.attach()
for all its children when it is attached to the session. This method is always called before the connector's data is sent to the client-side for the first time.The attachment logic is implemented in
AbstractClientConnector
.Specified by:
attach
in interfaceClientConnector
Specified by:
Overrides:
attach
in classAbstractComponent
-
detach
public void detach()
Description copied from class:
AbstractClientConnector
Notifies the connector that it is detached from its VaadinSession.
The caller of this method is
Component.setParent(HasComponents)
if the parent is in the session. When the parent is detached from the session it is its responsibility to callClientConnector.detach()
for each of its children.The
AbstractClientConnector.getSession()
andAbstractClientConnector.getUI()
methods might returnnull
after this method is called.Specified by:
detach
in interfaceClientConnector
Overrides:
detach
in classAbstractComponent
-
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 classAbstractSingleSelect<T>
Parameters:
design
- the element into which to insert the itemitem
- the item to writecontext
- the DesignContext instance used in writingReturns:
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 the
design
.Overrides:
readItems
in classAbstractSingleSelect<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)
Description copied from class:
AbstractSingleSelect
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.
Overrides:
readItem
in classAbstractSingleSelect<T>
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 parsingReturns:
the item id of the new item
-
getDataProvider
public DataProvider<T,?> getDataProvider()
Description copied from interface:
HasItems
Returns the source of data items used by this listing.
Specified by:
getDataProvider
in interfaceHasItems<T>
Returns:
the data provider, not null
-
setDataProvider
public <C> void setDataProvider(DataProvider<T,C> dataProvider, SerializableFunction<String,C> filterConverter)
Description copied from interface:
HasFilterableDataProvider
Sets the data provider and filter converter for this listing. The data provider is queried for displayed items as needed.
Specified by:
setDataProvider
in interfaceHasFilterableDataProvider<T,String>
Type Parameters:
C
- filter typeParameters:
dataProvider
- the data provider, notnull
filterConverter
- a function that converts filter values produced by this listing into filter values expected by the provided data provider, notnull
-
setDataProvider
public void setDataProvider(ComboBox.FetchItemsCallback<T> fetchItems, SerializableToIntFunction<String> sizeCallback)
Sets a CallbackDataProvider using the given fetch items callback and a size callback.
This method is a shorthand for making a
CallbackDataProvider
that handles a partialQuery
object.Parameters:
fetchItems
- a callback for fetching itemssizeCallback
- a callback for getting the count of itemsSee Also:
CallbackDataProvider
,HasFilterableDataProvider.setDataProvider(DataProvider)
-
-