codeguru
codeguru

Reputation: 193

identifying nodes of a tree in gwt

I have a tree widget and I am adding treeitems and several sub nodes to this treeitems dynamically on a click of a button.

I am using addtreeitem () method. For example I have created a tree which has a level 1. Level 1 inturn has three level 2s.

And now I have to add a level 3 to the first level 2. As I am doing this dynamically, level 3 is getting added to the last level 2.

How can I identify each node distinctly? As per my requirement, I can have any number of nodes like this. There is no limit.

On the click of the same button, I have to properly identify under which treeitem I am supposed to add a child item.

Upvotes: 0

Views: 65

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

You can use TreeItem#setUserObject method to associate tree items with some data. It can be an object from your data model, or it can be a simple String. Something like:

treeItem.setUserObject("shoes");

or

treeItem.setUserObject(ProductCategory.SHOES);

Then you traverse the Tree and use TreeItem#getUserObject method to identify each item.

Upvotes: 1

Related Questions