I've been able to work out #1 and #2, but #3 is still giving me
issues.
Here is my code for #1 and #2 if anyone else is having problems and
needs this for reference:
This one can be called using
closeAllTreeNodes(tree.getRootTreeNode());
It is actually efficient enough because it will immediately return
when children are already closed (rather than traverse children of
closed children)
private void closeAllTreeNodes(TreeNode node) {
if(node == null) {
return;
}
for(int i = 0; i < node.getChildCount(); i++) {
TreeNode child = node.setChildOpen(i, false);
closeAllTreeNodes(child);
}
}
This one uses a custom object I use called TableOfContentsTreeNode,
but it can be adapted for your own uses, I'm sure. One thing to note
is that my custom TreeNode is not for display: it is the tree
structure I use to power the CellTree.
The parameter pageUrl is just an identifier I use to tell which node
is the node I want to jump to.
private void jumpToEntry(String pageUrl) {
List<TableOfContentsTreeNode> parentList =
treeModel.getParentList(pageUrl);
TreeNode current = tree.getRootTreeNode();
for(int i = 0; i < parentList.size(); i++) {
current =
current.setChildOpen(parentList.get(i).childIndex, true,
true);
}
System.out.println(current.getParent().getValue());
}
And these functions are in my custom tree model class
public List<TableOfContentsTreeNode> getParentList(String pageUrl) {
if(!itemLoaded(pageUrl)) {
return null;
}
List<TableOfContentsTreeNode> parents = new
ArrayList<TableOfContentsTreeNode>();
//Add the actual page
parents.add(items.get(pageUrl));
return addParentList(parents);
}
//Recursion ftw!
private List<TableOfContentsTreeNode>
addParentList(List<TableOfContentsTreeNode> parents) {
if(parents.get(0).parent == null) {
//The root of the tree isn't really a real node (it is a
placeholder), so don't return it.
parents.remove(0);
return parents;
}
parents.add(0, parents.get(0).parent);
return addParentList(parents);
}
---------
I can't seem to figure out a good way to actually scroll to the
specific node in the tree (ie. #3).
Thanks for taking a look :)
--Andrew
On Mar 11, 1:02 pm, aarnott <[email protected]> wrote:
> I'm having a bit of difficulty writing some code to traverse a
> CellTree. Here is my goal:
>
> 1. I want to first close all of the TreeNodes in the CellTree. There
> doesn't seem to be an efficient way to do this besides literally
> looping through the entire tree structure.
>
> 2. I have a separate model for the tree in memory and I I want to open
> the tree all the way up to a particular node. For example:
>
> If my tree was
>
> A->B->D->F
> ->C->E->G
>
> And I wanted it to open to node D, I would close all of the nodes, and
> then open A and B (making D visible).
>
> ----
>
> This would seem simple enough, but it is giving me a lot of trouble.
> My tree model can easily just return a list of all the parent nodes
> leading up to the node I want to open. The problem is, the TreeNode
> object doesn't really contain any relevant information for me to tell
> which node is which.
>
> 3. The tree is in a ScrollPanel and I want to have it scroll so that
> the Node from #2 is in view.
>
> Any suggestions of how to do this would be greatly appreciated!
>
> Thanks,
>
> Andrew Arnott
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.