Class TreeData<T>
java.lang.Object
com.vaadin.flow.data.provider.hierarchy.TreeData<T>
- Type Parameters:
T
- data type
- All Implemented Interfaces:
Serializable
Represents hierarchical data.
Typically used as a backing data source for TreeDataProvider
.
- Since:
- 1.2
- Author:
- Vaadin Ltd
- See Also:
-
Constructor Summary
ConstructorDescriptionTreeData()
Creates an initially empty hierarchical data representation to which items can be added or removed. -
Method Summary
Modifier and TypeMethodDescriptionAdds a data item as a child ofparent
.addItems
(Collection<T> rootItems, ValueProvider<T, Collection<T>> childItemProvider) Adds the given items as root items and uses the given value provider to recursively populate children of the root items.Adds the given items as root items and uses the given value provider to recursively populate children of the root items.addItems
(T parent, Collection<T> items) Adds a list of data items as children ofparent
.Adds data items contained in a stream as children ofparent
.Adds a list of data items as children ofparent
.addRootItems
(Collection<T> items) Adds the items of the given collection as root items to this structure.addRootItems
(Stream<T> items) Adds the items of the given stream as root items to this structure.addRootItems
(T... items) Adds the items as root items to this structure.clear()
Clear all items from this structure.boolean
Check whether the given item is in this hierarchy.getChildren
(T item) Get the immediate child items for the given item.Get the parent item for the given item.Gets the root items of this structure.void
moveAfterSibling
(T item, T sibling) Moves an item to the position immediately after a sibling item.removeItem
(T item) Remove a given item from this structure.void
Moves an item to become a child of the given parent item.
-
Constructor Details
-
TreeData
public TreeData()Creates an initially empty hierarchical data representation to which items can be added or removed.
-
-
Method Details
-
addRootItems
Adds the items as root items to this structure.- Parameters:
items
- the items to add- Returns:
- this
- Throws:
IllegalArgumentException
- if any of the given items have already been added to this structureNullPointerException
- if any of the items are {code null}
-
addRootItems
Adds the items of the given collection as root items to this structure.- Parameters:
items
- the collection of items to add- Returns:
- this
- Throws:
IllegalArgumentException
- if any of the given items have already been added to this structureNullPointerException
- if any of the items are {code null}
-
addRootItems
Adds the items of the given stream as root items to this structure.- Parameters:
items
- the stream of root items to add- Returns:
- this
- Throws:
IllegalArgumentException
- if any of the given items have already been added to this structureNullPointerException
- if any of the items are {code null}
-
addItem
Adds a data item as a child ofparent
. Call withnull
as parent to add a root level item. The given parent item must already exist in this structure, and an item can only be added to this structure once.- Parameters:
parent
- the parent item for which the items are added as childrenitem
- the item to add- Returns:
- this
- Throws:
IllegalArgumentException
- if parent is not null and not already added to this structureIllegalArgumentException
- if the item has already been added to this structureNullPointerException
- if item is null
-
addItems
Adds a list of data items as children ofparent
. Call withnull
as parent to add root level items. The given parent item must already exist in this structure, and an item can only be added to this structure once.- Parameters:
parent
- the parent item for which the items are added as childrenitems
- the list of items to add- Returns:
- this
- Throws:
IllegalArgumentException
- if parent is not null and not already added to this structureIllegalArgumentException
- if any of the given items have already been added to this structureNullPointerException
- if any of the items are null
-
addItems
Adds a list of data items as children ofparent
. Call withnull
as parent to add root level items. The given parent item must already exist in this structure, and an item can only be added to this structure once.- Parameters:
parent
- the parent item for which the items are added as childrenitems
- the collection of items to add- Returns:
- this
- Throws:
IllegalArgumentException
- if parent is not null and not already added to this structureIllegalArgumentException
- if any of the given items have already been added to this structureNullPointerException
- if any of the items are null
-
addItems
Adds data items contained in a stream as children ofparent
. Call withnull
as parent to add root level items. The given parent item must already exist in this structure, and an item can only be added to this structure once.- Parameters:
parent
- the parent item for which the items are added as childrenitems
- stream of items to add- Returns:
- this
- Throws:
IllegalArgumentException
- if parent is not null and not already added to this structureIllegalArgumentException
- if any of the given items have already been added to this structureNullPointerException
- if any of the items are null
-
addItems
public TreeData<T> addItems(Collection<T> rootItems, ValueProvider<T, Collection<T>> childItemProvider) Adds the given items as root items and uses the given value provider to recursively populate children of the root items.- Parameters:
rootItems
- the root items to addchildItemProvider
- the value provider used to recursively populate this TreeData from the given root items- Returns:
- this
-
addItems
Adds the given items as root items and uses the given value provider to recursively populate children of the root items.- Parameters:
rootItems
- the root items to addchildItemProvider
- the value provider used to recursively populate this TreeData from the given root items- Returns:
- this
-
removeItem
Remove a given item from this structure. Additionally, this will recursively remove any descendants of the item.- Parameters:
item
- the item to remove, or null to clear all data- Returns:
- this
- Throws:
IllegalArgumentException
- if the item does not exist in this structure
-
clear
Clear all items from this structure. Shorthand for callingremoveItem(Object)
with null.- Returns:
- this
-
getRootItems
Gets the root items of this structure.- Returns:
- an unmodifiable list of root items of this structure
-
getChildren
Get the immediate child items for the given item.- Parameters:
item
- the item for which to retrieve child items for, null to retrieve all root items- Returns:
- an unmodifiable list of child items for the given item
- Throws:
IllegalArgumentException
- if the item does not exist in this structure
-
getParent
Get 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
null
if the item is a root item. - Throws:
IllegalArgumentException
- if the item does not exist in this structure
-
setParent
Moves an item to become a child of the given parent item. The new parent item must exist in the hierarchy. Setting the parent tonull
makes the item a root item. After making changes to the tree data,AbstractDataProvider.refreshAll()
should be called.- Parameters:
item
- the item to be set as the child ofparent
parent
- the item to be set as parent ornull
to set the item as root
-
moveAfterSibling
Moves an item to the position immediately after a sibling item. The two items must have the same parent. After making changes to the tree data,AbstractDataProvider.refreshAll()
should be called.- Parameters:
item
- the item to be movedsibling
- the item after which the moved item will be located, ornull
to move item to first position
-
contains
Check whether the given item is in this hierarchy.- Parameters:
item
- the item to check- Returns:
true
if the item is in this hierarchy,false
if not
-