Interface HierarchicalDataProvider<T,F>
- Type Parameters:
T- data typeF- filter type
- All Superinterfaces:
DataProvider<T,,F> Serializable
- All Known Subinterfaces:
BackEndHierarchicalDataProvider<T,,F> HierarchicalConfigurableFilterDataProvider<T,Q, C>
- All Known Implementing Classes:
AbstractBackEndHierarchicalDataProvider,AbstractHierarchicalDataProvider,TreeDataProvider
HierarchicalDataProvider.HierarchyFormat.NESTED and
HierarchicalDataProvider.HierarchyFormat.FLATTENED.- Since:
- 1.2
- Author:
- Vaadin Ltd
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionFetches children based on the given hierarchical query.fetchChildren(HierarchicalQuery<T, F> query) Fetches children based on the given hierarchical query.intgetChildCount(HierarchicalQuery<T, F> query) Gets the number of children based on the given hierarchical query.default intGets the depth of a given item in the hierarchy, starting from zero (root).Specifies the format in which the data provider returns hierarchical data.default intgetItemIndex(T item, HierarchicalQuery<T, F> query) Gets the index of a given item based on the given hierarchical query.default TGets the parent item for the given item.booleanhasChildren(T item) Check whether a given item has any children associated with it.default intGets the number of children based on the given hierarchical query.default HierarchicalConfigurableFilterDataProvider<T, Void, F> Wraps this data provider to create a data provider that supports programmatically setting a filter but no filtering through the query.default <Q,C> HierarchicalConfigurableFilterDataProvider <T, Q, C> withConfigurableFilter(SerializableBiFunction<Q, C, F> filterCombiner) Wraps this data provider to create a data provider that supports programmatically setting a filter that will be combined with a filter provided through the query.default <C> HierarchicalDataProvider<T, C> withConvertedFilter(SerializableFunction<C, F> filterConverter) Wraps this data provider to create a data provider that uses a different filter type.Methods inherited from interface com.vaadin.flow.data.provider.DataProvider
addDataProviderListener, getId, isInMemory, refreshAll, refreshItem, refreshItem
-
Method Details
-
getHierarchyFormat
Specifies the format in which the data provider returns hierarchical data. The default format isHierarchicalDataProvider.HierarchyFormat.NESTED.The component uses this method to determine how to fetch and render hierarchical data with this data provider.
- Returns:
- the hierarchy format
- Since:
- 25.0
-
size
Gets the number of children based on the given hierarchical query.The behavior of this method depends on the implemented hierarchy format, see
getHierarchyFormat()andgetChildCount(HierarchicalQuery)- Specified by:
sizein interfaceDataProvider<T,F> - Parameters:
query- given query to request the count for- Returns:
- the count of children for the parent item
HierarchicalQuery.getParent()or the root level ifnull - Throws:
IllegalArgumentException- if the query is not of type HierarchicalQuery
-
fetch
Fetches children based on the given hierarchical query.The behavior of this method depends on the implemented hierarchy format, see
getHierarchyFormat()andfetchChildren(HierarchicalQuery)- Specified by:
fetchin interfaceDataProvider<T,F> - Parameters:
query- given query to request data with- Returns:
- a stream of data objects for the
parent itemor the root level if the parent isnull, must not contain null values - Throws:
IllegalArgumentException- if the query is not of type HierarchicalQuery
-
getChildCount
Gets the number of children based on the given hierarchical query.This method must be implemented in accordance with the selected hierarchy type, see
getHierarchyFormat()andHierarchicalDataProvider.HierarchyFormat.- Parameters:
query- given query to request the count for- Returns:
- the count of children for the parent item or the root level if
the parent is
null
-
fetchChildren
Fetches children based on the given hierarchical query.This method must be implemented in accordance with the selected hierarchy type, see
getHierarchyFormat()andHierarchicalDataProvider.HierarchyFormat.- Parameters:
query- given query to request data with- Returns:
- a stream of data objects for the
parent itemor the root level if the parent isnull, must not contain null values
-
hasChildren
Check whether a given item has any children associated with it.- Parameters:
item- the item to check for children- Returns:
- whether the given item has children
-
getParent
Gets the parent item for the given item.- Parameters:
item- the item for which to retrieve the parent item for- Returns:
- parent item for the given item or
nullif the item is a root item - Throws:
UnsupportedOperationException- if not implemented
-
getItemIndex
Gets the index of a given item based on the given hierarchical query.This method must be implemented in accordance with the selected hierarchy type, see
getHierarchyFormat()andHierarchicalDataProvider.HierarchyFormat.- If
HierarchicalDataProvider.HierarchyFormat.FLATTENEDis used, it should be implemented to return the index in the entire flattened tree. - If
HierarchicalDataProvider.HierarchyFormat.NESTEDis used, it should be implemented to return the index within the given parent item.
This method has a default implementation for in-memory data providers.
- Parameters:
item- the item to get the index forquery- given query to request data with- Returns:
- the index of the provided item or -1 if not found
- Throws:
UnsupportedOperationException- if not implemented
- If
-
getDepth
Gets the depth of a given item in the hierarchy, starting from zero (root).This method must be implemented for data providers that implement the flattened hierarchy format, see
getHierarchyFormat()andHierarchicalDataProvider.HierarchyFormat.FLATTENED.- Parameters:
item- the item to get the depth for- Returns:
- the depth of the item in the hierarchy
- Throws:
UnsupportedOperationException- if not implemented
-
withConfigurableFilter
default <Q,C> HierarchicalConfigurableFilterDataProvider<T,Q, withConfigurableFilterC> (SerializableBiFunction<Q, C, F> filterCombiner) Description copied from interface:DataProviderWraps this data provider to create a data provider that supports programmatically setting a filter that will be combined with a filter provided through the query.- Specified by:
withConfigurableFilterin interfaceDataProvider<T,F> - Type Parameters:
Q- the query filter typeC- the configurable filter type- Parameters:
filterCombiner- a callback for combining and the configured filter with the filter from the query to get a filter to pass to the wrapped provider. Either parameter might benull, but the callback will not be invoked at all if both would benull. Notnull.- Returns:
- a data provider with a configurable filter, not
null - See Also:
-
withConvertedFilter
default <C> HierarchicalDataProvider<T,C> withConvertedFilter(SerializableFunction<C, F> filterConverter) Description copied from interface:DataProviderWraps this data provider to create a data provider that uses a different filter type. This can be used for adapting this data provider to a filter type provided by a Component such as ComboBox.For example receiving a String from ComboBox and making a Predicate based on it:
DataProvider<Person, Predicate<Person>> dataProvider; // ComboBox uses String as the filter type DataProvider<Person, String> wrappedProvider = dataProvider .withConvertedFilter(filterText -> { Predicate<Person> predicate = person -> person.getName() .startsWith(filterText); return predicate; }); comboBox.setDataProvider(wrappedProvider);- Specified by:
withConvertedFilterin interfaceDataProvider<T,F> - Type Parameters:
C- the filter type that the wrapped data provider accepts; typically provided by a Component- Parameters:
filterConverter- callback that converts the filter in the query of the wrapped data provider into a filter supported by this data provider. Will only be called if the query contains a filter. Notnull- Returns:
- wrapped data provider, not
null
-
withConfigurableFilter
Description copied from interface:DataProviderWraps this data provider to create a data provider that supports programmatically setting a filter but no filtering through the query.- Specified by:
withConfigurableFilterin interfaceDataProvider<T,F> - Returns:
- a data provider with a configurable filter, not
null - See Also:
-