com.vaadin.flow.component.combobox.dataview.
Class ComboBoxDataView<T>
- java.lang.Object
-
- com.vaadin.flow.data.provider.AbstractDataView<T>
-
- com.vaadin.flow.component.combobox.dataview.ComboBoxDataView<T>
-
Type Parameters:
T
- the item typeAll Implemented Interfaces:
DataView<T>
,Serializable
public class ComboBoxDataView<T> extends AbstractDataView<T>
Implementation of generic data view for ComboBox. This implementation does not depend on a certain type of data provider, i.e. whether is it of in-memory or backend type. It can be used if the type of data provider is not either
ListDataProvider
orBackEndDataProvider
.Since:
See Also:
-
-
Field Summary
-
Fields inherited from class com.vaadin.flow.data.provider.AbstractDataView
component, dataProviderSupplier, NULL_IDENTIFIER_ERROR_MESSAGE, NULL_ITEM_ERROR_MESSAGE
-
-
Constructor Summary
Constructors Constructor Description ComboBoxDataView(DataCommunicator<T> dataCommunicator, ComboBox<T> comboBox)
Creates a new generic data view for ComboBox and verifies the passed data provider is compatible with this data view implementation.
-
Method Summary
All Methods Modifier and Type Method Description Registration
addItemCountChangeListener(ComponentEventListener<ItemCountChangeEvent<?>> listener)
Add an item count change listener that is fired when the item count changes.
T
getItem(int index)
Gets the item at the given index from the data available in the ComboBox's server-side.
Stream<T>
getItems()
Gets the items available on the ComboBox's server-side.
protected Class<?>
getSupportedDataProviderType()
Returns supported
DataProvider
type for thisDataView
.void
setIdentifierProvider(IdentifierProvider<T> identifierProvider)
Sets an identifier provider, which returns an identifier for the given item.
-
Methods inherited from class com.vaadin.flow.data.provider.AbstractDataView
equals, getIdentifierProvider, refreshAll, refreshItem, verifyDataProviderType
-
-
-
-
Constructor Detail
-
ComboBoxDataView
public ComboBoxDataView(DataCommunicator<T> dataCommunicator, ComboBox<T> comboBox)
Creates a new generic data view for ComboBox and verifies the passed data provider is compatible with this data view implementation.
Parameters:
dataCommunicator
- the data communicator of the componentcomboBox
- the ComboBox
-
-
Method Detail
-
getItem
public T getItem(int index)
Gets the item at the given index from the data available in the ComboBox's server-side.
This method does not take into account the ComboBox client-side filtering, since it doesn't change the item count on the server-side, but only makes it easier for users to search through the items in the UI.
Parameters:
index
- item index numberReturns:
item on index
Throws:
IndexOutOfBoundsException
- requested index is outside of the data set
-
getSupportedDataProviderType
protected Class<?> getSupportedDataProviderType()
Description copied from class:
AbstractDataView
Returns supported
DataProvider
type for thisDataView
.Specified by:
getSupportedDataProviderType
in classAbstractDataView<T>
Returns:
supported data provider type
-
getItems
public Stream<T> getItems()
Gets the items available on the ComboBox's server-side.
This method does not take into account the ComboBox client-side filtering, since it doesn't change the item count on the server-side, but only makes it easier for users to search through the items in the UI.
-
setIdentifierProvider
public void setIdentifierProvider(IdentifierProvider<T> identifierProvider)
Description copied from interface:
DataView
Sets an identifier provider, which returns an identifier for the given item. The identifier is used for comparing the equality of items. Usage example:
dataView.setIdentifiedProvider(Item::getId);
.Specified by:
setIdentifierProvider
in interfaceDataView<T>
Overrides:
setIdentifierProvider
in classAbstractDataView<T>
Parameters:
identifierProvider
- function that returns the non-null identifier for a given item
-
addItemCountChangeListener
public Registration addItemCountChangeListener(ComponentEventListener<ItemCountChangeEvent<?>> listener)
Add an item count change listener that is fired when the item count changes. This can happen for instance when filtering the items.
Item count change listener is bound to the component and will be retained even if the data changes by setting of a new items or
DataProvider
to component.NOTE: when the component supports lazy loading (implements
HasLazyDataView
) and a count callback has not been provided, an estimate of the item count is used and increased until the actual count has been reached. When the estimate is used, the event is fired with theItemCountChangeEvent.isItemCountEstimated()
returningtrue
.Combo box fires
ItemCountChangeEvent
and notifies all the listeners added by this method, if the items count changed, for instance, due to adding or removing an item(s).ComboBox's client-side filter change won't fire
ItemCountChangeEvent
, since it doesn't change the item count on the server-side, but only makes it easier for users to search through the items in the UI.Specified by:
addItemCountChangeListener
in interfaceDataView<T>
Overrides:
addItemCountChangeListener
in classAbstractDataView<T>
Parameters:
listener
- item count change listener to registerReturns:
registration for removing the listener
-
-