T - item (bean) type in ComboBoxpublic class ComboBox<T> extends AbstractSingleSelect<T> implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, HasFilterableDataProvider<T,String>
| Modifier and Type | Class and 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 by
ComboBox.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.
|
AbstractListing.AbstractListingExtension<T>Component.ErrorEvent, Component.Event, Component.Focusable, Component.ListenerClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListenerSizeable.UnitHasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>DESIGN_ATTR_PLAIN_TEXTSIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS| Modifier | Constructor and 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) or setItems(Collection). |
|
ComboBox(String caption,
Collection<T> options)
Constructs a combo box with a static in-memory data provider with the
given options.
|
| Modifier and Type | Method and Description |
|---|---|
Registration |
addBlurListener(FieldEvents.BlurListener listener)
Adds a
BlurListener to the Component which gets fired
when a Field loses keyboard focus. |
Registration |
addFocusListener(FieldEvents.FocusListener listener)
Adds a
FocusListener to the Component which gets fired
when a Field 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).
|
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 use
getNewItemProvider() 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) and
setNewItemHandler(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. |
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.
|
<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 |
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(Collection<T> items)
Sets the data items of this component provided as a collection.
|
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(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 use
setNewItemProvider(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.
|
addSelectionListener, getCustomAttributes, getSelectedItem, getValue, isReadOnly, isRequiredIndicatorVisible, isSelected, keyToItem, setReadOnly, setRequiredIndicatorVisible, setSelectedItem, setSelectedItem, setValueaddDataGenerator, deserializeDeclarativeRepresentation, doReadDesign, doWriteDesign, focus, getDataCommunicator, getTabIndex, internalGetDataProvider, internalSetDataProvider, internalSetDataProvider, readDesign, readItem, removeDataGenerator, serializeDeclarativeRepresentation, setTabIndex, writeDesign, writeItemsaddContextClickListener, addListener, addShortcutListener, addStyleName, 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, setWidthUndefinedaddAttachListener, addDetachListener, addExtension, 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, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstateclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitsetDataProvideraddListener, 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, writeDesignaddAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandlergetConnectorIdgetHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefinedclear, getDefaultValidator, getEmptyValue, getOptionalValue, isEmptypublic ComboBox()
HasFilterableDataProvider.setDataProvider(DataProvider) or
setItems(Collection)public ComboBox(String caption)
HasFilterableDataProvider.setDataProvider(DataProvider) or setItems(Collection).caption - the caption to show in the containing layout, null for no
captionpublic ComboBox(String caption, Collection<T> options)
caption - the caption to show in the containing layout, null for no
captionoptions - collection of options, not nullprotected ComboBox(DataCommunicator<T> dataCommunicator)
dataCommunicator - the data comnunicator to use with this ComboBoxpublic void setItems(Collection<T> items)
The provided items are wrapped into a ListDataProvider and this
instance is used as a data provider for the
#setDataProvider(DataProvider) method. It means that the items
collection can be accessed later on via
ListDataProvider.getItems():
HasDataProvider<String> listing = new CheckBoxGroup<>();
listing.setItems(Arrays.asList("a","b"));
...
Collection collection = ((ListDataProvider)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.
public void setItems(Stream<T> streamOfItems)
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. See BackEndDataProvider for more info.
The provided items are wrapped into a ListDataProvider and this
instance is used as a data provider for the
#setDataProvider(DataProvider) method. It means that the items
collection can be accessed later on via
ListDataProvider.getItems():
HasDataProvider<String> listing = new CheckBoxGroup<>();
listing.setItems(Stream.of("a","b"));
...
Collection 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 in interface HasItems<T>streamOfItems - the stream of data items to display, not nullHasItems.setItems(Collection)public void setItems(T... items)
The provided items are wrapped into a ListDataProvider and this
instance is used as a data provider for the
#setDataProvider(DataProvider) method. It means that the items
collection can be accessed later on via
ListDataProvider.getItems():
HasDataProvider listing = new CheckBoxGroup<>();
listing.setItems("a","b");
...
Collection collection = ((ListDataProvider)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 in interface HasItems<T>items - the data items to displayHasItems.setItems(Collection)public void setDataProvider(ListDataProvider<T> listDataProvider)
Note that this is a shorthand that calls
HasFilterableDataProvider.setDataProvider(DataProvider) with a wrapper of the provided
list data provider. This means that getDataProvider() will
return the wrapper instead of the original list data provider.
listDataProvider - the list data provider to use, not nullpublic void setItems(ComboBox.CaptionFilter captionFilter, Collection<T> items)
Note that unlike setItems(Collection), no automatic case
conversion is performed before the comparison.
captionFilter - filter to check if an item is shown when user typed some text
into the ComboBoxitems - the data items to displaypublic void setDataProvider(ComboBox.CaptionFilter captionFilter, ListDataProvider<T> listDataProvider)
captionFilter - filter to check if an item is shown when user typed some text
into the ComboBoxlistDataProvider - the list data provider to use, not nullpublic void setItems(ComboBox.CaptionFilter captionFilter, T... items)
Note that unlike setItems(Collection), no automatic case
conversion is performed before the comparison.
captionFilter - filter to check if an item is shown when user typed some text
into the ComboBoxitems - the data items to displaypublic String getPlaceholder()
setPlaceholder(String)public void setPlaceholder(String placeholder)
placeholder - the desired placeholder, or null to disablepublic void setTextInputAllowed(boolean textInputAllowed)
NativeSelecttextInputAllowed - true to allow entering text, false to just show the current
selectionisTextInputAllowed()public boolean isTextInputAllowed()
setNewItemProvider(NewItemProvider) (recommended) and
setNewItemHandler(NewItemHandler) (deprecated)). If text input
is disabled, the comboBox will work in the same way as a
NativeSelectpublic Registration addBlurListener(FieldEvents.BlurListener listener)
FieldEvents.BlurNotifierBlurListener to the Component which gets fired
when a Field loses keyboard focus.addBlurListener in interface FieldEvents.BlurNotifierlistener - the blur listener to add, not nullFieldEvents.BlurListener,
Registrationpublic Registration addFocusListener(FieldEvents.FocusListener listener)
FieldEvents.FocusNotifierFocusListener to the Component which gets fired
when a Field receives keyboard focus.addFocusListener in interface FieldEvents.FocusNotifierlistener - the focus listener to add, not nullFieldEvents.FocusListener,
Registrationpublic int getPageLength()
public String getPopupWidth()
setPopupWidth(java.lang.String)public void setPageLength(int pageLength)
pageLength - the pageLength to setpublic boolean isEmptySelectionAllowed()
public void setEmptySelectionAllowed(boolean emptySelectionAllowed)
emptySelectionAllowed - true to allow not selecting anything, false to require
selectionpublic String getEmptySelectionCaption()
The empty string "" is the default empty selection caption.
nullsetEmptySelectionAllowed(boolean),
isEmptySelectionAllowed(),
setEmptySelectionCaption(String),
AbstractSingleSelect.isSelected(Object)public void setEmptySelectionCaption(String 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.
caption - the caption to set, not nullAbstractSingleSelect.isSelected(Object)public void setPopupWidth(String width)
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.
width - the widthgetPopupWidth()public void setScrollToSelectedItem(boolean scrollToSelectedItem)
This requires finding the index of the item, which can be expensive in many large lazy loading containers.
scrollToSelectedItem - true to find the page with the selected item when opening the
selection popuppublic boolean isScrollToSelectedItem()
setScrollToSelectedItem(boolean)public ItemCaptionGenerator<T> getItemCaptionGenerator()
AbstractListinggetItemCaptionGenerator in class AbstractListing<T>public void setItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator)
AbstractListingString.valueOf(Object) is used.setItemCaptionGenerator in class AbstractListing<T>itemCaptionGenerator - the item caption provider to use, not nullpublic void setStyleGenerator(StyleGenerator<T> itemStyleGenerator)
itemStyleGenerator - the item style generator to set, not nullNullPointerException - if itemStyleGenerator is nullStyleGeneratorpublic StyleGenerator<T> getStyleGenerator()
StyleGenerator,
setStyleGenerator(StyleGenerator)public void setItemIconGenerator(IconGenerator<T> itemIconGenerator)
AbstractListingImplementations that support item icons make this method public.
setItemIconGenerator in class AbstractListing<T>itemIconGenerator - the item icon generator to set, not nullIconGeneratorpublic IconGenerator<T> getItemIconGenerator()
AbstractListingImplementations that support item icons make this method public.
getItemIconGenerator in class AbstractListing<T>IconGenerator,
AbstractListing.setItemIconGenerator(IconGenerator)@Deprecated public void setNewItemHandler(ComboBox.NewItemHandler newItemHandler)
setNewItemProvider(NewItemProvider)
instead.newItemHandler - handler called for new items, null to only permit the
selection of existing items, all options ignored if new item
provider is setpublic void setNewItemProvider(ComboBox.NewItemProvider<T> newItemProvider)
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@Deprecated public ComboBox.NewItemHandler getNewItemHandler()
getNewItemProvider() instead.public ComboBox.NewItemProvider<T> getNewItemProvider()
public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener)
HasValueHasValue is changed either by the user or programmatically.addValueChangeListener in interface HasValue<T>addValueChangeListener in class AbstractSingleSelect<T>listener - the value change listener, not nullprotected ComboBoxState getState()
AbstractComponentgetState in class AbstractSingleSelect<T>protected ComboBoxState getState(boolean markAsDirty)
AbstractClientConnectorgetState in class AbstractSingleSelect<T>markAsDirty - true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()protected void updateSelectedItemState(T value)
AbstractSingleSelectAbstractSingleSelect.updateSelectedItemState in class AbstractSingleSelect<T>value - the value that is selected; may be nullpublic void attach()
ClientConnector
The caller of this method is Connector#setParent(ClientConnector)
if the parent is itself already attached to the session. If not, the
parent will call the ClientConnector.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.
attach in interface ClientConnectorattach in interface Componentattach in class AbstractComponentprotected org.jsoup.nodes.Element writeItem(org.jsoup.nodes.Element design,
T item,
DesignContext context)
AbstractListingwriteItem in class AbstractSingleSelect<T>design - the element into which to insert the itemitem - the item to writecontext - the DesignContext instance used in writingitemprotected void readItems(org.jsoup.nodes.Element design,
DesignContext context)
AbstractListingdesign.readItems in class AbstractSingleSelect<T>design - The element to obtain the state fromcontext - The DesignContext instance used for parsing the designprotected T readItem(org.jsoup.nodes.Element child, Set<T> selected, DesignContext context)
AbstractSingleSelectreadItem in class AbstractSingleSelect<T>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 parsingpublic DataProvider<T,?> getDataProvider()
HasItemsgetDataProvider in interface HasItems<T>public <C> void setDataProvider(DataProvider<T,C> dataProvider, SerializableFunction<String,C> filterConverter)
HasFilterableDataProvidersetDataProvider in interface HasFilterableDataProvider<T,String>dataProvider - the data provider, not nullfilterConverter - a function that converts filter values produced by this
listing into filter values expected by the provided data
provider, not nullpublic void setDataProvider(ComboBox.FetchItemsCallback<T> fetchItems, SerializableToIntFunction<String> sizeCallback)
This method is a shorthand for making a CallbackDataProvider that
handles a partial Query object.
fetchItems - a callback for fetching itemssizeCallback - a callback for getting the count of itemsCallbackDataProvider,
HasFilterableDataProvider.setDataProvider(DataProvider)Copyright © 2020 Vaadin Ltd. All rights reserved.