PDA

View Full Version : [2.0] TreePanel can't listen for DoubleClick



Cputerace
8 Jul 2009, 6:20 AM
Can't listen for DoubleClick on a TreePanel.


package com.mycompany.gwtprototype.client;

import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;

public class GwtPrototype implements EntryPoint {

private Viewport v = new Viewport();
private TreeStore<BaseModelData> ts = new TreeStore<BaseModelData>();
private TreePanel<BaseModelData> treePanel;

public void onModuleLoad() {
RootPanel.get().add(v);
v.setHeight("100%");
v.setLayout(new FitLayout());
treePanel = new TreePanel<BaseModelData>(ts);
treePanel.setDisplayProperty("name");
treePanel.addListener(Events.DoubleClick, new Listener(){

public void handleEvent(BaseEvent be)
{
Window.alert("Double Click");
}});
v.add(treePanel);
v.layout();

final BaseTreeModel root = new BaseTreeModel();
root.set("name", "another item");
ts.add(root, true);
}
}

sven
8 Jul 2009, 6:54 AM
This is not a bug. Moving this to the help forum.

Cputerace
8 Jul 2009, 12:25 PM
Any hints? I tried TreePanel.sinkEvents(Events.DoubleClick).

Arno.Nyhm
7 Aug 2009, 5:51 AM
you have to use this in after rendering (if you overwrite the onrender or add a listener):


el().addEventsSunk(Event.ONDBLCLICK);
with listener:


myItem.addListener(Events.Render, new Listener<BaseEvent>() {

public void handleEvent(BaseEvent be) {
myItem.el().addEventsSunk(Event.ONDBLCLICK);
}
});

look here for double klick on Header in a Window:

http://www.extjs.com/forum/showthread.php?p=370360#post370360

sven
7 Aug 2009, 5:54 AM
This answer is actually not correct.

The listener that was added is just the wrong one.




tree.sinkEvent(Event.ONDBLCLICK);
treePanel.addListener(Events.OnDoubleClick, new Listener(){