Class DefaultTreeNodeModel<V>

java.lang.Object
com.globalmentor.beans.BoundPropertyObject
Type Parameters:
V - The type of value contained in the tree node.
All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, com.globalmentor.model.MutableValued<V>, com.globalmentor.model.Valued<V>, ActionListenable, ActionModel, Model, Selectable, TreeNodeModel<V>, ValueModel<V>, Iterable<TreeNodeModel<?>>
Direct Known Subclasses:
DummyTreeNodeModel, DynamicTreeNodeModel

public class DefaultTreeNodeModel<V> extends DefaultValueModel<V> implements TreeNodeModel<V>
A default 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
  • Constructor Details

    • DefaultTreeNodeModel

      public DefaultTreeNodeModel(Class<V> valueClass)
      Constructs a tree node model indicating the type of value it can hold.
      Parameters:
      valueClass - The class indicating the type of value held in the model.
      Throws:
      NullPointerException - if the given value class is null.
    • DefaultTreeNodeModel

      public DefaultTreeNodeModel(Class<V> valueClass, V initialValue)
      Constructs a tree node model indicating the type of value it can hold, along with an initial value.
      Parameters:
      valueClass - The class indicating the type of value held in the model.
      initialValue - The initial value, which will not be validated.
      Throws:
      NullPointerException - if the given value class is null.
  • Method Details

    • isExpanded

      public boolean isExpanded()
      Specified by:
      isExpanded in interface TreeNodeModel<V>
      Returns:
      Whether the node is expanded, showing its children, if any.
    • setExpanded

      public void setExpanded(boolean newExpanded)
      Description copied from interface: TreeNodeModel
      Sets whether the node is expanded, showing its children, if any. This is a bound property of type Boolean.
      Specified by:
      setExpanded in interface TreeNodeModel<V>
      Parameters:
      newExpanded - true if the node is expanded.
      See Also:
    • setAllExpanded

      public void setAllExpanded(boolean newAllExpanded)
      Description copied from interface: TreeNodeModel
      Sets whether all tree nodes, including this node, are expanded in this subtree.
      Specified by:
      setAllExpanded in interface TreeNodeModel<V>
      Parameters:
      newAllExpanded - true if all the nodes in this tree should be expanded, or false if they should be collapsed.
      See Also:
    • isSelected

      public boolean isSelected()
      Specified by:
      isSelected in interface Selectable
      Returns:
      Whether the object is selected.
    • setSelected

      public void setSelected(boolean newSelected)
      Description copied from interface: Selectable
      Sets whether the object is selected. This is a bound property of type Boolean.
      Specified by:
      setSelected in interface Selectable
      Parameters:
      newSelected - true if the object should be selected, else false.
      See Also:
    • getTreeNodeList

      protected List<TreeNodeModel<?>> getTreeNodeList()
      Returns:
      The list of child tree nodes.
    • iterator

      public Iterator<TreeNodeModel<?>> iterator()
      Specified by:
      iterator in interface Iterable<V>
    • isLeaf

      public boolean isLeaf()
      Description copied from interface: TreeNodeModel
      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.
      Specified by:
      isLeaf in interface TreeNodeModel<V>
      Returns:
      true if this is a leaf node, else false if this node should not be considered a leaf.
    • hasChildren

      public boolean hasChildren()

      This implementation delegates to the tree node list.

      Specified by:
      hasChildren in interface TreeNodeModel<V>
      Returns:
      Whether this tree node has children. This implementation delegates to the tree node list.
    • hasChild

      public boolean hasChild(TreeNodeModel<?> treeNode)
      Description copied from interface: TreeNodeModel
      Determines whether this tree node contains the given child tree node.
      Specified by:
      hasChild in interface TreeNodeModel<V>
      Parameters:
      treeNode - The tree node to check.
      Returns:
      true if this tree node contains the given tree node.
    • add

      public void add(TreeNodeModel<?> treeNode)
      Description copied from interface: TreeNodeModel
      Adds a child tree node to this tree node.
      Specified by:
      add in interface TreeNodeModel<V>
      Parameters:
      treeNode - The tree node to add.
    • remove

      public void remove(TreeNodeModel<?> treeNode)
      Description copied from interface: TreeNodeModel
      Removes a child tree node from this tree node.
      Specified by:
      remove in interface TreeNodeModel<V>
      Parameters:
      treeNode - The child tree node to remove.
    • clear

      public void clear()
      Description copied from interface: TreeNodeModel
      Removes all of the child tree nodes from this tree node.
      Specified by:
      clear in interface TreeNodeModel<V>
    • getParent

      public TreeNodeModel<?> getParent()
      Specified by:
      getParent in interface TreeNodeModel<V>
      Returns:
      The parent of this node, or null if this node has no parent.
    • setParent

      public void setParent(TreeNodeModel<?> newParent)
      Description copied from interface: TreeNodeModel
      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.
      Specified by:
      setParent in interface TreeNodeModel<V>
      Parameters:
      newParent - The new parent for this tree node, or null if this tree node is being removed from a parent.
      See Also:
    • getChildren

      public List<TreeNodeModel<?>> getChildren()
      Returns a list of children. This method along with setChildren(List) provides a children property for alternate children access.
      Returns:
      A list of tree node children in order.
      See Also:
    • setChildren

      public void setChildren(List<TreeNodeModel<?>> treeNodes)
      Sets the children in this container. This method along with getChildren() provides a children property for alternate children access.
      Parameters:
      treeNodes - The new children of this tree node in order.
      See Also:
    • getDepth

      public int getDepth()
      Description copied from interface: TreeNodeModel
      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.
      Specified by:
      getDepth in interface TreeNodeModel<V>
      Returns:
      The zero-based depth of this node from the root.
    • addActionListener

      public void addActionListener(ActionListener actionListener)
      Description copied from interface: ActionListenable
      Adds an action listener.
      Specified by:
      addActionListener in interface ActionListenable
      Parameters:
      actionListener - The action listener to add.
    • removeActionListener

      public void removeActionListener(ActionListener actionListener)
      Description copied from interface: ActionListenable
      Removes an action listener.
      Specified by:
      removeActionListener in interface ActionListenable
      Parameters:
      actionListener - The action listener to remove.
    • getActionListeners

      public Iterable<ActionListener> getActionListeners()
      Specified by:
      getActionListeners in interface ActionModel
      Returns:
      all registered action listeners.
    • performAction

      public void performAction()
      Description copied from interface: ActionModel
      Performs the action with default force and default option. An ActionEvent is fired to all registered ActionListeners. This method delegates to ActionModel.performAction(int, int).
      Specified by:
      performAction in interface ActionModel
    • performAction

      public void performAction(int force, int option)
      Description copied from interface: ActionModel
      Performs the action with the given force and option. An ActionEvent is fired to all registered ActionListeners.
      Specified by:
      performAction in interface ActionModel
      Parameters:
      force - The zero-based force, such as 0 for no force or 1 for an action initiated by from a mouse single click.
      option - The zero-based option, such as 0 for an event initiated by a mouse left button click or 1 for an event initiated by a mouse right button click.
    • fireActionPerformed

      protected void fireActionPerformed(int force, int option)
      Fires an action event to all registered action listeners. This method delegates to fireActionPerformed(ActionEvent).
      Parameters:
      force - The zero-based force, such as 0 for no force or 1 for an action initiated by from a mouse single click.
      option - The zero-based option, such as 0 for an event initiated by a mouse left button click or 1 for an event initiaged by a mouse right button click.
      See Also:
    • fireActionPerformed

      protected void fireActionPerformed(ActionEvent actionEvent)
      Fires a given action event to all registered action listeners.
      Parameters:
      actionEvent - The action event to fire.