Class TreeviewNode

All Implemented Interfaces:
Animatable<ListItem>, CanDrop<ListItem>, Clickable<ListItem>, Draggable<ListItem>, Focusable<ListItem>, HandleHotKey<ListItem>, HandleMouseEvents<ListItem>, Scrollable<ListItem>, Touchable<ListItem>

public class TreeviewNode extends ListItem

A component representing a node in the treeview component The component is not intended for standalone use, it can only be inserted into the Treeview as node of the tree.

Since:
4.0
Author:
JBStrap
See Also:
  • Constructor Details

    • TreeviewNode

      public TreeviewNode(String name)
      Creates a tree by the specified name
      Parameters:
      name - The distinct name of the node
      Throws:
      NullPointerException - Thrown if the specified name is null
    • TreeviewNode

      public TreeviewNode(String name, TreeviewNode parent)
      Creates a node with the specified name and adds it below the parameter-specified parent node
      Parameters:
      name - The distinct name of the node
      parent - An instance of the node’s parent
      Throws:
      NullPointerException - Thrown if the specified name is null
  • Method Details

    • select

      public final TreeviewNode select(boolean select)
      Highlights the node
      Parameters:
      select - If true is set, the node gets selected, otherwise it is not selected
      Returns:
      The treeview component
    • setParentNode

      public final TreeviewNode setParentNode(TreeviewNode parent)
      Sets the parent for the node
      Parameters:
      parent - An instance of the node used to set the parent
      Returns:
      The node component
    • getParentNode

      public final TreeviewNode getParentNode()
      Gets the parent of the node
      Returns:
      The parent of the node or null if the node has no parent (root node)
    • getTreeview

      protected final Treeview getTreeview()
      Gets the Treeview component where the node is displayed.
      Returns:
      The treeview component where the node is displayed If the node is not displayed, null is returned.
    • getName

      public String getName()
      Gets the node name.
      Overrides:
      getName in class Component<ListItem>
      Returns:
      Node name
    • setTitle

      public TreeviewNode setTitle(String title)
      Sets the node text.
      Parameters:
      title - The text to be displayed on the node
      Returns:
      The treeview node
    • getTitle

      public String getTitle()
      Gets the node text
      Returns:
      Node text or null if there is no text set for the node
    • setIcon

      public TreeviewNode setIcon(Icon icon)
      Sets an icon for the node. This method sets an icon for the node, irrespective of its state (expanded, collapsed).
      Parameters:
      icon - The icon to be set for the node. Available icon are listed in the enum Icon.
      Returns:
      The treeview node
    • setIcon

      public TreeviewNode setIcon(Icon icon, String color)
      Sets an icon and its color for the node. This method sets an icon for the node, irrespective of its state (expanded, collapsed).
      Parameters:
      icon - The icon to be set for the node. Available icon are listed in the enum Icon.
      color - The color of the displayed icon as defined by the CSS3 standard
      Returns:
      The treeview node
    • getIcon

      public Icon getIcon()
      Gets the node icon.
      Returns:
      The node icon or null if no icon is set for the node
    • getIconColor

      public String getIconColor()
      Gets the node icon color.
      Returns:
      The node icon color in the specified format
    • setOpenIcon

      public TreeviewNode setOpenIcon(Icon icon)
      Sets the icon for an expanded node. The icon specified here is displayed only if the node is expanded.
      Parameters:
      icon - The icon to be displayed if the node is expanded. Available icon are listed in the enum Icon.
      Returns:
      The treeview node
    • setOpenIcon

      public TreeviewNode setOpenIcon(Icon icon, String color)
      Sets the icon for an expanded node and the icon color. The icon specified here is displayed only if the node is expanded.
      Parameters:
      icon - The icon to be displayed if the node is expanded. Available icon are listed in the enum Icon.
      color - The icon color as defined by the CSS3 standard
      Returns:
      The treeview node
    • setCloseIcon

      public TreeviewNode setCloseIcon(Icon icon)
      Sets the icon for a collapsed node. The icon specified here is displayed only if the node is collapsed.
      Parameters:
      icon - The icon to be displayed only if the node is collapsed. Available icon are listed in the enum Icon.
      Returns:
      The treeview node
    • setCloseIcon

      public TreeviewNode setCloseIcon(Icon icon, String color)
      Sets the icon for a collapsed node and its color. The icon specified here is displayed only if the node is expanded.
      Parameters:
      icon - The icon to be displayed only if the node is collapsed. Available icon are listed in the enum Icon.
      color - The icon color as defined by the CSS3 standard
      Returns:
      The treeview node
    • getOpenIcon

      public Icon getOpenIcon()
      Gets the icon for an expanded node.
      Returns:
      The icon for an expanded node or null if the icon is not displayed if the node is expanded
    • getOpenIconColor

      public String getOpenIconColor()
      Gets the icon color for an expanded node.
      Returns:
      The icon color for an expanded node in the specified format
    • getCloseIcon

      public Icon getCloseIcon()
      Gets the icon for a collapsed node.
      Returns:
      The icon for a collapsed node or null if no icon is displayed if the node is collapsed
    • getCloseIconColor

      public String getCloseIconColor()
      Gets the icon color for a collapsed node.
      Returns:
      The icon color for a collapsed node in the specified format
    • addChildNode

      public TreeviewNode addChildNode(TreeviewNode child)
      Adds a child to the current node. The node is automatically set as a parent to the child node specified here.
      Parameters:
      child - Child node instance
      Returns:
      The treeview node
    • addChildNodes

      public TreeviewNode addChildNodes(TreeviewNode... children)
      Adds multiple child nodes to the current node. The parent node is automatically set for all of the child nodes specified here.
      Parameters:
      children - An enumeration of all nodes to be added to the current node as children
      Returns:
      The treeview node
    • removeChildNode

      public TreeviewNode removeChildNode(String name)
      Removes a child from the node, referenced by the child node name. If no child is found by the specified name under the current node, the method does nothing.
      Parameters:
      name - The name of the child node to be removed
      Returns:
      The treeview node
    • removeChildNode

      public TreeviewNode removeChildNode(TreeviewNode node)
      Removes a child node from the current node. If the specified node is not the child of the current node, the method does nothing.
      Parameters:
      node - An instance of the node we want to remove from the node’s children
      Returns:
      The treeview node
    • removeChildNodes

      public TreeviewNode removeChildNodes(String... names)
      Removes multiple children from the current node by the specified names. If there is name among the specified name that is not a child of the current node, it is ignored.
      Parameters:
      names - An enumeration of all the names whose corresponding nodes we want to remove from the node’s children
      Returns:
      The treeview node
    • removeChildNode

      public TreeviewNode removeChildNode(TreeviewNode... nodes)
      Removes multiple chldren from the current node. If the enumeration contains a node that is not a child of the current node, it is ignored.
      Parameters:
      nodes - An enumeration of all nodes to be removed
      Returns:
      The treeview node
    • getChildNodes

      public Collection<TreeviewNode> getChildNodes()
      Gets all children of the current node.
      Returns:
      A collection of all children nodes of the current node or null if the current node has no children, that is, it is a leaf node.
    • getChildNode

      public TreeviewNode getChildNode(String name)
      Gets a child node by its name.
      Parameters:
      name - The name of the child node we want to get
      Returns:
      The child node corresponding to the specified name or null if the node by the specified name is not a child of the current node
    • isChecked

      public boolean isChecked()
      Determines if the node is checked.
      Returns:
      If true, the node is checked, otherwise false
    • isSelected

      public boolean isSelected()
      Determines if the node is selected.
      Returns:
      If true, the node is selected, otherwise false
    • setChecked

      public TreeviewNode setChecked(boolean checked)
      Sets the checkbox state for the current node.
      Parameters:
      checked - If true is set, the node is checked, otherwise not checked
      Returns:
      The treeview node
    • open

      public TreeviewNode open()
      Expands the current node and all containing parents.
      Returns:
      The treeview node
    • openCascade

      public final TreeviewNode openCascade()
      Expands the current node and all its children.
      Returns:
      The treeview node
    • close

      public TreeviewNode close()
      Collapses the node.
      Returns:
      The treeview node
    • closeCascade

      public final TreeviewNode closeCascade()
      Collapses the current node and all its children.
      Returns:
      The treeview node
    • getState

      public TreeviewNodeState getState()
      Gets the node state. (A node can have two states: expanded or collapsed.)
      Returns:
      The current state of the node
    • setState

      public final TreeviewNode setState(TreeviewNodeState state)
      Sets the node state.
      Parameters:
      state - The node state Available node states are listed in the enum TreeviewNodeState.
      Returns:
      The treeview node
    • addComponent

      public TreeviewNode addComponent(Component<?> component)
      Description copied from class: Component
      Adds the specified component as a subcomponent, and redraws the component immediately
      Overrides:
      addComponent in class Component<ListItem>
      Parameters:
      component - The component to be added
      Returns:
      The component
    • removeComponent

      public TreeviewNode removeComponent(Component<?> component)
      Description copied from class: Component
      Removes the specified subcomponent.
      Overrides:
      removeComponent in class Component<ListItem>
      Parameters:
      component - The component instance
      Returns:
      The component
    • getContent

      public Collection<Component<?>> getContent()
      Gets all components in a node.
      Returns:
      A collection of all components in a node. If the node contains no components, an empty collection is returned.
    • getSelectedChildNodes

      public List<TreeviewNode> getSelectedChildNodes()
      Gets all the checked children nodes.
      Returns:
      A list of all the checked children nodes If there are no checked children nodes, an empty list is returned.
    • hasChild

      public final boolean hasChild()
      Sets if the node contains any children.
      Returns:
      If true, the node has children, otherwise false
    • findFirst

      public final TreeviewNode findFirst(Predicate<TreeviewNode> filter)
      Looks up the first node corresponding to the specified criterion. This means if the node fulfils the specified criterion, the current node is returned, in all other cases the first node of the current one, fulfilling the criterion is returned, that is, either an immediate child or the child of some of the children.
      Parameters:
      filter - The predicate that the node must fulfil
      Returns:
      The first node fulfilling the specified predicate or null if there is no node fulfilling the predicate.
      Throws:
      NullPointerException - Thrown if the specified predicate is null
    • find

      public final List<TreeviewNode> find(Predicate<TreeviewNode> filter)
      Gets all children nodes fulfilling the specified predicate. The lookup returns not only the immediate children, but also the children of the children, fulfilling the specified predicate.
      Parameters:
      filter - The predicate that the nodes in the lookup must fulfil
      Returns:
      All children nodes fulfilling the specified predicate or an empty list if no children fulfil the specified predicate
    • showContent

      public final TreeviewNode showContent(boolean showContent)
      Displays or hides node content. The node’s content is not visible by default. The method is responsible for making the content visible or invisible.
      Parameters:
      showContent - If true is set, the node content is visible, otherwise invisible
      Returns:
      The treeview node
    • isContentShown

      public final boolean isContentShown()
      Sets if the node content is visible on the interface.
      Returns:
      If true, the content is displayed on the interface, otherwise false
    • highlightNode

      protected final TreeviewNode highlightNode(boolean highlight)
      Highlights the node.
      Parameters:
      highlight - If true is set, the node is highlighted, otherwise false
      Returns:
      The treeview node
    • setCurrent

      public final TreeviewNode setCurrent()
      Returns:
      The treeview node
    • addClickHandler

      public TreeviewNode addClickHandler(ClickEventHandler handler)
      Description copied from interface: Clickable
      Adds a single click event handler to the component. This handler runs when the user clicks once on the component.
      Parameters:
      handler - The ClickEventHandler implementation
      Returns:
      The component
      See Also:
    • addDoubleClickHandler

      public TreeviewNode addDoubleClickHandler(DoubleClickEventHandler handler)
      Description copied from interface: Clickable
      Adds a double click event handler to the component. This handler runs when the user clicks twice on the component.
      Parameters:
      handler - A DoubleClickEventHandler implementation
      Returns:
      The component
      See Also: