Class Tree<T>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<com.vaadin.flow.component.html.Div>
org.vaadin.tatu.Tree<T>
Type Parameters:
T - the data type
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable, com.vaadin.flow.component.FocusNotifier, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.data.provider.hierarchy.HasHierarchicalDataProvider<T>, Serializable

@CssImport(value="./custom-grid-tree-toggle.css", themeFor="custom-grid-tree-toggle") @JsModule("./custom-grid-tree-toggle.ts") public class Tree<T> extends com.vaadin.flow.component.Composite<com.vaadin.flow.component.html.Div> implements com.vaadin.flow.data.provider.hierarchy.HasHierarchicalDataProvider<T>, com.vaadin.flow.component.Focusable, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasTheme
Tree component. A Tree can be used to select an item from a hierarchical set of items.
Author:
Tatu Lund
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier

    com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier

    com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>
  • Constructor Summary

    Constructors
    Constructor
    Description
    Tree(com.vaadin.flow.data.provider.hierarchy.HierarchicalDataProvider<T,?> dataProvider, com.vaadin.flow.function.ValueProvider<T,?> valueProvider)
    Constructs a new Tree Component with given caption and HierarchicalDataProvider.
    Tree(com.vaadin.flow.data.provider.hierarchy.TreeData<T> treeData, com.vaadin.flow.function.ValueProvider<T,?> valueProvider)
    Constructs a new Tree Component with given caption and TreeData.
    Tree(com.vaadin.flow.function.ValueProvider<T,?> valueProvider)
    Constructs a new Tree Component.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.vaadin.flow.shared.Registration
    addCollapseListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.treegrid.CollapseEvent<T,com.vaadin.flow.component.treegrid.TreeGrid<T>>> listener)
    Adds a CollapseListener to this Tree.
    com.vaadin.flow.component.grid.contextmenu.GridContextMenu<T>
     
    com.vaadin.flow.shared.Registration
    addDragEndListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.grid.dnd.GridDragEndEvent<T>> listener)
    Adds a drag end listener to this component.
    com.vaadin.flow.shared.Registration
    addDragStartListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.grid.dnd.GridDragStartEvent<T>> listener)
    Adds a drag start listener to this component.
    com.vaadin.flow.shared.Registration
    addDropListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.grid.dnd.GridDropEvent<T>> listener)
    Adds a drop listener to this component.
    com.vaadin.flow.shared.Registration
    addExpandListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.treegrid.ExpandEvent<T,com.vaadin.flow.component.treegrid.TreeGrid<T>>> listener)
    Adds an ExpandListener to this Tree.
    com.vaadin.flow.shared.Registration
    addItemClickListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.grid.ItemClickEvent<T>> listener)
    Adds an item click listener.
    com.vaadin.flow.shared.Registration
    addSelectionListener(com.vaadin.flow.component.ComponentEventListener<SelectionChangedEvent<T,Tree<T>>> listener)
    Adds a selection listener to the current selection model.
    void
    addThemeVariants(com.vaadin.flow.component.grid.GridVariant... gridVariants)
     
    com.vaadin.flow.data.selection.MultiSelect<com.vaadin.flow.component.grid.Grid<T>,T>
    Use this tree as a multi select in Binder.
    com.vaadin.flow.data.selection.SingleSelect<com.vaadin.flow.component.grid.Grid<T>,T>
    Use this tree as a single select in Binder.
    void
    Collapse the given items.
    void
    collapse(T... items)
    Collapse the given items.
    void
    collapseRecursively(Collection<T> items, int depth)
    Collapse the given items and their children recursively until the given depth.
    protected Tree<T>.org.vaadin.tatu.Tree.CustomizedTreeGrid<T>
    Create inner TreeGrid object.
    void
    deselect(T item)
    This method is a shorthand that delegates to the currently set selection model.
    void
    Expands the given items.
    void
    expand(T... items)
    Expands the given items.
    void
    expandRecursively(Collection<T> items, int depth)
    Expands the given items and their children recursively until the given depth.
    protected void
    fireCollapseEvent(Collection<T> collection, boolean userOriginated)
    Fires a collapse event with given item.
    protected void
    fireExpandEvent(Collection<T> collection, boolean userOriginated)
    Fires an expand event with given item.
    void
     
    Gets the CSS class names for this component.
    com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicator<T>
    Returns the data communicator of this Grid.
    com.vaadin.flow.data.provider.hierarchy.HierarchicalDataProvider<T,com.vaadin.flow.function.SerializablePredicate<T>>
     
    com.vaadin.flow.component.grid.dnd.GridDropMode
    Gets the drop mode of this drop target.
    com.vaadin.flow.function.ValueProvider<T,com.vaadin.flow.component.icon.VaadinIcon>
    Gets the item icon provider.
    com.vaadin.flow.function.ValueProvider<T,com.vaadin.flow.server.StreamResource>
    Gets the item icon provider.
     
    com.vaadin.flow.function.ValueProvider<T,?>
    Gets the item caption provider.
    This method is a shorthand that delegates to the currently set selection model.
    com.vaadin.flow.component.grid.GridSelectionModel<T>
    Returns the selection model for this Tree.
    int
     
     
    com.vaadin.flow.dom.ThemeList
     
    com.vaadin.flow.function.ValueProvider<T,String>
    Gets the item description generator.
    boolean
    isExpanded(T item)
    Returns whether a given item is expanded or collapsed.
    boolean
    Gets whether rows of the tree can be dragged.
    boolean
    Removes a CSS class name from this component.
    void
    removeThemeVariants(com.vaadin.flow.component.grid.GridVariant... gridVariants)
     
    void
    Scrolls to the end of the last data row.
    void
    scrollToIndex(int row)
    Scrolls to a certain item.
    void
    scrollToIndex(int... indexes)
    Scrolls to a nested item within the tree.
    void
    Scrolls to the beginning of the first data row.
    void
    select(T item)
    This method is a shorthand that delegates to the currently set selection model.
    void
    setAllRowsVisible(boolean heightByRows)
     
    void
    setClassName(String className)
    Sets the CSS class names of this component.
    void
    setDataProvider(com.vaadin.flow.data.provider.hierarchy.HierarchicalDataProvider<T,?> dataProvider)
     
    void
    setDropMode(com.vaadin.flow.component.grid.dnd.GridDropMode dropMode)
    Sets the drop mode of this drop target.
    void
    setHtmlProvider(com.vaadin.flow.function.ValueProvider<T,?> htmlProvider)
    Sets the item generator that is used to produce the html content shown for each item.
    void
     
    void
    setItemCaptionProvider(com.vaadin.flow.function.ValueProvider<T,?> valueProvider)
    Sets the item caption generator that is used to produce the strings shown as the text for each item.
    void
    setItemIconProvider(com.vaadin.flow.function.ValueProvider<T,com.vaadin.flow.component.icon.VaadinIcon> iconProvider)
    Sets the item icon generator that is used to produce custom icons for items.
    void
    setItemIconSrcProvider(com.vaadin.flow.function.ValueProvider<T,com.vaadin.flow.server.StreamResource> iconSrcProvider)
    Sets the item icon src generator that is used to produce custom icons for items.
    void
    setItemTooltipProvider(com.vaadin.flow.function.ValueProvider<T,String> tooltipProvider)
    Sets the tooltip generator that is used for generating tooltip descriptions for items.
    void
    setPartNameGenerator(com.vaadin.flow.function.SerializableFunction<T,String> partNameGenerator)
    Sets the function that is used for generating CSS part names for all the cells in the rows in this tree.
    void
    setRowsDraggable(boolean rowsDraggable)
    Sets whether the user can drag the tree rows or not.
    void
    setSanitize(boolean sanitize)
    By default html content is sanitized, if you have custom web components to or other offending content that you want to render, set to false.
    com.vaadin.flow.component.grid.GridSelectionModel<T>
    setSelectionMode(com.vaadin.flow.component.grid.Grid.SelectionMode selectionMode)
    Sets the tree's selection mode.
    void
    setSelectOnlyLeafs(boolean selectOnlyLeafs)
    When true, only selecting leafs is accepted.
    void
    setTabIndex(int tabIndex)
     
    void
     

    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, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, 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.BlurNotifier

    addBlurListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.Focusable

    addFocusShortcut, blur, focus

    Methods inherited from interface com.vaadin.flow.component.FocusNotifier

    addFocusListener

    Methods inherited from interface com.vaadin.flow.component.HasComponents

    add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAll

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.data.provider.hierarchy.HasHierarchicalDataProvider

    getTreeData, setItems, setItems, setTreeData

    Methods inherited from interface com.vaadin.flow.component.HasSize

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassNames, getStyle, hasClassName, removeClassNames, setClassName

    Methods inherited from interface com.vaadin.flow.component.HasTheme

    addThemeName, addThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName
  • Constructor Details

    • Tree

      public Tree(com.vaadin.flow.function.ValueProvider<T,?> valueProvider)
      Constructs a new Tree Component.
      Parameters:
      valueProvider - the item caption provider to use, not null
    • Tree

      public Tree(com.vaadin.flow.data.provider.hierarchy.TreeData<T> treeData, com.vaadin.flow.function.ValueProvider<T,?> valueProvider)
      Constructs a new Tree Component with given caption and TreeData.
      Parameters:
      treeData - the tree data for component
      valueProvider - the item caption provider to use, not null
    • Tree

      public Tree(com.vaadin.flow.data.provider.hierarchy.HierarchicalDataProvider<T,?> dataProvider, com.vaadin.flow.function.ValueProvider<T,?> valueProvider)
      Constructs a new Tree Component with given caption and HierarchicalDataProvider.
      Parameters:
      dataProvider - the hierarchical data provider for component
      valueProvider - the item caption provider to use, not null
  • Method Details

    • createTreeGrid

      protected Tree<T>.org.vaadin.tatu.Tree.CustomizedTreeGrid<T> createTreeGrid()
      Create inner TreeGrid object. May be overridden in subclasses.
      Returns:
      new TreeGrid
    • getDataProvider

      public com.vaadin.flow.data.provider.hierarchy.HierarchicalDataProvider<T,com.vaadin.flow.function.SerializablePredicate<T>> getDataProvider()
      Specified by:
      getDataProvider in interface com.vaadin.flow.data.provider.hierarchy.HasHierarchicalDataProvider<T>
    • addExpandListener

      public com.vaadin.flow.shared.Registration addExpandListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.treegrid.ExpandEvent<T,com.vaadin.flow.component.treegrid.TreeGrid<T>>> listener)
      Adds an ExpandListener to this Tree.
      Parameters:
      listener - the listener to add
      Returns:
      a registration for the listener
      See Also:
      • ExpandEvent
    • addCollapseListener

      public com.vaadin.flow.shared.Registration addCollapseListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.treegrid.CollapseEvent<T,com.vaadin.flow.component.treegrid.TreeGrid<T>>> listener)
      Adds a CollapseListener to this Tree.
      Parameters:
      listener - the listener to add
      Returns:
      a registration for the listener
      See Also:
      • CollapseEvent
    • fireExpandEvent

      protected void fireExpandEvent(Collection<T> collection, boolean userOriginated)
      Fires an expand event with given item.
      Parameters:
      collection - the expanded item
      userOriginated - whether the expand was triggered by a user interaction or the server
    • fireCollapseEvent

      protected void fireCollapseEvent(Collection<T> collection, boolean userOriginated)
      Fires a collapse event with given item.
      Parameters:
      collection - the collapsed item
      userOriginated - whether the collapse was triggered by a user interaction or the server
    • expand

      public void expand(T... items)
      Expands the given items.

      If an item is currently expanded, does nothing. If an item does not have any children, does nothing.

      Parameters:
      items - the items to expand
    • expand

      public void expand(Collection<T> items)
      Expands the given items.

      If an item is currently expanded, does nothing. If an item does not have any children, does nothing.

      Parameters:
      items - the items to expand
    • expandRecursively

      public void expandRecursively(Collection<T> items, int depth)
      Expands the given items and their children recursively until the given depth.

      depth describes the maximum distance between a given item and its descendant, meaning that expandRecursively(items, 0) expands only the given items while expandRecursively(items, 2) expands the given items as well as their children and grandchildren.

      Parameters:
      items - the items to expand recursively
      depth - the maximum depth of recursion
    • collapse

      public void collapse(T... items)
      Collapse the given items.

      For items that are already collapsed, does nothing.

      Parameters:
      items - the collection of items to collapse
    • collapse

      public void collapse(Collection<T> items)
      Collapse the given items.

      For items that are already collapsed, does nothing.

      Parameters:
      items - the collection of items to collapse
    • collapseRecursively

      public void collapseRecursively(Collection<T> items, int depth)
      Collapse the given items and their children recursively until the given depth.

      depth describes the maximum distance between a given item and its descendant, meaning that collapseRecursively(items, 0) collapses only the given items while collapseRecursively(items, 2) collapses the given items as well as their children and grandchildren.

      Parameters:
      items - the items to expand recursively
      depth - the maximum depth of recursion
    • isExpanded

      public boolean isExpanded(T item)
      Returns whether a given item is expanded or collapsed.
      Parameters:
      item - the item to check
      Returns:
      true if the item is expanded, false if collapsed
    • getSelectedItems

      public Set<T> getSelectedItems()
      This method is a shorthand that delegates to the currently set selection model.
      Returns:
      set of selected items
      See Also:
    • select

      public void select(T item)
      This method is a shorthand that delegates to the currently set selection model.
      Parameters:
      item - item to select
      See Also:
    • deselect

      public void deselect(T item)
      This method is a shorthand that delegates to the currently set selection model.
      Parameters:
      item - item to deselect
      See Also:
    • addSelectionListener

      public com.vaadin.flow.shared.Registration addSelectionListener(com.vaadin.flow.component.ComponentEventListener<SelectionChangedEvent<T,Tree<T>>> listener)
      Adds a selection listener to the current selection model.

      NOTE: If selection mode is switched with setSelectionMode(SelectionMode), then this listener is not triggered anymore when selection changes!

      Parameters:
      listener - the listener to add
      Returns:
      a registration handle to remove the listener
      Throws:
      UnsupportedOperationException - if selection has been disabled with Grid.SelectionMode.NONE
    • asMultiSelect

      public com.vaadin.flow.data.selection.MultiSelect<com.vaadin.flow.component.grid.Grid<T>,T> asMultiSelect()
      Use this tree as a multi select in Binder. Throws IllegalStateException if the tree is not using Grid.SelectionMode.MULTI.
      Returns:
      the single select wrapper that can be used in binder
    • asSingleSelect

      public com.vaadin.flow.data.selection.SingleSelect<com.vaadin.flow.component.grid.Grid<T>,T> asSingleSelect()
      Use this tree as a single select in Binder. Throws IllegalStateException if the tree is not using Grid.SelectionMode.SINGLE.
      Returns:
      the single select wrapper that can be used in binder
    • getSelectionModel

      public com.vaadin.flow.component.grid.GridSelectionModel<T> getSelectionModel()
      Returns the selection model for this Tree.
      Returns:
      the selection model, not null
    • setHtmlProvider

      public void setHtmlProvider(com.vaadin.flow.function.ValueProvider<T,?> htmlProvider)
      Sets the item generator that is used to produce the html content shown for each item. By default, String.valueOf(Object) is used.

      Note: This will override icon, tooltip and value provider settings.

      Parameters:
      htmlProvider - the item html provider to use, not null
    • setItemCaptionProvider

      public void setItemCaptionProvider(com.vaadin.flow.function.ValueProvider<T,?> valueProvider)
      Sets the item caption generator that is used to produce the strings shown as the text for each item. By default, String.valueOf(Object) is used.
      Parameters:
      valueProvider - the item caption provider to use, not null
    • setItemIconProvider

      public void setItemIconProvider(com.vaadin.flow.function.ValueProvider<T,com.vaadin.flow.component.icon.VaadinIcon> iconProvider)
      Sets the item icon generator that is used to produce custom icons for items. The generator can return null for items with no icon.
      Parameters:
      iconProvider - the item icon generator to set, not null
      Throws:
      NullPointerException - if itemIconGenerator is null
    • setItemIconSrcProvider

      public void setItemIconSrcProvider(com.vaadin.flow.function.ValueProvider<T,com.vaadin.flow.server.StreamResource> iconSrcProvider)
      Sets the item icon src generator that is used to produce custom icons for items. The generator can return null for items with no icon.
      Parameters:
      iconSrcProvider - the item icon generator to set, not null
      Throws:
      NullPointerException - if itemIconGenerator is null
    • setItemTooltipProvider

      public void setItemTooltipProvider(com.vaadin.flow.function.ValueProvider<T,String> tooltipProvider)
      Sets the tooltip generator that is used for generating tooltip descriptions for items.
      Parameters:
      tooltipProvider - the item description generator to set, or null to remove a previously set generator
    • getItemCaptionProvider

      public com.vaadin.flow.function.ValueProvider<T,?> getItemCaptionProvider()
      Gets the item caption provider.
      Returns:
      the item caption provider
    • getIconProvider

      public com.vaadin.flow.function.ValueProvider<T,com.vaadin.flow.component.icon.VaadinIcon> getIconProvider()
      Gets the item icon provider.
      Returns:
      the item icon provider
    • getIconSrcProvider

      public com.vaadin.flow.function.ValueProvider<T,com.vaadin.flow.server.StreamResource> getIconSrcProvider()
      Gets the item icon provider.
      Returns:
      the item icon provider
    • getTooltipProvider

      public com.vaadin.flow.function.ValueProvider<T,String> getTooltipProvider()
      Gets the item description generator.
      Returns:
      the item description generator
    • addItemClickListener

      public com.vaadin.flow.shared.Registration addItemClickListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.grid.ItemClickEvent<T>> listener)
      Adds an item click listener. The listener is called when an item of this Tree is clicked.
      Parameters:
      listener - the item click listener, not null
      Returns:
      a registration for the listener
    • setSelectionMode

      public com.vaadin.flow.component.grid.GridSelectionModel<T> setSelectionMode(com.vaadin.flow.component.grid.Grid.SelectionMode selectionMode)
      Sets the tree's selection mode.

      The built-in selection modes are:

      • Grid.SelectionMode.SINGLE the default model
      • Grid.SelectionMode.MULTI
      • Grid.SelectionMode.NONE preventing selection
      Parameters:
      selectionMode - the selection mode to switch to, not null
      Returns:
      the used selection model
      See Also:
      • Grid.SelectionMode
    • getClassName

      public String getClassName()
      Gets the CSS class names for this component.
      Specified by:
      getClassName in interface com.vaadin.flow.component.HasStyle
      Returns:
      a space-separated string of class names, or null if there are no class names
    • setClassName

      public void setClassName(String className)
      Sets the CSS class names of this component. This method overwrites any previous set class names.
      Specified by:
      setClassName in interface com.vaadin.flow.component.HasStyle
      Parameters:
      className - a space-separated string of class names to set, or null to remove all class names
    • removeClassName

      public boolean removeClassName(String className)
      Removes a CSS class name from this component.
      Specified by:
      removeClassName in interface com.vaadin.flow.component.HasStyle
      Parameters:
      className - the CSS class name to remove, not null
      Returns:
      true if the class name was removed, false if the class list didn't contain the class name
    • setId

      public void setId(String id)
      Overrides:
      setId in class com.vaadin.flow.component.Component
    • getId

      public Optional<String> getId()
      Overrides:
      getId in class com.vaadin.flow.component.Component
    • addContextMenu

      public com.vaadin.flow.component.grid.contextmenu.GridContextMenu<T> addContextMenu()
    • scrollToIndex

      public void scrollToIndex(int row) throws IllegalArgumentException
      Scrolls to a certain item.

      If the item has an open details row, its size will also be taken into account.

      Parameters:
      row - zero based index of the item to scroll to in the current view.
      Throws:
      IllegalArgumentException - if the provided row is outside the item range
    • scrollToStart

      public void scrollToStart()
      Scrolls to the beginning of the first data row.
    • scrollToEnd

      public void scrollToEnd()
      Scrolls to the end of the last data row.
    • getTabIndex

      public int getTabIndex()
      Specified by:
      getTabIndex in interface com.vaadin.flow.component.Focusable<T>
    • setTabIndex

      public void setTabIndex(int tabIndex)
      Specified by:
      setTabIndex in interface com.vaadin.flow.component.Focusable<T>
    • focus

      public void focus()
      Specified by:
      focus in interface com.vaadin.flow.component.Focusable<T>
    • setAllRowsVisible

      public void setAllRowsVisible(boolean heightByRows)
    • setDataProvider

      public void setDataProvider(com.vaadin.flow.data.provider.hierarchy.HierarchicalDataProvider<T,?> dataProvider)
      Specified by:
      setDataProvider in interface com.vaadin.flow.data.provider.hierarchy.HasHierarchicalDataProvider<T>
    • addThemeVariants

      public void addThemeVariants(com.vaadin.flow.component.grid.GridVariant... gridVariants)
    • removeThemeVariants

      public void removeThemeVariants(com.vaadin.flow.component.grid.GridVariant... gridVariants)
    • setThemeName

      public void setThemeName(String theme)
      Specified by:
      setThemeName in interface com.vaadin.flow.component.HasTheme
    • getThemeName

      public String getThemeName()
      Specified by:
      getThemeName in interface com.vaadin.flow.component.HasTheme
    • getThemeNames

      public com.vaadin.flow.dom.ThemeList getThemeNames()
      Specified by:
      getThemeNames in interface com.vaadin.flow.component.HasTheme
    • setSanitize

      public void setSanitize(boolean sanitize)
      By default html content is sanitized, if you have custom web components to or other offending content that you want to render, set to false.
      Parameters:
      sanitize - Enable / disable html sanitation.
    • setDropMode

      public void setDropMode(com.vaadin.flow.component.grid.dnd.GridDropMode dropMode)
      Sets the drop mode of this drop target. When set to not null, tree fires drop events upon data drop over the tree or the tree rows.

      When using GridDropMode.ON_TOP, and the tree is either empty or has empty space after the last row, the drop can still happen on the empty space, and the GridDropEvent.getDropTargetItem() will return an empty optional.

      When using GridDropMode.BETWEEN or GridDropMode.ON_TOP_OR_BETWEEN, and there is at least one row in the tree, any drop after the last row in the tree will get the last row as the GridDropEvent.getDropTargetItem(). If there are no rows in the tree, then it will return an empty optional.

      If using GridDropMode.ON_GRID, then the drop will not happen on any row, but instead just "on the tree". The target row will not be present in this case.

      NOTE: Prefer not using a row specific GridDropMode with a tree that enables sorting. If for example a new row gets added to a specific location on drop event, it might not end up in the location of the drop but rather where the active sorting configuration prefers to place it. This behavior might feel unexpected for the users.

      Parameters:
      dropMode - Drop mode that describes the allowed drop locations within the Tree's row. Can be null to disable dropping on the tree.
      See Also:
      • GridDropEvent.getDropLocation()
    • getDropMode

      public com.vaadin.flow.component.grid.dnd.GridDropMode getDropMode()
      Gets the drop mode of this drop target.
      Returns:
      Drop mode that describes the allowed drop locations within the Tree's row. null if dropping is not enabled.
    • setRowsDraggable

      public void setRowsDraggable(boolean rowsDraggable)
      Sets whether the user can drag the tree rows or not.
      Parameters:
      rowsDraggable - true if the rows can be dragged by the user; false if not
    • isRowsDraggable

      public boolean isRowsDraggable()
      Gets whether rows of the tree can be dragged.
      Returns:
      true if the rows are draggable, false otherwise
    • addDragStartListener

      public com.vaadin.flow.shared.Registration addDragStartListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.grid.dnd.GridDragStartEvent<T>> listener)
      Adds a drag start listener to this component.
      Parameters:
      listener - the listener to add, not null
      Returns:
      a handle that can be used for removing the listener
    • addDropListener

      public com.vaadin.flow.shared.Registration addDropListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.grid.dnd.GridDropEvent<T>> listener)
      Adds a drop listener to this component.
      Parameters:
      listener - the listener to add, not null
      Returns:
      a handle that can be used for removing the listener
    • addDragEndListener

      public com.vaadin.flow.shared.Registration addDragEndListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.grid.dnd.GridDragEndEvent<T>> listener)
      Adds a drag end listener to this component.
      Parameters:
      listener - the listener to add, not null
      Returns:
      a handle that can be used for removing the listener
    • getDataCommunicator

      public com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicator<T> getDataCommunicator()
      Returns the data communicator of this Grid.
      Returns:
      HierarchicalDataCommunicator
    • setSelectOnlyLeafs

      public void setSelectOnlyLeafs(boolean selectOnlyLeafs)
      When true, only selecting leafs is accepted. Also SelectionChangedEvent is not fired if non-leaf node is clicked.

      Note: asSingleSelect and asMultiSelect pass thru API's are not affected.

      Parameters:
      selectOnlyLeafs - boolean value.
    • scrollToIndex

      public void scrollToIndex(int... indexes)
      Scrolls to a nested item within the tree.

      The `indexes` parameter can be either a single number or multiple numbers. The tree will first try to scroll to the item at the first index in the root level of the tree. In case the item at the first index is expanded, the tree will then try scroll to the item at the second index within the children of the expanded first item, and so on. Each given index points to a child of the item at the previous index.

      Parameters:
      indexes - zero based row indexes to scroll to
    • setPartNameGenerator

      public void setPartNameGenerator(com.vaadin.flow.function.SerializableFunction<T,String> partNameGenerator)
      Sets the function that is used for generating CSS part names for all the cells in the rows in this tree. Returning null from the generator results in no custom part name being set. Multiple part names can be returned from the generator as space-separated.

      Parameters:
      partNameGenerator - the part name generator to set, not null
      Throws:
      NullPointerException - if partNameGenerator is null