T
- the type of the items in ComboBoxpublic class ComboBoxListDataView<T> extends AbstractListDataView<T>
component, dataProviderSupplier, NULL_IDENTIFIER_ERROR_MESSAGE
Constructor and 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.
|
Modifier and Type | Method and 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.
|
addItem, addItemAfter, addItemBefore, addItems, addItemsAfter, addItemsBefore, addSortComparator, addSortOrder, contains, getDataProvider, getItem, getNextItem, getPreviousItem, getSupportedDataProviderType, removeItem, removeItems, removeSorting, setSortComparator, setSortOrder, validateItemIndex
equals, getIdentifierProvider, refreshAll, refreshItem, verifyDataProviderType
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
refreshAll, refreshItem
public ComboBoxListDataView(DataCommunicator<T> dataCommunicator, ComboBox<T> comboBox, SerializableBiConsumer<SerializablePredicate<T>,SerializableComparator<T>> filterOrSortingChangedCallback)
dataCommunicator
- the data communicator of the ComboBox, not null
comboBox
- the ComboBox component, not null
filterOrSortingChangedCallback
- callback, which is being invoked when the ComboBox's filtering
or sorting changes, not null
public Stream<T> getItems()
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)
or
addFilter(SerializablePredicate)
.
public int getItemCount()
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)
or
addFilter(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.
getItemCount
in interface ListDataView<T,AbstractListDataView<T>>
getItemCount
in class AbstractListDataView<T>
DataView.addItemCountChangeListener(ComponentEventListener)
public void setIdentifierProvider(IdentifierProvider<T> identifierProvider)
DataView
dataView.setIdentifiedProvider(Item::getId);
.setIdentifierProvider
in interface DataView<T>
setIdentifierProvider
in class AbstractDataView<T>
identifierProvider
- function that returns the non-null identifier for a given itempublic Registration addItemCountChangeListener(ComponentEventListener<ItemCountChangeEvent<?>> listener)
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 the
ItemCountChangeEvent.isItemCountEstimated()
returning
true
.
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 with
setFilter(SerializablePredicate)
or
addFilter(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.
addItemCountChangeListener
in interface DataView<T>
addItemCountChangeListener
in class AbstractDataView<T>
listener
- item count change listener to registerpublic ComboBoxListDataView<T> addFilter(SerializablePredicate<T> filter)
setFilter(com.vaadin.flow.function.SerializablePredicate<T>)
or addFilter(com.vaadin.flow.function.SerializablePredicate<T>)
. This filter is applied to data
set permanently until it's changed through setFilter(com.vaadin.flow.function.SerializablePredicate<T>)
or
removeFilters()
, 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 new DataProvider
is set to the
component.
addFilter
in interface ListDataView<T,AbstractListDataView<T>>
addFilter
in class AbstractListDataView<T>
filter
- the filter to add, not null
setFilter(SerializablePredicate)
,
removeFilters()
public ComboBoxListDataView<T> removeFilters()
removeFilters
in interface ListDataView<T,AbstractListDataView<T>>
removeFilters
in class AbstractListDataView<T>
addFilter(SerializablePredicate)
,
setFilter(SerializablePredicate)
public ComboBoxListDataView<T> setFilter(SerializablePredicate<T> filter)
null
will clear all
filters. This filter is applied to data set permanently until it's
changed through setFilter(com.vaadin.flow.function.SerializablePredicate<T>)
or removeFilters()
, 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 new DataProvider
is set to the
component.
setFilter
in interface ListDataView<T,AbstractListDataView<T>>
setFilter
in class AbstractListDataView<T>
filter
- filter to be set, or null
to clear any previously
set filtersaddFilter(SerializablePredicate)
,
removeFilters()
Copyright © 2022. All rights reserved.