View Full Version : Tree events

2 Jul 2008, 10:01 AM
Hi guys, I need your help with Tree/TreeItem events.

The situation:
I have the latest Ext-GWT 1.0.RC2, simple tree widget, model and backend invoked via GWT-RPC. Everything works fine when it comes to rendering and dynamic sub-tree loading. Also I attached the context menus to all nodes and it also works fine (including the events in context menu).

The problem:
I need to separately handle the "left" click and "right" click on tree nodes or items. I attached the listener for "Events.SelectionChange" event to Tree widget. However, this handler is invoked for both the left AND right click on node or item that was not selected before. How can I distinguish between those two types of clicks? I know that TreeEvent.isRightClick() method is not working properly in this latest official release (and most likely will work in next release), but I need that functionality now. Does anybody know about any workaround? Also I tried to hook-up on "Events.Select" but it is not fired on Tree widget and "Events.OnClick" is too sensitive (it fires on any kind of clicks on Tree widget).

Next problem is that "Events.SelectionChange" is fired only when a user clicks on a tree node or item that was not previously selected. What event is fired when user clicks on already selected tree node or item? It looks like it's not "Events.SelectionChange".

Thanks a lot.

3 Jul 2008, 6:21 AM
In TreeEvent (extends DomEvent) you have an Event event attribute which is the GWT event. Try (I didn't test) :

tree.addListener(Events.SelectionChange,new Listener<TreeEvent>(){
public void handleEvent(TreeEvent be) {
if(Event.BUTTON_RIGHT == be.event.getButton()){
//on right click

3 Jul 2008, 10:11 AM
Thanks, zaccret, for this idea. Unfortunately, TreeEvent.event is null so I cannot call getButton() method on it.

9 Jul 2008, 1:38 AM
Mmm, maybe you should post it in the Bug forum ?

16 Jul 2008, 4:37 AM
With the last release, it is not null but the test I suggest don't work.

17 Jul 2008, 7:46 AM
Thanks, zaccret. The TreeEvent.isRightClick() works in Ext-GWT 1.0 (final release) so I was able to solve the problem with that release.