com.vaadin.flow.data.provider.hierarchy.
Interface HierarchicalDataProvider<T,F>
-
Type Parameters:
T
- data typeF
- filter typeAll Superinterfaces:
DataProvider<T,F>
,Serializable
All Known Subinterfaces:
BackEndHierarchicalDataProvider<T,F>
,HierarchicalConfigurableFilterDataProvider<T,Q,C>
All Known Implementing Classes:
AbstractBackEndHierarchicalDataProvider
,AbstractHierarchicalDataProvider
,TreeDataProvider
public interface HierarchicalDataProvider<T,F> extends DataProvider<T,F>
A common interface for fetching hierarchical data from a data source, such as an in-memory collection or a backend database.
Since:
1.2
Author:
Vaadin Ltd
-
-
Method Summary
All Methods Modifier and Type Method Description default Stream<T>
fetch(Query<T,F> query)
Fetches data from this HierarchicalDataProvider using given
query
.Stream<T>
fetchChildren(HierarchicalQuery<T,F> query)
Fetches data from this HierarchicalDataProvider using given
query
.int
getChildCount(HierarchicalQuery<T,F> query)
Get the number of immediate child data items for the parent item returned by a given query.
boolean
hasChildren(T item)
Check whether a given item has any children associated with it.
default int
size(Query<T,F> query)
Get the number of immediate child data items for the parent item returned by a given query.
default HierarchicalConfigurableFilterDataProvider<T,Void,F>
withConfigurableFilter()
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 Detail
-
size
default int size(Query<T,F> query)
Get the number of immediate child data items for the parent item returned by a given query.
Specified by:
size
in interfaceDataProvider<T,F>
Parameters:
query
- given query to request the count forReturns:
the count of child data items for the data item
HierarchicalQuery.getParent()
Throws:
IllegalArgumentException
- if the query is not of type HierarchicalQuery
-
fetch
default Stream<T> fetch(Query<T,F> query)
Fetches data from this HierarchicalDataProvider using given
query
. Only the immediate children ofHierarchicalQuery.getParent()
will be returned.Specified by:
fetch
in interfaceDataProvider<T,F>
Parameters:
query
- given query to request data withReturns:
a stream of data objects resulting from the query
Throws:
IllegalArgumentException
- if the query is not of type HierarchicalQuery
-
getChildCount
int getChildCount(HierarchicalQuery<T,F> query)
Get the number of immediate child data items for the parent item returned by a given query.
Parameters:
query
- given query to request the count forReturns:
the count of child data items for the data item
HierarchicalQuery.getParent()
-
fetchChildren
Stream<T> fetchChildren(HierarchicalQuery<T,F> query)
Fetches data from this HierarchicalDataProvider using given
query
. Only the immediate children ofHierarchicalQuery.getParent()
will be returned.Parameters:
query
- given query to request data withReturns:
a stream of data objects resulting from the query
-
hasChildren
boolean hasChildren(T item)
Check whether a given item has any children associated with it.
Parameters:
item
- the item to check for childrenReturns:
whether the given item has children
-
withConfigurableFilter
default <Q,C> HierarchicalConfigurableFilterDataProvider<T,Q,C> withConfigurableFilter(SerializableBiFunction<Q,C,F> filterCombiner)
Description copied from interface:
DataProvider
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.
Specified by:
withConfigurableFilter
in interfaceDataProvider<T,F>
Type Parameters:
Q
- the query filter typeC
- the configurable filter typeParameters:
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:
DataProvider.withConfigurableFilter()
,ConfigurableFilterDataProvider.setFilter(Object)
-
withConvertedFilter
default <C> HierarchicalDataProvider<T,C> withConvertedFilter(SerializableFunction<C,F> filterConverter)
Description copied from interface:
DataProvider
Wraps 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:
withConvertedFilter
in interfaceDataProvider<T,F>
Type Parameters:
C
- the filter type that the wrapped data provider accepts; typically provided by a ComponentParameters:
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
default HierarchicalConfigurableFilterDataProvider<T,Void,F> withConfigurableFilter()
Description copied from interface:
DataProvider
Wraps this data provider to create a data provider that supports programmatically setting a filter but no filtering through the query.
Specified by:
withConfigurableFilter
in interfaceDataProvider<T,F>
Returns:
a data provider with a configurable filter, not
null
See Also:
DataProvider.withConfigurableFilter(SerializableBiFunction)
,ConfigurableFilterDataProvider.setFilter(Object)
-
-