Class AbstractListDataView<T>
- java.lang.Object
-
- com.vaadin.flow.data.provider.AbstractDataView<T>
-
- com.vaadin.flow.data.provider.AbstractListDataView<T>
-
- Type Parameters:
T- data type
- All Implemented Interfaces:
DataView<T>,ListDataView<T,AbstractListDataView<T>>,Serializable
public abstract class AbstractListDataView<T> extends AbstractDataView<T> implements ListDataView<T,AbstractListDataView<T>>
Abstract list data view implementation which provides common methods for fetching, filtering and sorting in-memory data to allListDataViewsubclasses.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.vaadin.flow.data.provider.AbstractDataView
component, dataProviderSupplier, NULL_IDENTIFIER_ERROR_MESSAGE
-
-
Constructor Summary
Constructors Constructor Description AbstractListDataView(SerializableSupplier<? extends DataProvider<T,?>> dataProviderSupplier, Component component, SerializableBiConsumer<SerializablePredicate<T>,SerializableComparator<T>> filterOrSortingChangedCallback)Creates a new instance ofAbstractListDataViewsubclass and verifies the passed data provider is compatible with this data view implementation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractListDataView<T>addFilter(SerializablePredicate<T> filter)Adds a filter to be applied to all queries.AbstractListDataView<T>addItem(T item)Adds an item to the data list if it is not already present.AbstractListDataView<T>addItemAfter(T item, T after)Adds an item after the given target item.AbstractListDataView<T>addItemBefore(T item, T before)Adds an item before the given target item.AbstractListDataView<T>addItems(Collection<T> items)Adds multiple items to the data list.AbstractListDataView<T>addItemsAfter(Collection<T> items, T after)Adds multiple items after the given target item.AbstractListDataView<T>addItemsBefore(Collection<T> items, T before)Adds multiple items before the given target item.AbstractListDataView<T>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.booleancontains(T item)Check if item is present in the currently filtered data set.protected ListDataProvider<T>getDataProvider()TgetItem(int index)Gets the item at the given index from the data available to the component.intgetItemCount()Get the full item count with filters if any set.Stream<T>getItems()Get the full data available to the component.Optional<T>getNextItem(T item)Gets the item after given item from the filtered and sorted data.Optional<T>getPreviousItem(T item)Gets the item before given item from the filtered and sorted data.protected Class<?>getSupportedDataProviderType()Returns supportedDataProvidertype for thisDataView.AbstractListDataView<T>removeFilters()Removes all in-memory filters set or added.AbstractListDataView<T>removeItem(T item)Remove an item from the data list.AbstractListDataView<T>removeItems(Collection<T> items)Remove multiple items from the data list.AbstractListDataView<T>removeSorting()Removes any default sorting that has been set or added previously.AbstractListDataView<T>setFilter(SerializablePredicate<T> filter)Sets a filter to be applied to the data.AbstractListDataView<T>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 voidvalidateItemIndex(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, refreshAll, refreshItem, setIdentifierProvider, 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, refreshAll, refreshItem, setIdentifierProvider
-
-
-
-
Constructor Detail
-
AbstractListDataView
public AbstractListDataView(SerializableSupplier<? extends DataProvider<T,?>> dataProviderSupplier, Component component, SerializableBiConsumer<SerializablePredicate<T>,SerializableComparator<T>> filterOrSortingChangedCallback)
Creates a new instance ofAbstractListDataViewsubclass 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 Detail
-
getItemCount
public int getItemCount()
Description copied from interface:ListDataViewGet 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 theDataView.addItemCountChangeListener(ComponentEventListener)method instead to get notified when the item count has changed.- Specified by:
getItemCountin interfaceListDataView<T,AbstractListDataView<T>>- Returns:
- filtered item count
- See Also:
DataView.addItemCountChangeListener(ComponentEventListener)
-
getItem
public T getItem(int index)
Description copied from interface:DataViewGets 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
public Stream<T> getItems()
Description copied from interface:DataViewGet the full data available to the component. Data is filtered and sorted the same way as in the component.
-
getNextItem
public Optional<T> getNextItem(T item)
Description copied from interface:ListDataViewGets 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:
getNextItemin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
item- item to get next for- Returns:
- next item if available, else empty optional if item doesn't exist or not in current filtered items
- See Also:
ListDataView.getPreviousItem(Object)
-
getPreviousItem
public Optional<T> getPreviousItem(T item)
Description copied from interface:ListDataViewGets 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:
getPreviousItemin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
item- item to get previous for- Returns:
- previous item if available, else empty optional if item doesn't exist or not in current filtered items
- See Also:
ListDataView.getNextItem(Object)
-
addFilter
public AbstractListDataView<T> addFilter(SerializablePredicate<T> filter)
Description copied from interface:ListDataViewAdds 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
DataProviderobject 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 newDataProvideris set to the component.- Specified by:
addFilterin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
filter- the filter to add, notnull- Returns:
- ListDataView instance
- See Also:
ListDataView.setFilter(SerializablePredicate),ListDataView.removeFilters()
-
removeFilters
public AbstractListDataView<T> removeFilters()
Description copied from interface:ListDataViewRemoves all in-memory filters set or added.- Specified by:
removeFiltersin interfaceListDataView<T,AbstractListDataView<T>>- Returns:
- ListDataView instance
- See Also:
ListDataView.addFilter(SerializablePredicate),ListDataView.setFilter(SerializablePredicate)
-
setFilter
public AbstractListDataView<T> setFilter(SerializablePredicate<T> filter)
Description copied from interface:ListDataViewSets a filter to be applied to the data. The filter replaces any filter that has been set or added previously.nullwill clear all filters.This filter is bound to the component. Thus, any other component using the same
DataProviderobject 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 newDataProvideris set to the component.- Specified by:
setFilterin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
filter- filter to be set, ornullto clear any previously set filters- Returns:
- ListDataView instance
- See Also:
ListDataView.addFilter(SerializablePredicate),ListDataView.removeFilters()
-
setSortComparator
public AbstractListDataView<T> setSortComparator(SerializableComparator<T> sortComparator)
Description copied from interface:ListDataViewSets 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
DataProviderobject 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 newDataProvideris set to the component.- Specified by:
setSortComparatorin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
sortComparator- a comparator to use, ornullto clear any previously set sort order- Returns:
- ListDataView instance
- See Also:
ListDataView.addSortComparator(SerializableComparator)
-
addSortComparator
public AbstractListDataView<T> addSortComparator(SerializableComparator<T> sortComparator)
Description copied from interface:ListDataViewAdds 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
DataProviderobject 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 newDataProvideris set to the component.- Specified by:
addSortComparatorin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
sortComparator- a comparator to add, notnull- Returns:
- ListDataView instance
- See Also:
ListDataView.setSortComparator(SerializableComparator)
-
removeSorting
public AbstractListDataView<T> removeSorting()
Description copied from interface:ListDataViewRemoves any default sorting that has been set or added previously.Any other component using the same
DataProviderobject would not be affected by removing default sorting through data view of another component.- Specified by:
removeSortingin interfaceListDataView<T,AbstractListDataView<T>>- Returns:
- ListDataView instance
- See Also:
ListDataView.setSortComparator(SerializableComparator),ListDataView.addSortComparator(SerializableComparator)
-
setSortOrder
public <V1 extends Comparable<? super V1>> AbstractListDataView<T> setSortOrder(ValueProvider<T,V1> valueProvider, SortDirection sortDirection)
Description copied from interface:ListDataViewSets 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 thisDataProvider.This sort order is bound to the component. Thus, any other component using the same
DataProviderobject 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 newDataProvideris set to the component.- Specified by:
setSortOrderin interfaceListDataView<T,AbstractListDataView<T>>- Type Parameters:
V1- the provided value type- Parameters:
valueProvider- the value provider that defines the property do sort by, notnullsortDirection- the sort direction to use, notnull- Returns:
- ListDataView instance
- See Also:
ListDataView.addSortOrder(ValueProvider, SortDirection)
-
addSortOrder
public <V1 extends Comparable<? super V1>> AbstractListDataView<T> addSortOrder(ValueProvider<T,V1> valueProvider, SortDirection sortDirection)
Description copied from interface:ListDataViewAdds 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
DataProviderobject 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 newDataProvideris set to the component.- Specified by:
addSortOrderin interfaceListDataView<T,AbstractListDataView<T>>- Type Parameters:
V1- the provided value type- Parameters:
valueProvider- the value provider that defines the property do sort by, notnullsortDirection- the sort direction to use, notnull- Returns:
- ListDataView instance
- See Also:
ListDataView.setSortOrder(ValueProvider, SortDirection)
-
contains
public boolean contains(T item)
Description copied from interface:ListDataViewCheck if item is present in the currently filtered data set.By default,
equalsmethod 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:
containsin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
item- item to search for- Returns:
trueif item is found in filtered data set- See Also:
DataView.setIdentifierProvider(IdentifierProvider)
-
getSupportedDataProviderType
protected Class<?> getSupportedDataProviderType()
Description copied from class:AbstractDataViewReturns supportedDataProvidertype for thisDataView.- Specified by:
getSupportedDataProviderTypein classAbstractDataView<T>- Returns:
- supported data provider type
-
getDataProvider
protected ListDataProvider<T> getDataProvider()
-
addItem
public AbstractListDataView<T> addItem(T item)
Description copied from interface:ListDataViewAdds an item to the data list if it is not already present.The backing
Listmust be mutable to use this method. Immutable data structure will throw an exception.- Specified by:
addItemin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
item- item to add- Returns:
- this ListDataView instance
- See Also:
ListDataView.addItemBefore(Object, Object),ListDataView.addItemAfter(Object, Object),ListDataView.removeItem(Object)
-
addItems
public AbstractListDataView<T> addItems(Collection<T> items)
Description copied from interface:ListDataViewAdds multiple items to the data list.The backing
Listmust 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.
- Specified by:
addItemsin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
items- collection of item to add- Returns:
- this ListDataView instance
- See Also:
ListDataView.removeItems(Collection),ListDataView.addItemsBefore(Collection, Object),ListDataView.addItemsAfter(Collection, Object)
-
addItemAfter
public AbstractListDataView<T> addItemAfter(T item, T after)
Description copied from interface:ListDataViewAdds an item after the given target item.The backing
Listmust 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.
Note! Item is added to the unfiltered and unsorted List.
- Specified by:
addItemAfterin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
item- item to addafter- item after which to add the item at- Returns:
- this ListDataView instance
- See Also:
ListDataView.addItem(Object),ListDataView.addItemBefore(Object, Object)
-
addItemBefore
public AbstractListDataView<T> addItemBefore(T item, T before)
Description copied from interface:ListDataViewAdds an item before the given target item.The backing
Listmust 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.
Note! Item is added to the unfiltered and unsorted List.
- Specified by:
addItemBeforein interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
item- item to addbefore- item before which to add the item at- Returns:
- this ListDataView instance
- See Also:
ListDataView.addItem(Object),ListDataView.addItemAfter(Object, Object)
-
addItemsAfter
public AbstractListDataView<T> addItemsAfter(Collection<T> items, T after)
Description copied from interface:ListDataViewAdds multiple items after the given target item. The full collection is added in order after the target.The backing
Listmust be mutable to use this method. Immutable data structure will throw an exception. Any items that already present in the data provider are moved.Note! Item is added to the unfiltered and unsorted List.
- Specified by:
addItemsAfterin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
items- collection of items to addafter- item after which to add the item at- Returns:
- this ListDataView instance
- See Also:
ListDataView.addItems(Collection),ListDataView.addItemsBefore(Collection, Object)
-
addItemsBefore
public AbstractListDataView<T> addItemsBefore(Collection<T> items, T before)
Description copied from interface:ListDataViewAdds multiple items before the given target item. The full collection is added in order before the target.The backing
Listmust be mutable to use this method. Immutable data structure will throw an exception.Any items that already present in the data provider are moved.
Note! Item is added to the unfiltered and unsorted List.
- Specified by:
addItemsBeforein interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
items- collection of items to addbefore- item before which to add the item at- Returns:
- this ListDataView instance
- See Also:
ListDataView.addItems(Collection),ListDataView.addItemsAfter(Collection, Object)
-
removeItem
public AbstractListDataView<T> removeItem(T item)
Description copied from interface:ListDataViewRemove an item from the data list.The backing
Listmust be mutable to use this method. Immutable data structure will throw an exception.- Specified by:
removeItemin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
item- item to remove- Returns:
- this ListDataView instance
- See Also:
ListDataView.addItem(Object),ListDataView.removeItems(Collection)
-
removeItems
public AbstractListDataView<T> removeItems(Collection<T> items)
Description copied from interface:ListDataViewRemove multiple items from the data list.The backing
Listmust be mutable to use this method. Immutable data structure will throw an exception.- Specified by:
removeItemsin interfaceListDataView<T,AbstractListDataView<T>>- Parameters:
items- collection of items to remove- Returns:
- this ListDataView instance
- See Also:
ListDataView.removeItem(Object),ListDataView.removeItems(Collection)
-
validateItemIndex
protected void validateItemIndex(int itemIndex)
Validate that index is inside bounds of the data available.- Parameters:
itemIndex- item index to validate
-
-