Based of Path how to get TreeBranch or TreeNode

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Based of Path how to get TreeBranch or TreeNode

Santosh
Hi,

In using TreeView (checked) i was able to get paths for Checked TreeBranches and TreeNodes asĀ 
Sequence<Path> paths = treeView.getCheckedPaths();

Now i want to test whether these paths are of TreeBranches or TreeNodes?
Because i want to restrict the selection of tree nodes to some number.

So is there any way of doing this?

--
Thanks & Regards
B.S.V.S.Pavan Raju.
Skype: skype_pavan1
Hyderabad.
santosh pavan raju
Reply | Threaded
Open this post in threaded view
|

RE: Based of Path how to get TreeBranch or TreeNode

Roger Whitcomb-2

I think what you will need to do is this:

·         Get the root of your tree data as “treeRoot” (for instance, by doing: “TreeBranch treeRoot = (TreeBranch)treeView.getTreeData();”

·         Iterate through the sequence of paths that are checked (returned from “getCheckedPaths()”.

·         For each path in the list, call “Sequence.Tree.get(treeRoot, path)” to get the node at that path

·         Then check the type of the node (you could use “if (node instanceof TreeBranch)” for instance) to see if it is a branch or a leaf node.

 

HTH,

~Roger Whitcomb

 

From: V SANTOSH PAVAN RAJU Bs [mailto:[hidden email]]
Sent: Monday, July 01, 2013 5:38 AM
To: [hidden email]
Subject: Based of Path how to get TreeBranch or TreeNode

 

Hi,

 

In using TreeView (checked) i was able to get paths for Checked TreeBranches and TreeNodes as 

Sequence<Path> paths = treeView.getCheckedPaths();

 

Now i want to test whether these paths are of TreeBranches or TreeNodes?

Because i want to restrict the selection of tree nodes to some number.

 

So is there any way of doing this?

 

--
Thanks & Regards

B.S.V.S.Pavan Raju.

Skype: skype_pavan1

Hyderabad.

Reply | Threaded
Open this post in threaded view
|

RE: Based of Path how to get TreeBranch or TreeNode

Santosh
Thank you Roger, its working.

Now how can i get the all the leaf nodes under the selected TreeBranch.
Also how to make leaf node selection from java code. Like treeNode.setSelected(true / false);

Can you help me in this regard ?
santosh pavan raju
Reply | Threaded
Open this post in threaded view
|

RE: Based of Path how to get TreeBranch or TreeNode

Roger Whitcomb-2
Hi Santosh,
        That's good.  So, if you have a TreeBranch object, you can get
the leaf nodes under it this way (since TreeBranch implements the
Sequence<TreeNode> and Iterable<TreeNode> interfaces:

        TreeBranch branch = ... however you got it
        for (TreeNode leaf : branch) {
                .... process the "leaf"
        }

Then, to select the leaf node from Java, you would need to get the path
of the node (starting from the root) and then tell the TreeView to
select it, something like this:

        treeView.clearSelection(); // assuming you want to select
just the leaf nodes under this branch
        TreeBranch treeRoot = (TreeBranch)treeView.getTreeData();
        for (TreeNode leaf : branch) {
                Sequence.Tree.Path leafPath =
Sequence.Tree.pathOf(treeRoot, leaf);
                treeView.addSelectedPath(leafPath);
        }

HTH,
~Roger Whitcomb
Reply | Threaded
Open this post in threaded view
|

RE: Based of Path how to get TreeBranch or TreeNode

Santosh
Hi Roger,

I made a mistake of saying node selection.
The process you told was working correctly. I see all the leaf nodes are selected, under a checked TreeBranch. But this is not exactly what i need. As iam using TreeView (Checked - with a Checkbox associated to all the nodes), i want the leaf nodes to be checked / unchecked.

As i was able to get the leaf nodes path under a checked TreeBranch as:

for (TreeNode node : branch) {
        Sequence.Tree.Path leafPath = Sequence.Tree.pathOf(treeRoot, node);
        //treeView.addSelectedPath(leafPath); // This makes the particular leaf node selection.
}

With the leaf node path how to check it or uncheck it.
santosh pavan raju
Reply | Threaded
Open this post in threaded view
|

Re: Based of Path how to get TreeBranch or TreeNode

Roger and Beth Whitcomb
Ah, then what you would do is this:
treeView.setNodeChecked(leafPath, true);

~Roger

On 7/10/13 11:28 PM, Santosh wrote:

> Hi Roger,
>
> I made a mistake of saying node selection.
> The process you told was working correctly. I see all the leaf nodes are
> selected, under a checked TreeBranch. But this is not exactly what i need.
> As iam using TreeView (Checked - with a Checkbox associated to all the
> nodes), i want the leaf nodes to be checked / unchecked.
>
> As i was able to get the leaf nodes path under a checked TreeBranch as:
>
> for (TreeNode node : branch) {
> Sequence.Tree.Path leafPath = Sequence.Tree.pathOf(treeRoot, node);
> //treeView.addSelectedPath(leafPath); // This makes the particular leaf
> node selection.
> }
>
> With the leaf node path how to check it or uncheck it.
>
>
>
> -----
> santosh pavan raju
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Based-of-Path-how-to-get-TreeBranch-or-TreeNode-tp4022629p4022633.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Based of Path how to get TreeBranch or TreeNode

Santosh
Thank you Roger.
Its all good now.
santosh pavan raju