sapientconceptions
asked on
JTree aggregation
I have a dynamic JTree that has numerous root nodes that appear as duplicates (via name), yet the children may be different. I'm interested in allowing the user to aggregate the tree so the root nodes only appear once, yet all the tree nodes appear under them -- without having to make additional calls to the backend to get the data again.
So for instance, if the tree looks like this
- User
+ Josh
+ Frank
+ Susan
- Admin
+ Tom
+ Dick
+ Harry
- User
+ Johnny
+ Rick
+ Dave
- Admin
+ Tommy
I'd like it to appear as follows:
- User
- User
+ Josh
+ Frank
+ Susan
- User
+ Johnny
+ Rick
+ Dave
- Admin
- Admin
+ Tom
+ Dick
+ Harry
- Admin
+ Tommy
So for instance, if the tree looks like this
- User
+ Josh
+ Frank
+ Susan
- Admin
+ Tom
+ Dick
+ Harry
- User
+ Johnny
+ Rick
+ Dave
- Admin
+ Tommy
I'd like it to appear as follows:
- User
- User
+ Josh
+ Frank
+ Susan
- User
+ Johnny
+ Rick
+ Dave
- Admin
- Admin
+ Tom
+ Dick
+ Harry
- Admin
+ Tommy
ASKER
can you provide an example?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for you help. But this didn't help me at all. I'm hoping someone can provide me the methods for re-arranging the children from one parent to another.
Thanks.
Thanks.
do u actually need both views?
ASKER
yes...
is the data dynamic or static?
ASKER
Data is dynamic. But only two levels are initially populated with the original tree ("User/Admin" and their children). So I'd like to iterate through the tree check a list to see if the node's value exists (i.e. User) if not, add node to new tree and map (record position in new tree), then add current node & children from original tree as child of newly added node to new tree.
Repeat, however if node exists in list, then find position of node in new tree and add node and kids to that parent node in tree.
hope that makes sense.
Repeat, however if node exists in list, then find position of node in new tree and add node and kids to that parent node in tree.
hope that makes sense.
you could do that ie maintain two seperate tree models externally, or use the approach I suggested above to have the alternate view wrap your existing model and handle the mapping.
Either way it's fairly involved, but am happy to help when you have problems.
Either way it's fairly involved, but am happy to help when you have problems.
The second approach should be cleaner.