Interface TreeNodeModel<V>

Type Parameters:
V - The type of value contained in the tree node.
All Superinterfaces:
ActionListenable, ActionModel, Iterable<TreeNodeModel<?>>, Model, com.globalmentor.model.MutableValued<V>, com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, Selectable, com.globalmentor.model.Valued<V>, ValueModel<V>
All Known Implementing Classes:
DefaultTreeNodeModel, DummyTreeNodeModel, DynamicTreeNodeModel

public interface TreeNodeModel<V> extends ActionModel, ValueModel<V>, Selectable, Iterable<TreeNodeModel<?>>
A node in a tree model. Property change events and action events on one tree node will be bubbled up the hierarchy, with the tree node initiating the event accessible via TargetedEvent.getTarget().
Author:
Garret Wilson
  • Field Details

    • EXPANDED_PROPERTY

      static final String EXPANDED_PROPERTY
      The expanded bound property.
  • Method Details

    • isExpanded

      boolean isExpanded()
      Returns:
      Whether the node is expanded, showing its children, if any.
    • setExpanded

      void setExpanded(boolean newExpanded)
      Sets whether the node is expanded, showing its children, if any. This is a bound property of type Boolean.
      Parameters:
      newExpanded - true if the node is expanded.
      See Also:
    • setAllExpanded

      void setAllExpanded(boolean newAllExpanded)
      Sets whether all tree nodes, including this node, are expanded in this subtree.
      Parameters:
      newAllExpanded - true if all the nodes in this tree should be expanded, or false if they should be collapsed.
      See Also:
    • isLeaf

      boolean isLeaf()
      Determines whether this node could be considered a leaf node. This method may return false even if it currently has no children, if it intends to load them later and there is no way to know ahead of time if there will be children.
      Returns:
      true if this is a leaf node, else false if this node should not be considered a leaf.
    • hasChildren

      boolean hasChildren()
      Returns:
      Whether this tree node has children. This implementation delegates to the tree node list.
    • hasChild

      boolean hasChild(TreeNodeModel<?> treeNode)
      Determines whether this tree node contains the given child tree node.
      Parameters:
      treeNode - The tree node to check.
      Returns:
      true if this tree node contains the given tree node.
    • add

      void add(TreeNodeModel<?> treeNode)
      Adds a child tree node to this tree node.
      Parameters:
      treeNode - The tree node to add.
      Throws:
      IllegalArgumentException - if the tree node already has a parent.
    • remove

      void remove(TreeNodeModel<?> treeNode)
      Removes a child tree node from this tree node.
      Parameters:
      treeNode - The child tree node to remove.
      Throws:
      IllegalArgumentException - if the tree node is not a child of this tree node.
    • clear

      void clear()
      Removes all of the child tree nodes from this tree node.
    • getParent

      TreeNodeModel<?> getParent()
      Returns:
      The parent of this node, or null if this node has no parent.
    • setParent

      void setParent(TreeNodeModel<?> newParent)
      Sets the parent of this tree node. This method is managed by other tree nodes, and normally should not be called by applications. A tree node cannot be given a parent if it already has a parent. A tree node's parent cannot be removed this component is still a child of that parent. A tree node's parent cannot be set unless that parent already recognizes this tree node as one of its children. If a tree node is given the same parent it already has, no action occurs.
      Parameters:
      newParent - The new parent for this tree node, or null if this tree node is being removed from a parent.
      Throws:
      IllegalStateException - if a parent is provided and this tree node already has a parent.
      IllegalStateException - if no parent is provided and this tree node's old parent still recognizes this tree node as its child.
      IllegalArgumentException - if a parent is provided and the given parent does not already recognize this tree node as its child.
      See Also:
    • getDepth

      int getDepth()
      Returns the zero-based depth of the node within in its tree. This result represents the number of levels above this node needed to reach the root node.
      Returns:
      The zero-based depth of this node from the root.