Package totalcross.ui.tree
Class TreeModel
- java.lang.Object
-
- totalcross.ui.tree.TreeModel
-
public class TreeModel extends java.lang.ObjectThis class holds the tree structure that the Tree class used to render the tree widget. Note: you should use this class to mofidy the tree after the root node is setted to this model; otherwise, the tree will reflect the change visually; a faster option for bulk inserts is to use the node's add/insert methods and then do a reload.
-
-
Field Summary
Fields Modifier and Type Field Description booleanallowsChildrenflag 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 voidaddNode(Node parent, Node newNode)Method to add a node to the parent node at the specified position.voidclear()Method to clear this model.NodegetRoot()Method to return the root node of this tree model.voidinsertNode(Node parent, Node newNode, int index)Method to insert a node to the parent node at the specified position.voidmodifyNode(Node node, java.lang.Object userObject)Method to modify a node userObject and notify the tree of the changes.voidreload()Method to notify the tree to reload.voidremoveNode(Node parent, Node node)Method to remove a node from the tree.voidsetRoot(Node root)Method to set the root node of this tree model and notify the tree to reload the tree.voidsetTree(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.
-
-
-
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.
-
-