tree = createTree();
//Try and load the already stored nodes from the session.
//If this is the first time we access the page, this method
//will return null, indicating no nodes is stored.
TreeNode existingRootNode = loadNodesFromSession();
if(existingRootNode != null) {
//OK we had already nodes stored in the session, so no need
//to rebuild them. We attach the root node and return.
tree.setRootNode(existingRootNode);
return tree;
}
//Create a node representing the root directory with the specified
//parameter as the value. Because an id is not specified, a random
//one will be generated by the node. By default the root node is
//not rendered by the tree. This can be changed by calling
//tree.setRootNodeDisplayed(true).
TreeNode root = new TreeNode("c:");
//Create a new directory, setting the root directory as its parent. Here
//we do specify a id as the 2nd argument, so no id is generated.
TreeNode dev = new TreeNode("dev","1", root);
//The follwing 2 nodes represent files in the directory, setting the
//dev node as their parent. Note the false argument to the constructor.
//This means that the specific node does not support child nodes, and
//it will be rendered as a leaf icon. If children are supported (the
//default value) then even if the node is a leaf, it will still be rendered
//as a collapsed icon. In the example a default leaf node will be
//rendered as a directory, and a node that does not support children is
//rendered as a file.
new TreeNode("java.pdf", "2", dev, false);
new TreeNode("ruby.pdf", "3", dev, false);
//We continue constructing the rest of the tree
TreeNode programFiles = new TreeNode("program files", "4", root);
new TreeNode("Adobe", "5", programFiles);
TreeNode download = new TreeNode("downloads","6", root);
TreeNode web = new TreeNode("web", "7", download);
new TreeNode("html.pdf", "8", web, false);
new TreeNode("css.html", "9", web, false);
TreeNode databases = new TreeNode("databases", "10", download);
new TreeNode("mysql.html","11",databases, false);
new TreeNode("oracle.pdf","12",databases, false);
new TreeNode("postgres","13",databases, false);
//Attach the root node containing all the other nodes to the tree
tree.setRootNode(root);
//By default root node is not displayed in browser. Here we expand it,