com.vaadin.flow.data.provider.hierarchy.
Class TreeData<T>
- java.lang.Object
-
- com.vaadin.flow.data.provider.hierarchy.TreeData<T>
-
Type Parameters:
T
- data typeAll Implemented Interfaces:
public class TreeData<T> extends Object implements Serializable
Class for representing hierarchical data.
Typically used as a backing data source for
TreeDataProvider
.Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor and Description TreeData()
Creates an initially empty hierarchical data representation to which items can be added or removed.
-
Method Summary
All Methods Modifier and Type Method and Description TreeData<T>
addItem(T parent, T item)
Adds a data item as a child of
parent
.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.
TreeData<T>
addItems(Stream<T> rootItems, ValueProvider<T,Stream<T>> childItemProvider)
Adds the given items as root items and uses the given value provider to recursively populate children of the root items.
TreeData<T>
addItems(T parent, Collection<T> items)
Adds a list of data items as children of
parent
.TreeData<T>
addItems(T parent, Stream<T> items)
Adds data items contained in a stream as children of
parent
.TreeData<T>
addItems(T parent, T... items)
Adds a list of data items as children of
parent
.TreeData<T>
addRootItems(Collection<T> items)
Adds the items of the given collection as root items to this structure.
TreeData<T>
addRootItems(Stream<T> items)
Adds the items of the given stream as root items to this structure.
TreeData<T>
addRootItems(T... items)
Adds the items as root items to this structure.
TreeData<T>
clear()
Clear all items from this structure.
boolean
contains(T item)
Check whether the given item is in this hierarchy.
List<T>
getChildren(T item)
Get the immediate child items for the given item.
T
getParent(T item)
Get the parent item for the given item.
List<T>
getRootItems()
Gets the root items of this structure.
void
moveAfterSibling(T item, T sibling)
Moves an item to the position immediately after a sibling item.
TreeData<T>
removeItem(T item)
Remove a given item from this structure.
void
setParent(T item, T parent)
Moves an item to become a child of the given parent item.
-
-
-
Constructor Detail
-
TreeData
public TreeData()
Creates an initially empty hierarchical data representation to which items can be added or removed.
-
-
Method Detail
-
addRootItems
public TreeData<T> addRootItems(T... items)
Adds the items as root items to this structure.
Parameters:
items
- the items to addReturns:
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
public TreeData<T> addRootItems(Collection<T> items)
Adds the items of the given collection as root items to this structure.
Parameters:
items
- the collection of items to addReturns:
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
public TreeData<T> addRootItems(Stream<T> items)
Adds the items of the given stream as root items to this structure.
Parameters:
items
- the stream of root items to addReturns:
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
public TreeData<T> addItem(T parent, T item)
Adds a data item as a child of
parent
. 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 addReturns:
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
public TreeData<T> addItems(T parent, T... items)
Adds a list of data items as children of
parent
. 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 addReturns:
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(T parent, Collection<T> items)
Adds a list of data items as children of
parent
. 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 addReturns:
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(T parent, Stream<T> items)
Adds data items contained in a stream as children of
parent
. 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 addReturns:
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 itemsReturns:
this
-
addItems
public TreeData<T> addItems(Stream<T> rootItems, ValueProvider<T,Stream<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 itemsReturns:
this
-
removeItem
public TreeData<T> removeItem(T item)
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 dataReturns:
this
Throws:
IllegalArgumentException
- if the item does not exist in this structure
-
clear
public TreeData<T> clear()
Clear all items from this structure. Shorthand for calling
removeItem(Object)
with null.Returns:
this
-
getRootItems
public List<T> getRootItems()
Gets the root items of this structure.
Returns:
an unmodifiable list of root items of this structure
-
getChildren
public List<T> getChildren(T item)
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 itemsReturns:
an unmodifiable list of child items for the given item
Throws:
IllegalArgumentException
- if the item does not exist in this structure
-
getParent
public T getParent(T item)
Get the parent item for the given item.
Parameters:
item
- the item for which to retrieve the parent item forReturns:
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
public void setParent(T item, T parent)
Moves an item to become a child of the given parent item. The new parent item must exist in the hierarchy. Setting the parent to
null
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
public void moveAfterSibling(T item, T sibling)
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
public boolean contains(T item)
Check whether the given item is in this hierarchy.
Parameters:
item
- the item to checkReturns:
true
if the item is in this hierarchy,false
if not
-
-