com.vaadin.flow.data.provider.hierarchy.
Interface HasHierarchicalDataProvider<T>
-
Type Parameters:
T
- the item data typeAll Superinterfaces:
All Known Implementing Classes:
public interface HasHierarchicalDataProvider<T> extends Serializable
A generic interface for hierarchical listing components that use a data provider for showing hierarchical data.
Since:
1.2
Author:
Vaadin Ltd
-
-
Method Summary
All Methods Modifier and Type Method Description HierarchicalDataProvider<T,SerializablePredicate<T>>
getDataProvider()
default TreeData<T>
getTreeData()
Gets the backing
TreeData
instance of the data provider, if the data provider is aTreeDataProvider
.void
setDataProvider(DataProvider<T,?> dataProvider)
Deprecated.
UsesetDataProvider(HierarchicalDataProvider)
instead as the data should be hierarchicalvoid
setDataProvider(HierarchicalDataProvider<T,?> hierarchicalDataProvider)
Sets the hierarchical data provider for this listing.
default void
setItems(Collection<T> rootItems, ValueProvider<T,Collection<T>> childItemProvider)
Sets the root data items of this component provided as a collection and recursively populates them with child items with the given value provider.
default void
setItems(Stream<T> rootItems, ValueProvider<T,Stream<T>> childItemProvider)
Sets the root data items of this component provided as a stream and recursively populates them with child items with the given value provider.
default void
setTreeData(TreeData<T> treeData)
Sets a new
TreeDataProvider
wrapping the givenTreeData
.
-
-
-
Method Detail
-
getDataProvider
HierarchicalDataProvider<T,SerializablePredicate<T>> getDataProvider()
-
setTreeData
default void setTreeData(TreeData<T> treeData)
Sets a new
TreeDataProvider
wrapping the givenTreeData
.Parameters:
treeData
- the tree data to set
-
getTreeData
default TreeData<T> getTreeData()
Gets the backing
TreeData
instance of the data provider, if the data provider is aTreeDataProvider
.Returns:
the TreeData instance used by the data provider
Throws:
IllegalStateException
- if the type of the data provider is notTreeDataProvider
-
setItems
default void setItems(Collection<T> rootItems, ValueProvider<T,Collection<T>> childItemProvider)
Sets the root data items of this component provided as a collection and recursively populates them with child items with the given value provider.
The provided items are wrapped into a
TreeDataProvider
backed by a flatTreeData
structure. The data provider instance is used as a parameter for thesetDataProvider(DataProvider)
method. It means that the items collection can be accessed later on viagetTreeData()
:Collection<Person> grandParents = getGrandParents(); HasHierarchicalDataProvider<Person> treeGrid = new TreeGrid<>(); treeGrid.setItems(grandParents, Person::getChildren); ... TreeData<Person> data = treeGrid.getTreeData();
The returned
TreeData
instance may be used as-is to add, remove or modify items in the hierarchy. These modifications to the object are not automatically reflected back to the TreeGrid. Items modified should be refreshed withDataProvider.refreshItem(Object)
and when adding or removing itemsDataProvider.refreshAll()
should be called.Parameters:
rootItems
- the root items to display, notnull
childItemProvider
- the value provider used to recursively populate the given root items with child items, notnull
-
setItems
default void setItems(Stream<T> rootItems, ValueProvider<T,Stream<T>> childItemProvider)
Sets the root data items of this component provided as a stream and recursively populates them with child items with the given value provider.
The provided items are wrapped into a
TreeDataProvider
backed by a flatTreeData
structure. The data provider instance is used as a parameter for thesetDataProvider(DataProvider)
method. It means that the items collection can be accessed later on viagetTreeData()
:Stream<Person> grandParents = getGrandParents(); HasHierarchicalDataProvider<Person> treeGrid = new TreeGrid<>(); treeGrid.setItems(grandParents, Person::getChildren); ... TreeData<Person> data = treeGrid.getTreeData();
The returned
TreeData
instance may be used as-is to add, remove or modify items in the hierarchy. These modifications to the object are not automatically reflected back to the TreeGrid. Items modified should be refreshed withDataProvider.refreshItem(Object)
and when adding or removing itemsDataProvider.refreshAll()
should be called.Parameters:
rootItems
- the root items to display, notnull
childItemProvider
- the value provider used to recursively populate the given root items with child items, notnull
-
setDataProvider
@Deprecated void setDataProvider(DataProvider<T,?> dataProvider)
Deprecated.UsesetDataProvider(HierarchicalDataProvider)
instead as the data should be hierarchicalSets the data provider for this listing. The data provider is queried for displayed items as needed.
NOTE: This method is here for backwards compatibility, but the implementation for it will most likely throw if the data provider is not a
HierarchicalDataProvider
.Parameters:
dataProvider
- the data provider, not null
-
setDataProvider
void setDataProvider(HierarchicalDataProvider<T,?> hierarchicalDataProvider)
Sets the hierarchical data provider for this listing. The data provider provides the items and the hierarchy as needed.
Parameters:
hierarchicalDataProvider
- the hierarchical data provider to use, notnull
-
-