PDA

View Full Version : [FIXED] Tree node bug when second leaf is added



andrey
15 May 2008, 8:50 AM
You can actually see this bug in the Ext GWT Explorer:

1) Load the Ext GWT Explorer demo
2) Navigate to Data Widgets->Trees->Context Menu Tree
3) Select the "Beetoven" node, right-click, and "Insert Item"
The Beetoven node should expand with a new item added - so far so good
4) Select "Beetoven" node again, right-click, and "Insert Item"
The new node will be added under a different node (not the "Beethoven" node)
Try the above on other nodes. First leaf under a node seems to work, second or more go somewhere else.

andrey
17 May 2008, 5:35 AM
Can someone (Darrell?) please acknowledge that this is a bug and that it will be or has been fixed in beta3. This is a real problem for me. Also, from the test case below (mostly copied from the Explorer demo), in addition to the tree items being inserted under the wrong nodes, the entire tree will shift up and partially out of view when you select the context menu after the first time. The viewport is being bound to a single div tag in the html.


import com.extjs.gxt.ui.client.event.MenuEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.FillLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.extjs.gxt.ui.client.widget.menu.Menu;
import com.extjs.gxt.ui.client.widget.menu.TextMenuItem;
import com.extjs.gxt.ui.client.widget.tree.SingleTreeSelectionModel;
import com.extjs.gxt.ui.client.widget.tree.Tree;
import com.extjs.gxt.ui.client.widget.tree.TreeItem;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class TestTreeInsert implements EntryPoint {

private int count = 0;

public void onModuleLoad() {
final Viewport viewport = new Viewport();
viewport.setLayout(new FlowLayout(20));

final Tree<SingleTreeSelectionModel> tree = new Tree<SingleTreeSelectionModel>();
tree.setItemIconStyle("icon-money");

TreeItem rootItem = tree.getRootItem();
rootItem.add(new TreeItem("Howdy"));
TreeItem childItem = new TreeItem("Doody");
rootItem.add(childItem);
childItem.add(new TreeItem("Fiddle"));
childItem.add(new TreeItem("Faddle"));

Menu contextMenu = new Menu();
contextMenu.setWidth(130);

TextMenuItem insert = new TextMenuItem();
insert.setText("Insert Item");
insert.setIconStyle("icon-add");
insert.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
TreeItem item = tree.getSelectionModel().getSelectedItem();
if (item != null) {
TreeItem newItem = new TreeItem();
newItem.setText("Add Child " + count++);
item.add(newItem);
item.setExpanded(true);
viewport.layout(true);
}
}
});
contextMenu.add(insert);

TextMenuItem remove = new TextMenuItem();
remove.setText("Remove Selected");
remove.setIconStyle("icon-delete");
remove.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
TreeItem item = tree.getSelectionModel().getSelectedItem();
if (item != null) {
item.getParentItem().remove(item);
}
}
});
contextMenu.add(remove);

tree.setContextMenu(contextMenu);

ContentPanel panel = new ContentPanel();
panel.setLayout(new FillLayout());
panel.add(tree);
viewport.add(panel);
viewport.layout(true);
RootPanel.get("slot1").add(viewport);
}
}Thanks,
Andre

darrellmeyer
20 May 2008, 8:35 PM
Fixed in beta 3.