PDA

View Full Version : How is it possible to attach a Event Listener with a TreeItem..??



RaulDM
3 Jun 2009, 5:16 AM
Hello all

I have created a Tree as:

Tree tree = new Tree();
tree.getStyle().setLeafIconStyle("icon-info");
TreeBuilder.buildTree(tree, IrbModels.getTreeModel());


But now I am unable to attach event Listener with the Tree Items which has no more child elements.

Say my tree looks like

--Main
-------Portfolio
-----------------Add Portfolio
-----------------Modify Portfolio
-----------------Delete Portfolio.

Now I want to add Event Listeners with the TrreItems: Add Portfolio, Modify Portfolio, Delete Portfolio.

I have tried to do this by:

List<TreeItem> items = tree.getAllItems();
TreeItem item;
Iterator<TreeItem> t = items.iterator();
while(t.hasNext()){
item=t.next();
if(item.hasChildren()){
t.remove();
}else{
try{

Listener<ComponentEvent> listener = new SelectionListener<ComponentEvent>(){
@Override
public void componentSelected(ComponentEvent ce) {
TreeItem h = (TreeItem) ce.getSource();
MessageBox.alert("abcd", h.getText()+" Item is clicked", null);
}
};
tree.getItemById(item.getId()).addListener(new EventType(Event.ONCLICK), listener) ;
}catch(Exception e){
e.printStackTrace();
e.getCause();
e.getMessage();
}
}
}

But it does not working.

I have tried the AddEventSunk() Method also with the el() component of the child nodes but then I got error message like;

java.lang.AssertionError: Method must be called after the component is rendered
at com.extjs.gxt.ui.client.widget.Component.assertAfterRender(Component.java:1286)
at com.extjs.gxt.ui.client.widget.Component.el(Component.java:406)
.......
.......



Does any One has any idea about this...

Please show a way...!!

It will be of great help



Raul

RaulDM
8 Jun 2009, 4:25 AM
Cool I have done it..!!

Thanks..!!