com.vaadin.flow.component.combobox.dataview.
Class ComboBoxListDataView<T>
- java.lang.Object
-
- com.vaadin.flow.data.provider.AbstractDataView<T>
-
- com.vaadin.flow.data.provider.AbstractListDataView<T>
-
- com.vaadin.flow.component.combobox.dataview.ComboBoxListDataView<T>
-
Type Parameters:
T
- the type of the items in ComboBoxAll Implemented Interfaces:
DataView<T>
,ListDataView<T,AbstractListDataView<T>>
,Serializable
public class ComboBoxListDataView<T> extends AbstractListDataView<T>
Data view implementation for ComboBox with in-memory list data. Provides information on the data and allows operations on it.
Since:
See Also:
-
-
Field Summary
-
Fields inherited from class com.vaadin.flow.data.provider.AbstractDataView
component, dataProviderSupplier, NULL_IDENTIFIER_ERROR_MESSAGE
-
-
Constructor Summary
Constructors Constructor Description ComboBoxListDataView(DataCommunicator<T> dataCommunicator, ComboBox<T> comboBox, SerializableBiConsumer<SerializablePredicate<T>,SerializableComparator<T>> filterOrSortingChangedCallback)
Creates a new instance of ComboBox in-memory data view and verifies the passed data provider is compatible with this data view implementation.
-
Method Summary
All Methods Modifier and Type Method Description ComboBoxListDataView<T>
addFilter(SerializablePredicate<T> filter)
Adds a filter to be applied to all queries.
Registration
addItemCountChangeListener(ComponentEventListener<ItemCountChangeEvent<?>> listener)
Add an item count change listener that is fired when the item count changes.
int
getItemCount()
Get the full item count with filters if any set.
Stream<T>
getItems()
Gets the items available on the ComboBox's server-side.
ComboBoxListDataView<T>
removeFilters()
Removes all in-memory filters set or added.
ComboBoxListDataView<T>
setFilter(SerializablePredicate<T> filter)
Sets a filter to be applied to the data.
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.AbstractListDataView
addItem, addItemAfter, addItemBefore, addItems, addItemsAfter, addItemsBefore, addSortComparator, addSortOrder, contains, getDataProvider, getItem, getNextItem, getPreviousItem, getSupportedDataProviderType, removeItem, removeItems, removeSorting, setSortComparator, setSortOrder, validateItemIndex
-
Methods inherited from class com.vaadin.flow.data.provider.AbstractDataView
equals, getIdentifierProvider, refreshAll, refreshItem, verifyDataProviderType
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.data.provider.DataView
refreshAll, refreshItem
-
-
-
-
Constructor Detail
-
ComboBoxListDataView
public ComboBoxListDataView(DataCommunicator<T> dataCommunicator, ComboBox<T> comboBox, SerializableBiConsumer<SerializablePredicate<T>,SerializableComparator<T>> filterOrSortingChangedCallback)
Creates a new instance of ComboBox in-memory data view and verifies the passed data provider is compatible with this data view implementation.
Parameters:
dataCommunicator
- the data communicator of the ComboBox, notnull
comboBox
- the ComboBox component, notnull
filterOrSortingChangedCallback
- callback, which is being invoked when the ComboBox's filtering or sorting changes, notnull
-
-
Method Detail
-
getItems
public Stream<T> getItems()
Gets the items available on the ComboBox's server-side.
Data is sorted the same way as in the ComboBox, but it 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. Only the server-side filtering considered, which is set by:
setFilter(SerializablePredicate)
oraddFilter(SerializablePredicate)
.
-
getItemCount
public int getItemCount()
Get the full item count with filters if any set. As the item count might change at any point, it is recommended to add a listener with the
DataView.addItemCountChangeListener(ComponentEventListener)
method instead to get notified when the item count has changed.This method takes into account only the server-side filtering, which is set by:
setFilter(SerializablePredicate)
oraddFilter(SerializablePredicate)
. ComboBox's client-side filter is not considered, 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:
getItemCount
in interfaceListDataView<T,AbstractListDataView<T>>
Overrides:
getItemCount
in classAbstractListDataView<T>
Returns:
filtered item count
See Also:
-
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 due to adding or removing an item(s), or by changing the server-side filtering withsetFilter(SerializablePredicate)
oraddFilter(SerializablePredicate)
.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
-
addFilter
public ComboBoxListDataView<T> addFilter(SerializablePredicate<T> filter)
Adds a filter to be applied to all queries. The filter will be used in addition to any filter that has been set or added previously through
setFilter(com.vaadin.flow.function.SerializablePredicate<T>)
oraddFilter(com.vaadin.flow.function.SerializablePredicate<T>)
. This filter is applied to data set permanently until it's changed throughsetFilter(com.vaadin.flow.function.SerializablePredicate<T>)
orremoveFilters()
, in contrary with the client-side filter that can be typed in by user and does not modify the data set on server-side, but only defines which items are shown for a single request and erases on drop down close.This filter is bound to the component. Thus, any other component using the same
DataProvider
object would not be affected by setting a filter through data view of another component. A filter set by this method won't be retained when a newDataProvider
is set to the component.Specified by:
addFilter
in interfaceListDataView<T,AbstractListDataView<T>>
Overrides:
addFilter
in classAbstractListDataView<T>
Parameters:
filter
- the filter to add, notnull
Returns:
ComboBoxListDataView instance
See Also:
-
removeFilters
public ComboBoxListDataView<T> removeFilters()
Removes all in-memory filters set or added.
Specified by:
removeFilters
in interfaceListDataView<T,AbstractListDataView<T>>
Overrides:
removeFilters
in classAbstractListDataView<T>
Returns:
ComboBoxListDataView instance
See Also:
addFilter(SerializablePredicate)
,setFilter(SerializablePredicate)
-
setFilter
public ComboBoxListDataView<T> setFilter(SerializablePredicate<T> filter)
Sets a filter to be applied to the data. The filter replaces any filter that has been set or added previously.
null
will clear all filters. This filter is applied to data set permanently until it's changed throughsetFilter(com.vaadin.flow.function.SerializablePredicate<T>)
orremoveFilters()
, in contrary with the client-side filter that can be typed in by user and does not modify the data set on server-side, but only defines which items are shown for a single request and erases on drop down close.This filter is bound to the component. Thus, any other component using the same
DataProvider
object would not be affected by setting a filter through data view of another component. A filter set by this method won't be retained when a newDataProvider
is set to the component.Specified by:
setFilter
in interfaceListDataView<T,AbstractListDataView<T>>
Overrides:
setFilter
in classAbstractListDataView<T>
Parameters:
filter
- filter to be set, ornull
to clear any previously set filtersReturns:
ComboBoxListDataView instance
See Also:
-
-