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 ComboBox
- All 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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceComboBox.CaptionFilterPredicate to checkComboBoxitem captions against user typed strings.protected static classComboBox.DeclarativeStyleGenerator<T>Item style generator class for declarative support.static interfaceComboBox.FetchItemsCallback<T>A callback method for fetching items.static interfaceComboBox.NewItemHandlerDeprecated.Since 8.4 replaced byComboBox.NewItemProvider.static interfaceComboBox.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.protectedComboBox(DataCommunicator<T> dataCommunicator)Constructs and initializes an empty combo box.ComboBox(String caption)Constructs an empty combo box, whose content can be set withHasFilterableDataProvider.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 Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RegistrationaddBlurListener(FieldEvents.BlurListener listener)Adds aBlurListenerto the Component which gets fired when aFieldloses keyboard focus.RegistrationaddFocusListener(FieldEvents.FocusListener listener)Adds aFocusListenerto the Component which gets fired when aFieldreceives keyboard focus.RegistrationaddValueChangeListener(HasValue.ValueChangeListener<T> listener)Adds a value change listener.voidattach()Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).voiddetach()Notifies the connector that it is detached from its VaadinSession.DataProvider<T,?>getDataProvider()Returns the source of data items used by this listing.StringgetEmptySelectionCaption()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.NewItemHandlergetNewItemHandler()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).intgetPageLength()Returns the page length of the suggestion popup.StringgetPlaceholder()Gets the current placeholder text shown when the combo box would be empty.StringgetPopupWidth()Returns the suggestion pop-up's width as a CSS string.protected ComboBoxStategetState()Returns the shared state bean with information to be sent from the server to the client.protected ComboBoxStategetState(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.booleanisEmptySelectionAllowed()Returns whether the user is allowed to select nothing in the combo box.booleanisScrollToSelectedItem()Returns true if the select should find the page with the selected item when opening the popup.booleanisTextInputAllowed()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 (seesetNewItemProvider(NewItemProvider)(recommended) andsetNewItemHandler(NewItemHandler)(deprecated)).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.<C> voidsetDataProvider(DataProvider<T,C> dataProvider, SerializableFunction<String,C> filterConverter)Sets the data provider and filter converter for this listing.voidsetDataProvider(ListDataProvider<T> listDataProvider)Sets a list data provider as the data provider of this combo box.voidsetDataProvider(ComboBox.CaptionFilter captionFilter, ListDataProvider<T> listDataProvider)Sets a list data provider with an item caption filter as the data provider of this combo box.voidsetDataProvider(ComboBox.FetchItemsCallback<T> fetchItems, SerializableToIntFunction<String> sizeCallback)Sets a CallbackDataProvider using the given fetch items callback and a size callback.voidsetEmptySelectionAllowed(boolean emptySelectionAllowed)Sets whether the user is allowed to select nothing in the combo box.voidsetEmptySelectionCaption(String caption)Sets the empty selection caption.voidsetItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator)Sets the item caption generator that is used to produce the strings shown in the combo box for each item.voidsetItemIconGenerator(IconGenerator<T> itemIconGenerator)Sets the item icon generator that is used to produce custom icons for shown items.voidsetItems(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.voidsetItems(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.voidsetItems(Collection<T> items)Sets the data items of this component provided as a collection.voidsetItems(Stream<T> streamOfItems)Sets the data items of this listing provided as a stream.voidsetItems(T... items)Sets the data items of this listing.voidsetNewItemHandler(ComboBox.NewItemHandler newItemHandler)Deprecated.Since 8.4 usesetNewItemProvider(NewItemProvider)instead.voidsetNewItemProvider(ComboBox.NewItemProvider<T> newItemProvider)Sets the provider function that is called when user types a new item.voidsetPageLength(int pageLength)Sets the page length for the suggestion popup.voidsetPlaceholder(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.voidsetPopupWidth(String width)Sets the suggestion pop-up's width as a CSS string.voidsetScrollToSelectedItem(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.voidsetStyleGenerator(StyleGenerator<T> itemStyleGenerator)Sets the style generator that is used to produce custom class names for items visible in the popup.voidsetTextInputAllowed(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 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.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 withHasFilterableDataProvider.setDataProvider(DataProvider)orsetItems(Collection)
-
ComboBox
public ComboBox(String caption)
Constructs an empty combo box, whose content can be set withHasFilterableDataProvider.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 ComboBox- Since:
- 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
ListDataProviderand 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. SeeBackEndDataProviderfor more info.The provided items are wrapped into a
ListDataProviderand 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.
- Specified by:
setItemsin interfaceHasItems<T>- Parameters:
streamOfItems- the stream of data items to display, notnull- See Also:
HasItems.setItems(Collection)
-
setItems
public void setItems(T... items)
Sets the data items of this listing.The provided items are wrapped into a
ListDataProviderand 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.
- Specified by:
setItemsin interfaceHasItems<T>- Parameters:
items- the data items to display- See Also:
HasItems.setItems(Collection)
-
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 display- Since:
- 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 display- Since:
- 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(String)
-
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 disable- Since:
- 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 aNativeSelect- Parameters:
textInputAllowed- true to allow entering text, false to just show the current selection- See Also:
isTextInputAllowed()
-
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 (seesetNewItemProvider(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.BlurNotifierAdds aBlurListenerto the Component which gets fired when aFieldloses keyboard focus.- Specified by:
addBlurListenerin interfaceFieldEvents.BlurNotifier- Parameters:
listener- the blur listener to add, not null- Returns:
- a registration object for removing the listener
- See Also:
FieldEvents.BlurListener,Registration
-
addFocusListener
public Registration addFocusListener(FieldEvents.FocusListener listener)
Description copied from interface:FieldEvents.FocusNotifierAdds aFocusListenerto the Component which gets fired when aFieldreceives keyboard focus.- Specified by:
addFocusListenerin interfaceFieldEvents.FocusNotifier- Parameters:
listener- the focus listener to add, not null- Returns:
- a registration object for removing the listener
- See Also:
FieldEvents.FocusListener,Registration
-
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:
setPopupWidth(java.lang.String)
-
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 selection- Since:
- 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:
AbstractSingleSelect.isSelected(Object)
-
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 width- Since:
- 7.7
- See Also:
getPopupWidth()
-
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:
setScrollToSelectedItem(boolean)
-
getItemCaptionGenerator
public ItemCaptionGenerator<T> getItemCaptionGenerator()
Description copied from class:AbstractListingGets the item caption generator that is used to produce the strings shown in the combo box for each item.- Overrides:
getItemCaptionGeneratorin classAbstractListing<T>- Returns:
- the item caption generator used, not null
-
setItemCaptionGenerator
public void setItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator)
Description copied from class:AbstractListingSets 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:
setItemCaptionGeneratorin 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 null- Throws:
NullPointerException- ifitemStyleGeneratorisnull- Since:
- 8.0
- See Also:
StyleGenerator
-
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:
StyleGenerator,setStyleGenerator(StyleGenerator)
-
setItemIconGenerator
public void setItemIconGenerator(IconGenerator<T> itemIconGenerator)
Description copied from class:AbstractListingSets 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:
setItemIconGeneratorin classAbstractListing<T>- Parameters:
itemIconGenerator- the item icon generator to set, not null- See Also:
IconGenerator
-
getItemIconGenerator
public IconGenerator<T> getItemIconGenerator()
Description copied from class:AbstractListingGets 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:
getItemIconGeneratorin 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 set- Since:
- 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 set- Since:
- 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: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>- Overrides:
addValueChangeListenerin classAbstractSingleSelect<T>- Parameters:
listener- the value change listener, not null- Returns:
- a registration for the listener
-
getState
protected ComboBoxState 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 classAbstractSingleSelect<T>- Returns:
- updated component shared state
-
getState
protected ComboBoxState getState(boolean markAsDirty)
Description copied from class:AbstractClientConnectorReturns the shared state for this connector.- Overrides:
getStatein classAbstractSingleSelect<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()
-
updateSelectedItemState
protected void updateSelectedItemState(T value)
Description copied from class:AbstractSingleSelectThis method updates the shared selection state of theAbstractSingleSelect.- Overrides:
updateSelectedItemStatein classAbstractSingleSelect<T>- Parameters:
value- the value that is selected; may benull
-
attach
public void attach()
Description copied from interface:ClientConnectorNotifies 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:
attachin interfaceClientConnector- Specified by:
attachin interfaceComponent- Overrides:
attachin classAbstractComponent
-
detach
public void detach()
Description copied from class:AbstractClientConnectorNotifies 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 returnnullafter this method is called.- Specified by:
detachin interfaceClientConnector- Overrides:
detachin classAbstractComponent
-
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 classAbstractSingleSelect<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.- Overrides:
readItemsin 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:AbstractSingleSelectReads 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:
readItemin 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 parsing- Returns:
- the item id of the new item
-
getDataProvider
public DataProvider<T,?> getDataProvider()
Description copied from interface:HasItemsReturns the source of data items used by this listing.- Specified by:
getDataProviderin 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:HasFilterableDataProviderSets the data provider and filter converter for this listing. The data provider is queried for displayed items as needed.- Specified by:
setDataProviderin interfaceHasFilterableDataProvider<T,String>- Type Parameters:
C- filter type- Parameters:
dataProvider- the data provider, notnullfilterConverter- 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
CallbackDataProviderthat handles a partialQueryobject.- Parameters:
fetchItems- a callback for fetching itemssizeCallback- a callback for getting the count of items- See Also:
CallbackDataProvider,HasFilterableDataProvider.setDataProvider(DataProvider)
-
-