PDA

View Full Version : [CLOSED]TreeStore.add(parent, child, true) not adding child to parent.getChildren()



Cputerace
29 Jun 2009, 9:02 AM
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.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
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;
private TreePanel<BaseModelData> tp;

public void onModuleLoad() {
RootPanel.get().add(v);
v.setHeight("100%");
v.setLayout(new FlowLayout());
ts = new TreeStore<BaseModelData>();
tp = new TreePanel<BaseModelData>(ts);
tp.setDisplayProperty("name");
final BaseTreeModel root = new BaseTreeModel();
root.set("name", "root");
ts.add(root, true);
BaseTreeModel child = new BaseTreeModel();
child.set("name", "child");
ts.add(root, child, true);
Button b = new Button(){};
b.addSelectionListener(new SelectionListener<ButtonEvent>(){

@Override
public void componentSelected(ButtonEvent ce)
{
Window.alert(root.getChildCount() + "");
}});
v.add(tp);
v.add(b);
v.layout();
}
}

Clicking the button results in 0, when I believe it should be 1. ts.add(root, child, true) does not seem to be updating the root model's children.

sven
29 Jun 2009, 9:20 AM
You have to get the childcount from the store and not the model.

The relationships between parent and child are maintained internally by the store, therefore, the children of root is never added directly to the root model.

If you change your code to be the following it works:


System.out.println(ts.getChildCount(root));

I am closing the issue.