Class DefaultTreeNodeModel<V>

  • 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>, java.lang.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 Summary

      Constructors 
      Constructor Description
      DefaultTreeNodeModel​(java.lang.Class<V> valueClass)
      Constructs a tree node model indicating the type of value it can hold.
      DefaultTreeNodeModel​(java.lang.Class<V> valueClass, V initialValue)
      Constructs a tree node model indicating the type of value it can hold, along with an initial value.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(TreeNodeModel<?> treeNode)
      Adds a child tree node to this tree node.
      void addActionListener​(ActionListener actionListener)
      Adds an action listener.
      void clear()
      Removes all of the child tree nodes from this tree node.
      protected void fireActionPerformed​(int force, int option)
      Fires an action event to all registered action listeners.
      protected void fireActionPerformed​(ActionEvent actionEvent)
      Fires a given action event to all registered action listeners.
      java.lang.Iterable<ActionListener> getActionListeners()  
      java.util.List<TreeNodeModel<?>> getChildren()
      Returns a list of children.
      int getDepth()
      Returns the zero-based depth of the node within in its tree.
      TreeNodeModel<?> getParent()  
      protected java.util.List<TreeNodeModel<?>> getTreeNodeList()  
      boolean hasChild​(TreeNodeModel<?> treeNode)
      Determines whether this tree node contains the given child tree node.
      boolean hasChildren()
      boolean isExpanded()  
      boolean isLeaf()
      Determines whether this node could be considered a leaf node.
      boolean isSelected()  
      java.util.Iterator<TreeNodeModel<?>> iterator()  
      void performAction()
      Performs the action with default force and default option.
      void performAction​(int force, int option)
      Performs the action with the given force and option.
      void remove​(TreeNodeModel<?> treeNode)
      Removes a child tree node from this tree node.
      void removeActionListener​(ActionListener actionListener)
      Removes an action listener.
      void setAllExpanded​(boolean newAllExpanded)
      Sets whether all tree nodes, including this node, are expanded in this subtree.
      void setChildren​(java.util.List<TreeNodeModel<?>> treeNodes)
      Sets the children in this container.
      void setExpanded​(boolean newExpanded)
      Sets whether the node is expanded, showing its children, if any.
      void setParent​(TreeNodeModel<?> newParent)
      Sets the parent of this tree node.
      void setSelected​(boolean newSelected)
      Sets whether the object is selected.
      • Methods inherited from class com.globalmentor.beans.BoundPropertyObject

        addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from interface com.globalmentor.beans.PropertyBindable

        addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
      • Methods inherited from interface com.globalmentor.beans.PropertyConstrainable

        addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, hasVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
    • Constructor Detail

      • DefaultTreeNodeModel

        public DefaultTreeNodeModel​(java.lang.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:
        java.lang.NullPointerException - if the given value class is null.
      • DefaultTreeNodeModel

        public DefaultTreeNodeModel​(java.lang.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:
        java.lang.NullPointerException - if the given value class is null.
    • Method Detail

      • 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:
        TreeNodeModel.EXPANDED_PROPERTY
      • 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:
        TreeNodeModel.setExpanded(boolean)
      • 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:
        Selectable.SELECTED_PROPERTY
      • getTreeNodeList

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

        public java.util.Iterator<TreeNodeModel<?>> iterator()
        Specified by:
        iterator in interface java.lang.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>
      • 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:
        TreeNodeModel.add(TreeNodeModel), TreeNodeModel.remove(TreeNodeModel)
      • getChildren

        public java.util.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:
        iterator()
      • setChildren

        public void setChildren​(java.util.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:
        clear(), add(TreeNodeModel)
      • 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.
      • 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:
        ActionListener, ActionEvent
      • fireActionPerformed

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