Class 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
    • Constructor Detail

      • Tree

        public Tree()
    • Method Detail

      • setItems

        public void setItems​(com.vaadin.flow.data.provider.hierarchy.TreeData<T> treeData,
                             Tree.ChildrenProvider<T> childrenProvider)
      • createTreeItem

        protected TreeItem createTreeItem​(T item)
      • setItemLabelGenerator

        public void setItemLabelGenerator​(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)
        Sets the strategy to generate label texts for the items.
        Parameters:
        itemLabelGenerator - the ItemLabelGenerator
      • addSelectionListener

        public void addSelectionListener​(Tree.SelectionListener<T> listener)
        Adds selection listener to nodes.
        Parameters:
        listener - the listener to be called when selected item changes
      • 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 null
        items - the items within which one is to be moved
        index - the index of the item to be moved
        up - 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 null
        item - 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 null
        item - 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 UI
        styleName - the style property name as camelCase, not null
        styleValue - 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 UI
        selected - if True then select else deselect
      • deselectAllItems

        public void deselectAllItems()
        Deselects all tree items in the UI.