PDA

View Full Version : [FIXED] Context Menu on Tree does not change selection before appearing



Cputerace
24 Jun 2009, 5:59 AM
package com.mycompany.gwtprototype.client;

import com.extjs.gxt.ui.client.binder.TreeBinder;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.TreeEvent;
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.menu.Menu;
import com.extjs.gxt.ui.client.widget.menu.MenuItem;
import com.extjs.gxt.ui.client.widget.tree.Tree;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class GwtPrototype implements EntryPoint {

private Viewport v = new Viewport();

public void onModuleLoad() {
RootPanel.get().add(v);
v.setHeight("100%");
v.setLayout(new FitLayout());
final Tree tree = new Tree();
Menu cm = new Menu();
final MenuItem mi = new MenuItem("nothing selected");
cm.add(mi);
tree.setContextMenu(cm);
TreeStore<BaseTreeModel> ts = new TreeStore<BaseTreeModel>();
TreeBinder<BaseTreeModel> tb = new TreeBinder<BaseTreeModel>(tree, ts);
tb.setDisplayProperty("name");
BaseTreeModel btm1 = new BaseTreeModel();
BaseTreeModel btm2 = new BaseTreeModel();
btm1.set("name", "Node 1");
btm2.set("name", "Node 2");
tree.addListener(Events.SelectionChange, new Listener<TreeEvent>(){
public void handleEvent(TreeEvent te)
{
BaseTreeModel model = (BaseTreeModel)tree.getSelectedItem().getModel();
String name = (String)model.get("name");
mi.setText(name);
}});
ts.add(btm1, false);
ts.add(btm2, false);
v.add(tree);
v.layout();
}
}right click a node. it will say nothing selected. left click node 1, then right click node 2, it will say node 1.

I know Tree is deprecated, but until I have time to replace it, this issue is critical. If an item is selected, and the user right clicks on another tree item, they get the context menu for the previously selected item because selectionChange never fires. This can cause all sorts of devastating problems (e.g. delete wrong item). This used to work in 1.2, not sure if it did in m1 or m2.

darrellmeyer
24 Jun 2009, 6:21 PM
Fixed in SVN.