PDA

View Full Version : Get Selected Tree item on double click



bornsilly
16 Nov 2009, 7:00 AM
Hi,

I just moved from GWT-EXT to GXT and am not jet familiar wit how to do things. Also in this case looking at the examples didnt show me a example which did what i wanted.

The treegrid examples all perform a action when the selection changed, but how could you accomplisch the same but then only perform it when the user double clicks on a treenode.

Currently i have the below code which reacts to the selectionchanged



tree.getSelectionModel().addSelectionChangedListener(
new SelectionChangedListener<MenuItem>() {

@Override
public void selectionChanged(SelectionChangedEvent<MenuItem> se) {
MenuItem f = (MenuItem) se.getSelection().get(0);
AppEvent evt = new AppEvent(EasyTrackEvents.Show, f.getName() );
fireEvent(evt);
}
});


Question being how i could accomplish the same but when the user double clicks.

Any help is highly appriciated.

Thanks.

micgala
16 Nov 2009, 7:17 AM
Hi.

Try this (untested):


workbenchTree.addListener(Events.OnDoubleClick, new Listener<TreePanelEvent<MenuItem>>() {
public void handleEvent(TreePanelEvent<MenuItem> be) {
MenuItem doubleClickedEntry = be.getItem();
//TODO: do what you want to do here.
}
});


PS: I see you are using MenuItem as the name of your model class. Not a good idea, since MenuItem is already a class defined in Gxt. You would better rename it to "SomethingModel".

Regards,
Michel.

bornsilly
16 Nov 2009, 11:34 AM
workbenchTree.addListener(Events.OnDoubleClick, new Listener<TreePanelEvent<MenuItem>>() {
public void handleEvent(TreePanelEvent<MenuItem> be) {
MenuItem doubleClickedEntry = be.getItem();
//TODO: do what you want to do here.
}
});


PS: I see you are using MenuItem as the name of your model class. Not a good idea, since MenuItem is already a class defined in Gxt. You would better rename it to "SomethingModel".

Regards,
Michel.


Michel.

Thanks so much that work great. And also thanks for the suggestion i will rename that model to something less common.


Thanks.

Marco