com.vaadin.flow.data.provider.
Class AbstractListDataView<T>
Type Parameters:
T
- data type
All Implemented Interfaces:
DataView<T>
, ListDataView<T,
, Serializable
Direct Known Subclasses:
CheckboxGroupListDataView
, ComboBoxListDataView
, GridListDataView
, ListBoxListDataView
, RadioButtonGroupListDataView
, SelectListDataView
Abstract list data view implementation which provides common methods for
fetching, filtering and sorting in-memory data to all ListDataView
subclasses.
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
ConstructorsConstructorDescriptionAbstractListDataView
(SerializableSupplier<? extends DataProvider<T, ?>> dataProviderSupplier, Component component, SerializableBiConsumer<SerializablePredicate<T>, SerializableComparator<T>> filterOrSortingChangedCallback) Creates a new instance of
AbstractListDataView
subclass and verifies the passed data provider is compatible with this data view implementation. -
Method Summary
Modifier and TypeMethodDescriptionaddFilter
(SerializablePredicate<T> filter) Adds a filter to be applied to all queries.
Adds an item to the data list if it is not already present.
addItemAfter
(T item, T after) Adds an item after the given target item.
addItemBefore
(T item, T before) Adds an item before the given target item.
addItems
(Collection<T> items) Adds multiple items to the data list.
addItemsAfter
(Collection<T> items, T after) Adds multiple items after the given target item.
addItemsBefore
(Collection<T> items, T before) Adds multiple items before the given target item.
addSortComparator
(SerializableComparator<T> sortComparator) Adds a comparator to the data default sorting.
<V1 extends Comparable<? super V1>>
AbstractListDataView<T>addSortOrder
(ValueProvider<T, V1> valueProvider, SortDirection sortDirection) Adds a property and direction to the default sorting.
boolean
Check if item is present in the currently filtered data set.
protected ListDataProvider<T>
getItem
(int index) Gets the item at the given index from the data available to the component.
int
Get the full item count with filters if any set.
getItems()
Get the full data available to the component.
getNextItem
(T item) Gets the item after given item from the filtered and sorted data.
getPreviousItem
(T item) Gets the item before given item from the filtered and sorted data.
protected Class<?>
Returns supported
DataProvider
type for thisDataView
.Removes all in-memory filters set or added.
removeItem
(T item) Remove an item from the data list.
removeItems
(Collection<T> items) Remove multiple items from the data list.
Removes any default sorting that has been set or added previously.
setFilter
(SerializablePredicate<T> filter) Sets a filter to be applied to the data.
setSortComparator
(SerializableComparator<T> sortComparator) Sets the comparator to use as the default sorting.
<V1 extends Comparable<? super V1>>
AbstractListDataView<T>setSortOrder
(ValueProvider<T, V1> valueProvider, SortDirection sortDirection) Sets the property and direction to use as the default sorting.
protected void
validateItemIndex
(int itemIndex) Validate that index is inside bounds of the data available.
Methods inherited from class com.vaadin.flow.data.provider.AbstractDataView
addIdentifierProviderChangeListener, addItemCountChangeListener, equals, getIdentifierProvider, getItemIndex, getItemIndex, refreshAll, refreshItem, setIdentifierProvider, verifyDataProviderType, 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
addItemCountChangeListener, getItemIndex, refreshAll, refreshItem, setIdentifierProvider
-
Constructor Details
-
AbstractListDataView
public AbstractListDataView(SerializableSupplier<? extends DataProvider<T, ?>> dataProviderSupplier, Component component, SerializableBiConsumer<SerializablePredicate<T>, SerializableComparator<T>> filterOrSortingChangedCallback) Creates a new instance of
AbstractListDataView
subclass and verifies the passed data provider is compatible with this data view implementation.Parameters:
dataProviderSupplier
- supplier from which the DataProvider can be gottencomponent
- the component that the dataView is bound tofilterOrSortingChangedCallback
- callback, which is being invoked when the component filtering or sorting changes, notnull
-
-
Method Details
-
getItemCount
public int getItemCount()Description copied from interface:
ListDataView
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.Specified by:
getItemCount
in interfaceListDataView<T,
AbstractListDataView<T>> Returns:
filtered item count
See Also:
-
getItem
Description copied from interface:
DataView
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.
-
getItems
Description copied from interface:
DataView
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 }
-
getNextItem
Description copied from interface:
ListDataView
Gets the item after given item from the filtered and sorted data.
Note! Item might be present in the data set, but be filtered out or be the last item so that the next item won't be available.
Specified by:
getNextItem
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
item
- item to get next forReturns:
next item if available, else empty optional if item doesn't exist or not in current filtered items
See Also:
-
getPreviousItem
Description copied from interface:
ListDataView
Gets the item before given item from the filtered and sorted data.
Note! Item might be present in the data set, but be filtered out or be the first item so that the previous item won't be available.
Specified by:
getPreviousItem
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
item
- item to get previous forReturns:
previous item if available, else empty optional if item doesn't exist or not in current filtered items
See Also:
-
addFilter
Description copied from interface:
ListDataView
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.
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.Refreshes all items of the component after adding the filter, i.e. runs
DataView.refreshAll()
.Specified by:
addFilter
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
filter
- the filter to add, notnull
Returns:
ListDataView instance
See Also:
-
removeFilters
Description copied from interface:
ListDataView
Removes all in-memory filters set or added.
Refreshes all items of the component after removing the filter, i.e. runs
DataView.refreshAll()
.Specified by:
removeFilters
in interfaceListDataView<T,
AbstractListDataView<T>> Returns:
ListDataView instance
See Also:
-
setFilter
Description copied from interface:
ListDataView
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 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.Refreshes all items of the component after setting the filter, i.e. runs
DataView.refreshAll()
.Specified by:
setFilter
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
filter
- filter to be set, ornull
to clear any previously set filtersReturns:
ListDataView instance
See Also:
-
setSortComparator
Description copied from interface:
ListDataView
Sets the comparator to use as the default sorting. This overrides the sorting set by any other method that manipulates the default sorting.
This comparator is bound to the component. Thus, any other component using the same
DataProvider
object would not be affected by setting a sort comparator through data view of another component. A sorting set by this method won't be retained when a newDataProvider
is set to the component.Refreshes all items of the component after setting the sorting, i.e. runs
DataView.refreshAll()
.Specified by:
setSortComparator
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
sortComparator
- a comparator to use, ornull
to clear any previously set sort orderReturns:
ListDataView instance
See Also:
-
addSortComparator
Description copied from interface:
ListDataView
Adds a comparator to the data default sorting. If no default sorting has been defined, then the provided comparator will be used as the default sorting. If a default sorting has been defined, then the provided comparator will be used to determine the ordering of items that are considered equal by the previously defined default sorting.
This comparator is bound to the component. Thus, any other component using the same
DataProvider
object would not be affected by setting a sort comparator through data view of another component. A sorting set by this method won't be retained when a newDataProvider
is set to the component.Refreshes all items of the component after adding the sorting, i.e. runs
DataView.refreshAll()
.Specified by:
addSortComparator
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
sortComparator
- a comparator to add, notnull
Returns:
ListDataView instance
See Also:
-
removeSorting
Description copied from interface:
ListDataView
Removes any default sorting that has been set or added previously.
Any other component using the same
DataProvider
object would not be affected by removing default sorting through data view of another component.Refreshes all items of the component after removing the sorting, i.e. runs
DataView.refreshAll()
.Specified by:
removeSorting
in interfaceListDataView<T,
AbstractListDataView<T>> Returns:
ListDataView instance
See Also:
-
setSortOrder
public <V1 extends Comparable<? super V1>> AbstractListDataView<T> setSortOrder(ValueProvider<T, V1> valueProvider, SortDirection sortDirection) Description copied from interface:
ListDataView
Sets the property and direction to use as the default sorting. This overrides the sorting set by any other method that manipulates the default sorting of this
DataProvider
.This sort order is bound to the component. Thus, any other component using the same
DataProvider
object would not be affected by setting a sort order through data view of another component. A sort order set by this method won't be retained when a newDataProvider
is set to the component.Refreshes all items of the component after setting the sorting, i.e. runs
DataView.refreshAll()
.Specified by:
setSortOrder
in interfaceListDataView<T,
AbstractListDataView<T>> Type Parameters:
V1
- the provided value typeParameters:
valueProvider
- the value provider that defines the property do sort by, notnull
sortDirection
- the sort direction to use, notnull
Returns:
ListDataView instance
See Also:
-
addSortOrder
public <V1 extends Comparable<? super V1>> AbstractListDataView<T> addSortOrder(ValueProvider<T, V1> valueProvider, SortDirection sortDirection) Description copied from interface:
ListDataView
Adds a property and direction to the default sorting. If no default sorting has been defined, then the provided sort order will be used as the default sorting. If a default sorting has been defined, then the provided sort order will be used to determine the ordering of items that are considered equal by the previously defined default sorting.
This sort order is bound to the component. Thus, any other component using the same
DataProvider
object would not be affected by setting a sort sort through data view of another component. A sorting set by this method won't be retained when a newDataProvider
is set to the component.Refreshes all items of the component after adding the sorting, i.e. runs
DataView.refreshAll()
.Specified by:
addSortOrder
in interfaceListDataView<T,
AbstractListDataView<T>> Type Parameters:
V1
- the provided value typeParameters:
valueProvider
- the value provider that defines the property do sort by, notnull
sortDirection
- the sort direction to use, notnull
Returns:
ListDataView instance
See Also:
-
contains
Description copied from interface:
ListDataView
Check if item is present in the currently filtered data set.
By default,
equals
method implementation of the item is used for identity check. If a custom data provider is used, then theDataProvider.getId(Object)
method is used instead. Item's custom identity can be set up with aDataView.setIdentifierProvider(IdentifierProvider)
.Specified by:
contains
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
item
- item to search forReturns:
true
if item is found in filtered data setSee Also:
-
getSupportedDataProviderType
Description copied from class:
AbstractDataView
Returns supported
DataProvider
type for thisDataView
.Specified by:
getSupportedDataProviderType
in classAbstractDataView<T>
Returns:
supported data provider type
-
getDataProvider
-
addItem
Description copied from interface:
ListDataView
Adds an item to the data list if it is not already present.
The backing
List
must be mutable to use this method. Immutable data structure will throw an exception.Refreshes all items of the component after adding the item, i.e. runs
DataView.refreshAll()
.Specified by:
addItem
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
item
- item to addReturns:
this ListDataView instance
See Also:
-
addItems
Description copied from interface:
ListDataView
Adds multiple items to the data list.
The backing
List
must be mutable to use this method. Immutable data structure will throw an exception.Any items that already present in the data provider are moved to the end.
Refreshes all items of the component after adding the items, i.e. runs
DataView.refreshAll()
.Specified by:
addItems
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
items
- collection of item to addReturns:
this ListDataView instance
See Also:
-
addItemAfter
Description copied from interface:
ListDataView
Adds an item after the given target item.
The backing
List
must be mutable to use this method. Immutable data structure will throw an exception.If the item is already present in the data provider, then it is moved.
Refreshes all items of the component after adding the item, i.e. runs
DataView.refreshAll()
.Note! Item is added to the unfiltered and unsorted List.
Specified by:
addItemAfter
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
item
- item to addafter
- item after which to add the item atReturns:
this ListDataView instance
See Also:
-
addItemBefore
Description copied from interface:
ListDataView
Adds an item before the given target item.
The backing
List
must be mutable to use this method. Immutable data structure will throw an exception.If the item is already present in the data provider, then it is moved.
Refreshes all items of the component after adding the item, i.e. runs
DataView.refreshAll()
.Note! Item is added to the unfiltered and unsorted List.
Specified by:
addItemBefore
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
item
- item to addbefore
- item before which to add the item atReturns:
this ListDataView instance
See Also:
-
addItemsAfter
Description copied from interface:
ListDataView
Adds multiple items after the given target item. The full collection is added in order after the target.
The backing
List
must be mutable to use this method. Immutable data structure will throw an exception. Any items that already present in the data provider are moved.Refreshes all items of the component after adding the item, i.e. runs
DataView.refreshAll()
.Note! Item is added to the unfiltered and unsorted List.
Specified by:
addItemsAfter
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
items
- collection of items to addafter
- item after which to add the item atReturns:
this ListDataView instance
See Also:
-
addItemsBefore
Description copied from interface:
ListDataView
Adds multiple items before the given target item. The full collection is added in order before the target.
The backing
List
must be mutable to use this method. Immutable data structure will throw an exception.Any items that already present in the data provider are moved.
Refreshes all items of the component after adding the item, i.e. runs
DataView.refreshAll()
.Note! Item is added to the unfiltered and unsorted List.
Specified by:
addItemsBefore
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
items
- collection of items to addbefore
- item before which to add the item atReturns:
this ListDataView instance
See Also:
-
removeItem
Description copied from interface:
ListDataView
Remove an item from the data list.
The backing
List
must be mutable to use this method. Immutable data structure will throw an exception.Refreshes all items of the component after removing the item, i.e. runs
DataView.refreshAll()
.Specified by:
removeItem
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
item
- item to removeReturns:
this ListDataView instance
See Also:
-
removeItems
Description copied from interface:
ListDataView
Remove multiple items from the data list.
The backing
List
must be mutable to use this method. Immutable data structure will throw an exception.Specified by:
removeItems
in interfaceListDataView<T,
AbstractListDataView<T>> Parameters:
items
- collection of items to removeReturns:
this ListDataView instance
See Also:
-
validateItemIndex
protected void validateItemIndex(int itemIndex) Validate that index is inside bounds of the data available.
Parameters:
itemIndex
- item index to validate
-