Class TreeModel

    • Field Summary

      Fields 
      Modifier and Type Field Description
      boolean allowsChildren
      flag used to determine if a node is a leaf or a folder.
    • Constructor Summary

      Constructors 
      Constructor Description
      TreeModel()
      Constructor to create an empty tree model with allowsChildren is true.
      TreeModel​(boolean allowsChildren)
      Constructor to create an empty tree model that use allowsChildren to determine the leaf node, if and only if allowsChildren is true.
      TreeModel​(Node root)
      Constructor to create a tree model with the specified root node and with allowsChildren is true.
      TreeModel​(Node root, boolean allowsChildren)
      Constructor to create a tree model with the specified root node and with the specified allowsChildren flag.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addNode​(Node parent, Node newNode)
      Method to add a node to the parent node at the specified position.
      void clear()
      Method to clear this model.
      Node getRoot()
      Method to return the root node of this tree model.
      void insertNode​(Node parent, Node newNode, int index)
      Method to insert a node to the parent node at the specified position.
      void modifyNode​(Node node, java.lang.Object userObject)
      Method to modify a node userObject and notify the tree of the changes.
      void reload()
      Method to notify the tree to reload.
      void removeNode​(Node parent, Node node)
      Method to remove a node from the tree.
      void setRoot​(Node root)
      Method to set the root node of this tree model and notify the tree to reload the tree.
      void setTree​(Tree tree)
      Method to set the tree (For internal use only) This method register the tree to this model, so when the user add, delete, or modify a node, the tree view will be notify and updated.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • allowsChildren

        public boolean allowsChildren
        flag used to determine if a node is a leaf or a folder.
    • Constructor Detail

      • TreeModel

        public TreeModel​(Node root,
                         boolean allowsChildren)
        Constructor to create a tree model with the specified root node and with the specified allowsChildren flag.
      • TreeModel

        public TreeModel​(Node root)
        Constructor to create a tree model with the specified root node and with allowsChildren is true.
      • TreeModel

        public TreeModel()
        Constructor to create an empty tree model with allowsChildren is true.
      • TreeModel

        public TreeModel​(boolean allowsChildren)
        Constructor to create an empty tree model that use allowsChildren to determine the leaf node, if and only if allowsChildren is true.
        Parameters:
        allowsChildren - true to use allowwsChildren to determine a leaf node.
    • Method Detail

      • setTree

        public void setTree​(Tree tree)
        Method to set the tree (For internal use only) This method register the tree to this model, so when the user add, delete, or modify a node, the tree view will be notify and updated.
        Parameters:
        tree - the tree (view) that is associated with this model.
      • clear

        public void clear()
        Method to clear this model.
      • reload

        public void reload()
        Method to notify the tree to reload.
      • getRoot

        public Node getRoot()
        Method to return the root node of this tree model.
        Returns:
        the root node of this tree model.
      • setRoot

        public void setRoot​(Node root)
        Method to set the root node of this tree model and notify the tree to reload the tree.
        Parameters:
        root - the new root node of this tree model.
      • insertNode

        public void insertNode​(Node parent,
                               Node newNode,
                               int index)
        Method to insert a node to the parent node at the specified position. This method will notify the associated tree to display the node, if the parent node is expanded. If the index out of range, the new node will be inserted at the end of the parent node children vector (consider, in this case, using the addNode method, which is faster).
        Parameters:
        parent - the parent node of the node to insert.
        newNode - the new node to insert into this tree model.
        index - the index to insert the node into
      • addNode

        public void addNode​(Node parent,
                            Node newNode)
        Method to add a node to the parent node at the specified position. This method will notify the associated tree to display the node, if the parent node is expanded. This is fastest than insertNode.
        Parameters:
        parent - the parent node of the node to insert.
        newNode - the new node to insert into this tree model.
      • removeNode

        public void removeNode​(Node parent,
                               Node node)
        Method to remove a node from the tree. This method will notify the tree to collapse the tree.
        Parameters:
        parent - the parent node of the node to remove.
        node - the node to remove from this tree model.
      • modifyNode

        public void modifyNode​(Node node,
                               java.lang.Object userObject)
        Method to modify a node userObject and notify the tree of the changes.
        Parameters:
        node - the node to modify.
        userObject - the new user object.