You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rob Decker <ro...@objectsource.org> on 2005/03/24 23:45:41 UTC

Tree2 nodes

Ok, the exception in my last message was caused by the fact that I had my TreeBacker 
class implement List. So before I go throught implementing this I'd like to at least 
feel if this sounds reasonably workable with the tree2 component. 

What I want to do is create a wrapper around my data so I want to implement TreeNode, 
List, Iterator in a special wrapper class. Then when TreeBacker.getTreeData is called 
I want to return this wrapper as my TreeNode. I was trying to do it with TreeBacker 
and having getTreeData return 'this' but since I can't currently implement List using 
that class (and it appears to instantiate a new TreeBacker for each branch) I guess I 
have to create a separate class.

The reason I want to do this is because I don't want do this:

TreeNode base = new TreeNodeBase("branch", "root", "0", false);
List l = getMyObjects();
Iterator i = l.iterator();
while (i.hasNext()) {
    MyObject o = (MyObject)i.next();
    String type = (o.hasChildren()) ? "branch" : "leaf";
    TreeNode node = new TreeNodeBase(type, o.getDescription(), new String(o.getId()), 
(type.equals("leaf")));
    recurseOn(o.getChildren());
    base.getChildren().add(node);
}

for all of my objects. I'd like just create an adapter using the TreeNode interface 
and go:

new MyTreeNodeImpl(getMyFirstLevelObjectList()) and then return that for the TreeNode 
and internally retrieve the children when someone clicks on a branch and return the 
interface requests by looking at my object. 

Does this sound like something tree2 is capable of handling? Or am I expected to use 
TreeNodeBase? It would also be really neat if I can access MyObject from the TreeNode 
interface so I can display additional data from it if I want to: TreeNode.getObject() 
but I can live with the server-side pull if that'll work.


--
Rob

@objectsource.org


Re: Tree2 nodes

Posted by Sean Schofield <se...@gmail.com>.
Rob,

You've touched on a subject that has come up recently on the dev list.
 I will describe the situation as it is now:

Your tree data must implement TreeNode interface.  You can use
TreeNodeBase or some other class of your own that implements TreeNode
interface.  An adapter class would be a perfectly acceptable
alternative.

Tree2 actually uses a class called TreeModel.  This class takes your
root node (that implements TreeNode) in its constructor.  You cannot
currently set the TreeModel value.  The idea was that most data comes
from a database (or directory server) and you can just as easily put
it in a TreeNodeBase object (or custom object) as you could in any
other form.  So the current design shields the user from the extra
requirements of TreeModel.

It sounds like in your case (and the case of a few others) it might
also be helpful to allow the user to specify the TreeModel as well. 
So that way you could have the option of building your tree data using
the current method, or provide a class that implements TreeModel.  So
we could turn TreeModel into an interface and provide a
DefaultTreeModel for the case where the user only wants to provide
TreeNode data.

If someone would like to provide a patch for this, I'd be happy to take a look.

sean


On Thu, 24 Mar 2005 17:45:41 -0500, Rob Decker <ro...@objectsource.org> wrote:
> 
> Ok, the exception in my last message was caused by the fact that I had my TreeBacker
> class implement List. So before I go throught implementing this I'd like to at least
> feel if this sounds reasonably workable with the tree2 component.
> 
> What I want to do is create a wrapper around my data so I want to implement TreeNode,
> List, Iterator in a special wrapper class. Then when TreeBacker.getTreeData is called
> I want to return this wrapper as my TreeNode. I was trying to do it with TreeBacker
> and having getTreeData return 'this' but since I can't currently implement List using
> that class (and it appears to instantiate a new TreeBacker for each branch) I guess I
> have to create a separate class.
> 
> The reason I want to do this is because I don't want do this:
> 
> TreeNode base = new TreeNodeBase("branch", "root", "0", false);
> List l = getMyObjects();
> Iterator i = l.iterator();
> while (i.hasNext()) {
>    MyObject o = (MyObject)i.next();
>    String type = (o.hasChildren()) ? "branch" : "leaf";
>    TreeNode node = new TreeNodeBase(type, o.getDescription(), new String(o.getId()),
> (type.equals("leaf")));
>    recurseOn(o.getChildren());
>    base.getChildren().add(node);
> }
> 
> for all of my objects. I'd like just create an adapter using the TreeNode interface
> and go:
> 
> new MyTreeNodeImpl(getMyFirstLevelObjectList()) and then return that for the TreeNode
> and internally retrieve the children when someone clicks on a branch and return the
> interface requests by looking at my object.
> 
> Does this sound like something tree2 is capable of handling? Or am I expected to use
> TreeNodeBase? It would also be really neat if I can access MyObject from the TreeNode
> interface so I can display additional data from it if I want to: TreeNode.getObject()
> but I can live with the server-side pull if that'll work.
> 
> --
> Rob
> 
> @objectsource.org
> 
>