Package org.vaadin.firitin.components
Class Tree<T>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<com.vaadin.flow.component.orderedlayout.VerticalLayout>
org.vaadin.firitin.components.Tree<T>
- Type Parameters:
T
- the type of items listed as nodes of Tree. Use Object if nothing else.
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier
,com.vaadin.flow.component.DetachNotifier
,com.vaadin.flow.component.HasElement
,com.vaadin.flow.component.HasStyle
,Serializable
@StyleSheet("context://frontend/org/vaadin/firitin/components/tree.css")
public class Tree<T>
extends com.vaadin.flow.component.Composite<com.vaadin.flow.component.orderedlayout.VerticalLayout>
A Tree component to display hierarchical data sets.
- Author:
- mstahv
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
This can be used to further configure the created TreeItem instances.static interface
Tree.ItemGenerator
can be used to customize how to item is shown.static interface
Tree.ItemIconGenerator
can be used to customize the icon shown before the label of an item.static interface
A listener to track when the selected node is changed. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds child of the node in UI.void
addItemDecorator
(Tree.ItemDecorator<T> decorator) Adds anTree.ItemDecorator
to further configureTreeItem
s generated automatically whensetItems(List, ChildrenProvider)
method is called.void
addSelectionListener
(Tree.SelectionListener<T> listener) Adds selection listener to nodes.protected TreeItem
createTreeItem
(T item) void
Deselects all tree items in the UI.void
Edits child in UI.protected void
fillTree
(Tree.ChildrenProvider<T> childrenProvider, T item, TreeItem treeItem) protected void
fillWithProviders
(int level, T item, TreeItem treeItem, Tree.ChildrenProvider... providers) void
hideChildren
(T item) Hides children of the node in UI.void
Moves child of the node in UI.void
removeChild
(T parent, T item) Removes child of the node in UI.void
removeItemDecorator
(Tree.ItemDecorator<T> decorator) void
removeSelectionListener
(Tree.SelectionListener<T> listener) scrollItemToView
(T item) Scrolls the tree item representing given item to be visible in the UI.void
selectItem
(T item, boolean selected) Selects (or deselects) the tree item representing given item in the UI.void
setItemGenerator
(Tree.ItemGenerator<T> itemGenerator) Sets the strategy to generate component for for the items.void
setItemIconGenerator
(Tree.ItemIconGenerator<T> itemIconGenerator) Sets the strategy to generate icons for the items.void
setItemLabelGenerator
(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator) Sets the strategy to generate label texts for the items.void
setItems
(com.vaadin.flow.data.provider.hierarchy.TreeData<T> treeData, Tree.ChildrenProvider<T> childrenProvider) Deprecated.Helper to move from TreeGrid usage, in case the TreeData (from Vaadin core) happens to be used to describe the hierarchy.void
setItems
(List<? extends T> roots, Tree.ChildrenProvider<? extends T>... providersForNextLevels) Sets root items with multiple children providers used to fetch sub-sequent levels.void
setItems
(List<? extends T> rootNodes, Tree.ChildrenProvider<T> childrenProvider) Sets the root nodes for the tree with a strategy to fetch children for items (recursively).void
setItems
(T root, Tree.ChildrenProvider<? extends T>... providersForNextLevels) Sets root item with multiple children providers used to fetch sub-sequent levels.void
setItems
(T rootNode, Tree.ChildrenProvider<T> childrenProvider) Sets the root node for the tree with a strategy to fetch children for items (recursively).void
showChildren
(T item) Shows children of the node in UI.void
showChildrenRecursively
(T item) Shows children of the node in UI recursively.void
styleChild
(T item, String styleName, String styleValue) Methods inherited from class com.vaadin.flow.component.Composite
getChildren, getContent, getElement, initContent
Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
Tree
public Tree()
-
-
Method Details
-
setItems
Sets the root nodes for the tree with a strategy to fetch children for items (recursively). The nodes will be closed by default and tree structure will be populated lazily when nodes are opened.Code example:
List<Dude> rootNodes = getRootNodes(); dudeTree.setItems(rootNodes, Dude::getSubordinates); dudeTree.showChildrenRecursively(rootNodes.get(0));
- Parameters:
rootNodes
- the items to be shown in the Tree at the root levelchildrenProvider
- the strategy to fetch children from the nodes
-
setItems
Sets the root node for the tree with a strategy to fetch children for items (recursively). The nodes will be closed by default and tree structure will be populated lazily when nodes are opened.Code example:
dudeTree.setItems(dude, Dude::getSubordinates); dudeTree.showChildrenRecursively(dude);
- Parameters:
rootNode
- the item to be shown in the Tree at the root levelchildrenProvider
- the strategy to fetch children from the nodes
-
setItems
public void setItems(List<? extends T> roots, Tree.ChildrenProvider<? extends T>... providersForNextLevels) Sets root items with multiple children providers used to fetch sub-sequent levels. This approach is handy if the hierarchy in the Tree comes from class hierarchy (different levels are different Java classes). The T type of the Tree in this case needs to be some common super type of the classes (java.lang.Object if no other exist).Code example:
Tree<AbstractPlace> tree = new Tree<>(); tree.setItemLabelGenerator(AbstractPlace::getName); tree.seItems(cities, (Tree.ChildrenProvider<City>) c -> c.getStreets(), (Tree.ChildrenProvider<Street>) s -> s.getHouses() );
- Parameters:
roots
- root items in the TreeprovidersForNextLevels
- the children providers for next levels of tree, that fetch the children for given item representing the tree node.
-
setItems
Sets root item with multiple children providers used to fetch sub-sequent levels. This approach is handy if the hierarchy in the Tree comes from class hierarchy (different levels are different Java classes). The T type of the Tree in this case needs to be some common super type of the classes (java.lang.Object if no other exist).Code example:
Tree<AbstractPlace> tree = new Tree<>(); tree.setItemLabelGenerator(AbstractPlace::getName); tree.seItems(city, (Tree.ChildrenProvider<City>) c -> c.getStreets(), (Tree.ChildrenProvider<Street>) s -> s.getHouses() );
- Parameters:
root
- root item in the TreeprovidersForNextLevels
- the children providers for next levels of tree, that fetch the children for given item representing the tree node.
-
fillWithProviders
protected void fillWithProviders(int level, T item, TreeItem treeItem, Tree.ChildrenProvider... providers) -
setItems
@Deprecated public void setItems(com.vaadin.flow.data.provider.hierarchy.TreeData<T> treeData, Tree.ChildrenProvider<T> childrenProvider) Deprecated.Helper to move from TreeGrid usage, in case the TreeData (from Vaadin core) happens to be used to describe the hierarchy.- Parameters:
treeData
- dchildrenProvider
- p
-
createTreeItem
-
fillTree
-
addItemDecorator
Adds anTree.ItemDecorator
to further configureTreeItem
s generated automatically whensetItems(List, ChildrenProvider)
method is called.- Parameters:
decorator
- theTree.ItemDecorator
-
removeItemDecorator
-
setItemLabelGenerator
public void setItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator) Sets the strategy to generate label texts for the items.- Parameters:
itemLabelGenerator
- theItemLabelGenerator
-
setItemIconGenerator
Sets the strategy to generate icons for the items.- Parameters:
itemIconGenerator
- theTree.ItemIconGenerator
-
setItemGenerator
Sets the strategy to generate component for for the items.Note that this overrides possibly configured
Tree.ItemIconGenerator
andItemLabelGenerator
.- Parameters:
itemGenerator
- theTree.ItemGenerator
-
addSelectionListener
Adds selection listener to nodes.- Parameters:
listener
- the listener to be called when selected item changes
-
removeSelectionListener
-
showChildren
Shows children of the node in UI. Same as user would click on the caret in the UI.- Parameters:
item
- the item whose children should be visible in the UI
-
showChildrenRecursively
Shows children of the node in UI recursively. Same as user would click on the caret in the UI.- Parameters:
item
- the item whose children should be visible in the UI
-
hideChildren
Hides children of the node in UI. Same as user would click on the caret in the UI when children are visible.- Parameters:
item
- the item whose children should be hidden in the UI
-
moveChild
Moves child of the node in UI.- Parameters:
parent
- the parent whose child should be moved in the UI, may be nullitems
- the items within which one is to be movedindex
- the index of the item to be movedup
- True then move up else move down
-
addChild
Adds child of the node in UI.- Parameters:
parent
- the parent whose child should be added in the UI, may be nullitem
- the item to be added in the UI
-
removeChild
Removes child of the node in UI.- Parameters:
parent
- the parent whose child should be removed in the UI, may be nullitem
- the item to be removed in the UI
-
editChild
Edits child in UI.- Parameters:
item
- the item to be edited in the UI
-
styleChild
- Parameters:
item
- the item to be styled in the UIstyleName
- the style property name as camelCase, not nullstyleValue
- the style property value (if null, the property will be removed)
-
scrollItemToView
Scrolls the tree item representing given item to be visible in the UI.Note, the item needs to be visible for the method to work.
- Parameters:
item
- the item to be shown in the UI- Returns:
- The TreeItem for the scroll
-
selectItem
Selects (or deselects) the tree item representing given item in the UI.- Parameters:
item
- item the item to be selected in the UIselected
- if True then select else deselect
-
deselectAllItems
public void deselectAllItems()Deselects all tree items in the UI.
-