View Full Version : getting nodes from treePanel

23 Oct 2009, 4:45 AM
I'd like to change icon of a treePanel node after execution of some functions. How can I retrieve treePanel node outside the listener?

26 Oct 2009, 1:36 AM
Can someone help? I have to change icon of the leaf(each leaf is a map) when the map is loaded. In the beginning each leaf has to have icon telling that the map is not loaded and then after the map had loaded I have to change the icon of the responding leaf. That's the problem how to change the icon of a one leaf, not every leaf in a node.

27 Oct 2009, 5:02 AM
Hoi Tomek ...

how about adding a ModelIconProvider?

public class DCModelElementTreeNodeRenderer implements ModelIconProvider<ModelData> {

* Default constructor initializing mandatory fields.
public DCModelElementTreeNodeRenderer() {

* {@inheritDoc}
public AbstractImagePrototype getIcon(ModelData inModelData) {

// Get the user object or whatever you need tro interpret.
AbstractModelElementWrapper aUserObject = ((DCTreeNode) inModelData).getUserObject();

// First make sure that we do not have any messages.
if (aUserObject.hasErrors()) {
return IconHelper.create("g-resources/message/type/error.gif");
} else if (aUserObject.hasWarnings()) {
return IconHelper.create("g-resources/message/type/warning.gif");
} else if (aUserObject.hasInfos()) {
return IconHelper.create("g-resources/message/type/information.gif");
}// else if

// Render the icon.
if (aUserObject instanceof DomainModelWrapper) {
return IconHelper.create("g-resources/model/type/domain_model.png");
} else if (aUserObject instanceof ModelCollectionWrapper) {
return IconHelper.create("g-resources/model/type/model_collection.png");
} else if (aUserObject instanceof ModelWrapper) {
return IconHelper.create("g-resources/model/type/model.gif");
} else if (aUserObject instanceof AttributeWrapper || aUserObject instanceof StateModelWrapper) {
return IconHelper.create("g-resources/model/type/attribute.gif");
} else {
return IconHelper.create("g-resources/model/type/unknown_obj.gif");
}// else if

In the sample above the DCTreeNode is an own implementation BaseTreeModel ("extends").

Of course: the drawback you will have is that you need a sort of display model holding state that can be interpreted by your icon provider ...

Good luck.

27 Oct 2009, 5:15 AM
Thanks Arthy for your interest:) ModelIconProvider is the second case, first of all I have to somehow get one leaf from the store and update it with a new icon. I've struggled a few days with it and still haven't found solution. Oh I see that you had the same problem (in your thread). How did you update the node in a treeStore?

27 Oct 2009, 6:12 AM
The idea of the Icon provider is to render all icons for you in the tree. Thus the tree must know what icon to render when he intends to render the node (i.e. because overlayn parts of the tree now are visible again). Thus you have to provide the logic what icon to use exactly in that ModelIconProvider.

To come closer to your needs: What kind of objects are you added to the tree model?

27 Oct 2009, 6:20 AM
TreeStore contains informations about map compositions. Each composition includes a few map layers.

I composition
a) first layer
b) second layer
II composition
a) first layer
b) second layer

What I have to do is:
1) Show a red icon (in a leaf) if map layer hasn't loaded
2) Green icon when map layer has loaded

So first of all I can set all icons to red ones and then if one map has loaded I have to retrieve that leaf from my treestore, update its icon and refresh the view.

27 Oct 2009, 6:28 AM
Please could you post the class representing the TreeStore element? I guess you definitively should think about keeping the state whether it has loaded the map or not in these objects. If you keep this loaded state as a property using get() and set() you provide a model changed event with any change. Of course in addition to that you need a listener registered on each node that reacts to these model changes forcing a treeModel.update() -> et voila: your tree node carries a new icon.
In our case it works that way: We render error, warning and info icons based on JBoss Rules executions updating the business model state ...

27 Oct 2009, 7:00 AM
ok I will post it within four hours as soon as I come back home.

27 Oct 2009, 11:04 AM
Ok I added setIcon() and getIcon() methods to my TreeItem and I change my icons thanks to ModelIconProvider. Thanks a lot Arthy.