TreePath in CheckBoxTree

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

TreePath in CheckBoxTree

Postby nick.denton » Wed Jan 18, 2012 10:30 am

Hi,
I have a problem to receive all the paths when all the nodes of a Parent are selected.
What I mean is : If the parent node has 3 kids and all the kids are selected, then by using something like that:
TreePath[] treePaths = myTree.getCheckBoxTreeSelectionModel().getSelectionPaths();

I am receiving only the path for the parent node.

But if one of the kids is not selected I am receiving the path of the two selected kids.

So my question is is there any way to receive the path for all the selected, nodes that are leafs?

Thanks
nick.denton
 
Posts: 7
Joined: Wed Nov 16, 2011 6:02 pm

Re: TreePath in CheckBoxTree

Postby JIDE Support » Wed Jan 18, 2012 10:56 am

That's the default behavior when isDigIn() returns false. When a parent node is selected, all its descendant nodes are selected.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: TreePath in CheckBoxTree

Postby nick.denton » Thu Jan 19, 2012 5:54 am

Thanks for the answer.

But I know that when a parent node is selected all its descendant nodes are selected.
My question is how I can get the paths of all the selected nodes that are leafs (they don't have descendant nodes). But keeping the DigIn true.

Thanks
nick.denton
 
Posts: 7
Joined: Wed Nov 16, 2011 6:02 pm

Re: TreePath in CheckBoxTree

Postby JIDE Support » Thu Jan 19, 2012 8:15 am

In dig in mode, you'll have to iterate the selected parent node to get all its descendant nodes. You could also try to invoke setDigIn(false) so that whatever node is selected, it is appeared in the CheckBoxTreeSelectionModel#getSelectionPaths().

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: TreePath in CheckBoxTree

Postby nick.denton » Thu Jan 19, 2012 12:35 pm

Sorry but I don't get it.
Lets say I have this tree:
Code: Select all
                     A
                 B      C
              D  E   F  G
           H   I

And the nodes (leafs) that are selected are H, I, F E, and G
How I will get the path for all of them? So if i press a button will print:
ABE
ABDH
ABDI
ACF
ACG

I cant see any function that will return me the selected nodes so i can iterate.
Can you provide a working simple example?

Thanks in advance
nick.denton
 
Posts: 7
Joined: Wed Nov 16, 2011 6:02 pm

Re: TreePath in CheckBoxTree

Postby JIDE Support » Thu Jan 19, 2012 3:29 pm

In your case, you will get just A or root from the getSelectionPaths(). You will then have to find A's children, B & C. Since B & C are not leaf nodes, keep digging it deeper to D/E/F/G. Keep going until all leaf nodes are navigated. Evemtually you will get the list you want, i.e., ABDH, ABDI, ABE, ACF, ACG.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: TreePath in CheckBoxTree

Postby nick.denton » Fri Jan 20, 2012 4:15 am

Thanks, I understood that.
But how you iterate in a checkboxtree? I cant find a method

Thanks
nick.denton
 
Posts: 7
Joined: Wed Nov 16, 2011 6:02 pm

Re: TreePath in CheckBoxTree

Postby JIDE Support » Fri Jan 20, 2012 7:52 am

Actually those methods are provided by native Swing.

Please invoke TreePath#getLastPathComponent() to get the last path component of the selected path. The last component should be an instance of DefaultMutableTreeNode. Please then invoke DefaultMutableTreeNode#getChildAt()/getChildCount() to get its children nodes.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 10 guests