cancel
Showing results for 
Search instead for 
Did you mean: 

Sample code on Tree UI element for the following requirements

Former Member
0 Kudos

Hi All

I have populated the Tree UI element as follows as an example

A
 A1
 A2
 A3
B
 B1
 B2
 B3
C
 C1
 C2
 C3
D 
 D1
 D2
 D3	 	

i have the following requirements on Tree UI element

a) How to check or how to write the code to check whether the current selected node is first level or second level or third level etc from the above example tree structure.

b) How to insert a node only at the first level , second level and third level i etc from the above example

c) How to delete only leaf node . i have a requirement which says that i can delete only leaf nodes , if i delete a node which having children then it should not allow to me. i can delete a node which is not having any child

4) How to rename any node, once user selects any node then on click of any button then popup opens which retrieves the current textvalue of a node and user have an inputfield where he enters then on click of save then that new textvalue needs to be updated to the selected tree element

If anybody helps in this regard then it would be great help to me.

Thanks in advance

Regards

Kalki reddy

Edited by: KalkiReddy on Nov 23, 2009 4:18 PM

Edited by: KalkiReddy on Nov 23, 2009 4:19 PM

Accepted Solutions (0)

Answers (1)

Answers (1)

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi

>a) How to check or how to write the code to check whether the current selected node is first level or second level or third level etc from the above example tree structure

In the context node you have to have attribute level (integer). When you populate context nodes for the tree you have to set correct value 0, 1, 2, ... for the attribute. Then it'll be easy for you to read the value and understand what is the level.

>b) How to insert a node only at the first level , second level and third level i etc from the above example

It slightly depends on whether you use recursive nodes or not. But in general it's simple - just create a new element in the corresponding node

>c) How to delete only leaf node . i have a requirement which says that i can delete only leaf nodes , if i delete a node which having children then it should not allow to me. i can delete a node which is not having any child

IWDNode node;
if (node.getChild("<child node name>").size() <= 0) {
// leaf node
}

>4) How to rename any node, once user selects any node then on click of any button then popup opens which retrieves the current textvalue of a node and user have an inputfield where he enters then on click of save then that new textvalue needs to be updated to the selected tree element

Just bind the text property of a tree item to some node attribute (let say NAME). The just update a value of the attribute.

BR, Siarhei

Former Member
0 Kudos

Hi,

You can find the code example of Tree UI element and explanation of the Tree API when you right click the Tree UI element which you have inserted in your view in your NWDS and click on Show Help.

Regards,

Meenakshi