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,Serializable
@CssImport("./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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTree.ChildrenProvider<T>static interfaceTree.ItemDecorator<T>This can be used to further configure the created TreeItem instances.static interfaceTree.ItemGenerator<T>Tree.ItemGeneratorcan be used to customize how to item is shown.static interfaceTree.ItemIconGenerator<T>Tree.ItemIconGeneratorcan be used to customize the icon shown before the label of an item.static interfaceTree.SelectionListener<T>A listener to track when the selected node is changed.
-
Constructor Summary
Constructors Constructor Description Tree()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(T parent, T item)Adds 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)voiddeselectAllItems()Deselects all tree items in the UI.voideditChild(T item)Edits child in UI.protected voidfillTree(Tree.ChildrenProvider<T> childrenProvider, T item, TreeItem treeItem)voidhideChildren(T item)Hides children of the node in UI.voidmoveChild(T parent, List<T> items, int index, boolean up)Moves 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)TreeItemscrollItemToView(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)voidsetItems(List<T> rootNodes, Tree.ChildrenProvider<T> childrenProvider)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, initContent
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
-
-
-
-
Method Detail
-
setItems
public void setItems(List<T> rootNodes, Tree.ChildrenProvider<T> childrenProvider)
-
setItems
public void setItems(com.vaadin.flow.data.provider.hierarchy.TreeData<T> treeData, Tree.ChildrenProvider<T> childrenProvider)
-
fillTree
protected void fillTree(Tree.ChildrenProvider<T> childrenProvider, T item, TreeItem treeItem)
-
addItemDecorator
public void addItemDecorator(Tree.ItemDecorator<T> decorator)
Adds anTree.ItemDecoratorto further configureTreeItems generated automatically whensetItems(List, ChildrenProvider)method is called.- Parameters:
decorator- theTree.ItemDecorator
-
removeItemDecorator
public void removeItemDecorator(Tree.ItemDecorator<T> decorator)
-
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
public void setItemIconGenerator(Tree.ItemIconGenerator<T> itemIconGenerator)
Sets the strategy to generate icons for the items.- Parameters:
itemIconGenerator- theTree.ItemIconGenerator
-
setItemGenerator
public void setItemGenerator(Tree.ItemGenerator<T> itemGenerator)
Sets the strategy to generate component for for the items.Note that this overrides possibly configured
Tree.ItemIconGeneratorandItemLabelGenerator.- Parameters:
itemGenerator- theTree.ItemGenerator
-
addSelectionListener
public void addSelectionListener(Tree.SelectionListener<T> listener)
Adds selection listener to nodes.- Parameters:
listener- the listener to be called when selected item changes
-
removeSelectionListener
public void removeSelectionListener(Tree.SelectionListener<T> listener)
-
showChildren
public void showChildren(T item)
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
public void showChildrenRecursively(T item)
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
public void hideChildren(T item)
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
public void moveChild(T parent, List<T> items, int index, boolean up)
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
public void addChild(T parent, T item)
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
public void removeChild(T parent, T item)
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
public void editChild(T item)
Edits child in UI.- Parameters:
item- the item to be edited in the UI
-
styleChild
public void styleChild(T item, String styleName, String styleValue)
- 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
public TreeItem scrollItemToView(T item)
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
public void selectItem(T item, boolean selected)
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.
-
-