com.vaadin.data.provider.
Class TreeDataProvider<T>
- java.lang.Object
-
- com.vaadin.data.provider.AbstractDataProvider<T,F>
-
- com.vaadin.data.provider.AbstractHierarchicalDataProvider<T,SerializablePredicate<T>>
-
- com.vaadin.data.provider.TreeDataProvider<T>
-
Type Parameters:
T
- data typeAll Implemented Interfaces:
ConfigurableFilterDataProvider<T,SerializablePredicate<T>,SerializablePredicate<T>>
,DataProvider<T,SerializablePredicate<T>>
,HierarchicalDataProvider<T,SerializablePredicate<T>>
,InMemoryDataProvider<T>
,Serializable
public class TreeDataProvider<T> extends AbstractHierarchicalDataProvider<T,SerializablePredicate<T>> implements InMemoryDataProvider<T>
An in-memory data provider for listing components that display hierarchical data. Uses an instance of
TreeData
as its source of data.Since:
8.1
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor Description TreeDataProvider(TreeData<T> treeData)
Constructs a new TreeDataProvider.
-
Method Summary
All Methods Modifier and Type Method Description Stream<T>
fetchChildren(HierarchicalQuery<T,SerializablePredicate<T>> query)
Fetches data from this HierarchicalDataProvider using given
query
.int
getChildCount(HierarchicalQuery<T,SerializablePredicate<T>> query)
Get the number of immediate child data items for the parent item returned by a given query.
SerializablePredicate<T>
getFilter()
Gets the current filter of this data provider.
SerializableComparator<T>
getSortComparator()
Gets the current sort comparator of this data provider.
TreeData<T>
getTreeData()
Return the underlying hierarchical data of this provider.
boolean
hasChildren(T item)
Check whether a given item has any children associated with it.
void
setFilter(SerializablePredicate<T> filter)
Sets a filter to be applied to all queries.
void
setSortComparator(SerializableComparator<T> comparator)
Sets the comparator to use as the default sorting for this data provider.
<C> DataProvider<T,C>
withConvertedFilter(SerializableFunction<C,SerializablePredicate<T>> filterConverter)
Wraps this data provider to create a data provider that uses a different filter type.
-
Methods inherited from class com.vaadin.data.provider.AbstractDataProvider
addDataProviderListener, addListener, fireEvent, refreshAll, refreshItem
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.data.provider.DataProvider
addDataProviderListener, getId, refreshAll, refreshItem, withConfigurableFilter, withConfigurableFilter
-
Methods inherited from interface com.vaadin.data.provider.HierarchicalDataProvider
fetch, size
-
Methods inherited from interface com.vaadin.data.provider.InMemoryDataProvider
addFilter, addFilter, addFilterByValue, addSortComparator, addSortOrder, clearFilters, filteringBy, filteringBy, filteringByEquals, filteringByPrefix, filteringByPrefix, filteringBySubstring, filteringBySubstring, isInMemory, setFilter, setFilterByValue, setSortOrder
-
-
-
-
Method Detail
-
getTreeData
public TreeData<T> getTreeData()
Return the underlying hierarchical data of this provider.
Returns:
the underlying data of this provider
-
hasChildren
public boolean hasChildren(T item)
Description copied from interface:
HierarchicalDataProvider
Check whether a given item has any children associated with it.
Specified by:
hasChildren
in interfaceHierarchicalDataProvider<T,SerializablePredicate<T>>
Parameters:
item
- the item to check for childrenReturns:
whether the given item has children
-
getChildCount
public int getChildCount(HierarchicalQuery<T,SerializablePredicate<T>> query)
Description copied from interface:
HierarchicalDataProvider
Get the number of immediate child data items for the parent item returned by a given query.
Specified by:
getChildCount
in interfaceHierarchicalDataProvider<T,SerializablePredicate<T>>
Parameters:
query
- given query to request the count forReturns:
the count of child data items for the data item
HierarchicalQuery.getParent()
-
fetchChildren
public Stream<T> fetchChildren(HierarchicalQuery<T,SerializablePredicate<T>> query)
Description copied from interface:
HierarchicalDataProvider
Fetches data from this HierarchicalDataProvider using given
query
. Only the immediate children ofHierarchicalQuery.getParent()
will be returned.NOTE: If your data request is likely to involve I/O channels, see
DataProvider.fetch(Query)
for instructions on how to handle the stream without risking resource leaks.Specified by:
fetchChildren
in interfaceHierarchicalDataProvider<T,SerializablePredicate<T>>
Parameters:
query
- given query to request data withReturns:
a stream of data objects resulting from the query
-
getFilter
public SerializablePredicate<T> getFilter()
Description copied from interface:
InMemoryDataProvider
Gets the current filter of this data provider.
Specified by:
getFilter
in interfaceInMemoryDataProvider<T>
Returns:
the filter of this data provider
-
setFilter
public void setFilter(SerializablePredicate<T> filter)
Description copied from interface:
InMemoryDataProvider
Sets a filter to be applied to all queries. The filter replaces any filter that has been set or added previously.
Specified by:
setFilter
in interfaceConfigurableFilterDataProvider<T,SerializablePredicate<T>,SerializablePredicate<T>>
Specified by:
setFilter
in interfaceInMemoryDataProvider<T>
Parameters:
filter
- the filter to set, ornull
to remove any set filtersSee Also:
InMemoryDataProvider.setFilter(ValueProvider, SerializablePredicate)
,InMemoryDataProvider.setFilterByValue(ValueProvider, Object)
,InMemoryDataProvider.addFilter(SerializablePredicate)
-
getSortComparator
public SerializableComparator<T> getSortComparator()
Description copied from interface:
InMemoryDataProvider
Gets the current sort comparator of this data provider.
Specified by:
getSortComparator
in interfaceInMemoryDataProvider<T>
Returns:
the sort comparator of this data provider
-
setSortComparator
public void setSortComparator(SerializableComparator<T> comparator)
Description copied from interface:
InMemoryDataProvider
Sets the comparator to use as the default sorting for this data provider. This overrides the sorting set by any other method that manipulates the default sorting of this data provider.
The default sorting is used if the query defines no sorting. The default sorting is also used to determine the ordering of items that are considered equal by the sorting defined in the query.
Specified by:
setSortComparator
in interfaceInMemoryDataProvider<T>
Parameters:
comparator
- a comparator to use, ornull
to clear any previously set sort orderSee Also:
InMemoryDataProvider.setSortOrder(ValueProvider, SortDirection)
,InMemoryDataProvider.addSortComparator(SerializableComparator)
-
withConvertedFilter
public <C> DataProvider<T,C> withConvertedFilter(SerializableFunction<C,SerializablePredicate<T>> 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 -> { SerializablePredicate<Person> predicate = person -> person .getName().startsWith(filterText); return predicate; }); comboBox.setDataProvider(wrappedProvider);
Specified by:
withConvertedFilter
in interfaceDataProvider<T,SerializablePredicate<T>>
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
-
-