I agree 100%, most likely one will extend TreeNode/TreeBranch in most cases. By the way, great work on the API's of Pivot - they are really nice and clean. I also like that you have put the adapter classes inside the interfaces - smart move :)

-- Edvin

Den 06.05.2011 14:36, skrev Greg Brown:
You mean, why isn't the userData property generic? No particular reason - that 
idea never came up. But honestly, I think making the entire class a generic 
might be a bit too verbose.

TreeNode<MyObject>  treeNode = new TreeNode<MyObject>();

vs.

TreeNode treeNode = new TreeNode();

User data is really just a minor convenience. Many apps that use tree views are 
likely to implement their own node and branch classes and wouldn't benefit from 
it anyways. I could potentially see an argument for parameterizing the 
getUserData() method, though.

On May 6, 2011, at 8:25 AM, Edvin Syse wrote:

OK. I think I'll start by wrapping my objects in TreeNode and TreeBranch and 
see how it goes. Can I ask why you didn't add generics to these objects? It 
would be nice to be able to do:

TreeNode<MyObject>  node = new TreeNode<MyObject>();
node.setUserData(instanceOfMyObject)


...

MyObject myObject = node.getUserData()

-- Edvin

Den 06.05.2011 14:16, skrev Greg Brown:
If a node implements org.apache.pivot.collections.List, it is considered a 
branch. Otherwise, it is a leaf.

On May 6, 2011, at 8:06 AM, Edvin Syse wrote:

ListAdapter was nice, thanks :)

But how do I express what is supposed to be Leaf nodes and what to be Branch 
nodes?

-- Edvin

Den 06.05.2011 13:49, skrev Greg Brown:
Have you looked at org.apache.pivot.collections.adapter.ListAdapter? You might 
be able to use this in conjunction with TreeViewBranchListener to construct 
your tree nodes from your backing data structure on demand.

G


On May 6, 2011, at 7:31 AM, Edvin Syse wrote:

I have a tree-structure represented by a list of domain objects. Some of the domain 
objects have a "children" property with a java.util.List of children. The 
TreeView#setTreeData method takes a org.apache.pivot.collections.List, and I figured I 
could do:

setTreeData(new ArrayList(myJavaUtilListList.toArray()));

This works so that I can see the first level of nodes, but I don't know how to 
express branch nodes. Also, I would like to lazy load some of the nodes. I 
think I need to use the TreeViewBranchListener somehow, but I can't find any 
documentation or examples.

Do I need to wrap all my domain objects in TreeNodes or is there another way to 
do this?

-- Edvin



Reply via email to