com.vaadin.flow.data.provider.
Interface DataView<T>
Type Parameters:
T
- data type
All Superinterfaces:
All Known Subinterfaces:
LazyDataView<T>
, ListDataView<T,
All Known Implementing Classes:
AbstractDataView
, AbstractLazyDataView
, AbstractListDataView
, CheckboxGroupDataView
, CheckboxGroupListDataView
, ComboBoxDataView
, ComboBoxLazyDataView
, ComboBoxListDataView
, GridDataView
, GridLazyDataView
, GridListDataView
, ListBoxDataView
, ListBoxListDataView
, RadioButtonGroupDataView
, RadioButtonGroupListDataView
, SelectDataView
, SelectListDataView
Base view interface for getting information on current data set of a Component.
Since:
-
Method Summary
Modifier and TypeMethodDescriptionAdd an item count change listener that is fired when the item count changes.
getItem
(int index) Gets the item at the given index from the data available to the component.
getItemIndex
(T item) Gets the index of the given item from the data available to the component.
getItems()
Get the full data available to the component.
void
Notifies the component that all the items should be refreshed.
void
refreshItem
(T item) Notifies the component that the item has been updated and thus should be refreshed.
void
setIdentifierProvider
(IdentifierProvider<T> identifierProvider) Sets an identifier provider, which returns an identifier for the given item.
-
Method Details
-
getItem
Gets the item at the given index from the data available to the component. Data is filtered and sorted the same way as in the component.
Parameters:
index
- item index numberReturns:
item on index
Throws:
IndexOutOfBoundsException
- requested index is outside of the filtered and sorted data set -
getItemIndex
Gets the index of the given item from the data available to the component. Data is filtered and sorted the same way as in the component.
Parameters:
item
- item to get index forReturns:
index of the item or empty optional if the item is not found
-
getItems
Get the full data available to the component. Data is filtered and sorted the same way as in the component.
Consumers of the returned stream are responsible for closing it when all the stream operations are done to ensure that any resources feeding the stream are properly released. Failure to close the stream might lead to resource leaks.
It is strongly recommended to use a try-with-resources block to automatically close the stream after its terminal operation has been executed. Below is an example of how to properly use and close the stream:
try (Stream<T> stream = dataView.getItems()) { stream.forEach(System.out::println); // Example terminal operation }
Returns:
filtered and sorted data set
-
refreshItem
Notifies the component that the item has been updated and thus should be refreshed.
For this to work properly, the item must either implement
Object.equals(Object)
andObject.hashCode()
to consider both the old and the new item instances to be equal, or alternatively use thesetIdentifierProvider(IdentifierProvider)
to set an appropriate item's identifier.This method delegates the update to
DataProvider.refreshItem(Object)
.Parameters:
item
- item containing updated stateSee Also:
-
refreshAll
void refreshAll()Notifies the component that all the items should be refreshed.
-
addItemCountChangeListener
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
.Parameters:
listener
- item count change listener to registerReturns:
registration for removing the listener
-
setIdentifierProvider
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);
.Parameters:
identifierProvider
- function that returns the non-null identifier for a given item
-