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
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfaceThis can be used to further configure the created TreeItem instances.static interfaceTree.ItemGeneratorcan be used to customize how to item is shown.static interfaceTree.ItemIconGeneratorcan be used to customize the icon shown before the label of an item.static interfaceA listener to track when the selected node is changed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds child of the node in UI.voidaddItemDecorator(Tree.ItemDecorator<T> decorator) Adds anTree.ItemDecoratorto further configureTreeItems generated automatically whensetItems(List, ChildrenProvider)method is called.voidaddSelectionListener(Tree.SelectionListener<T> listener) Adds selection listener to nodes.protected TreeItemcreateTreeItem(T item) voidDeselects all tree items in the UI.voidEdits child in UI.protected voidfillTree(Tree.ChildrenProvider<T> childrenProvider, T item, TreeItem treeItem) protected voidfillWithProviders(int level, T item, TreeItem treeItem, Tree.ChildrenProvider... providers) voidhideChildren(T item) Hides children of the node in UI.voidMoves child of the node in UI.voidremoveChild(T parent, T item) Removes child of the node in UI.voidremoveItemDecorator(Tree.ItemDecorator<T> decorator) voidremoveSelectionListener(Tree.SelectionListener<T> listener) scrollItemToView(T item) Scrolls the tree item representing given item to be visible in the UI.voidselectItem(T item, boolean selected) Selects (or deselects) the tree item representing given item in the UI.voidsetItemGenerator(Tree.ItemGenerator<T> itemGenerator) Sets the strategy to generate component for for the items.voidsetItemIconGenerator(Tree.ItemIconGenerator<T> itemIconGenerator) Sets the strategy to generate icons for the items.voidsetItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator) Sets the strategy to generate label texts for the items.voidsetItems(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.voidsetItems(List<? extends T> roots, Tree.ChildrenProvider<? extends T>... providersForNextLevels) Sets root items with multiple children providers used to fetch sub-sequent levels.voidsetItems(List<? extends T> rootNodes, Tree.ChildrenProvider<T> childrenProvider) Sets the root nodes for the tree with a strategy to fetch children for items (recursively).voidsetItems(T root, Tree.ChildrenProvider<? extends T>... providersForNextLevels) Sets root item with multiple children providers used to fetch sub-sequent levels.voidsetItems(T rootNode, Tree.ChildrenProvider<T> childrenProvider) Sets the root node for the tree with a strategy to fetch children for items (recursively).voidshowChildren(T item) Shows children of the node in UI.voidshowChildrenRecursively(T item) Shows children of the node in UI recursively.voidstyleChild(T item, String styleName, String styleValue) Methods inherited from class com.vaadin.flow.component.Composite
getChildren, getContent, getElement, initContentMethods 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, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods 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.ItemDecoratorto further configureTreeItems 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.ItemIconGeneratorandItemLabelGenerator.- 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.
-