PDA

View Full Version : TreePanel issue



LarsDK
10 Sep 2009, 5:02 AM
Hi,

I am trying to replace my "Tree" from GXT 1.x with the "TreePanel" of GXT 2.x.

I create a TreePanel, that initially does not have any data. Later I call the updateData() method that should populate the TreePanel, but the TreePanel remains empty. However, if the TreePanel contains at least one row (commented code), my RPC data is shown correctly in the TreePanel.

Any suggestions on how to resolve this problem?

My approach works with the deprecated Tree class.

Thanks in advance.

/Lars



public class NewUnitPanel extends ContentPanel {

TreePanel<ModelData> tree;
ModelData data;
private Widget parent;

/**
* Constructor.
*
* @param parent
* parent container reference
*/
public NewUnitPanel(Widget parent) {
this.parent = parent;

setIconStyle("unit-panel-ico");
setHeading("Unit selection");

TreeStore<ModelData> store = new TreeStore<ModelData>();

/*
data = new UnitTreeData();
data.set("Name", "TEST");
store.add(data, false);
*/

this.tree = new TreePanel<ModelData>(store);

UnitTreeImage icons = (UnitTreeImage) GWT.create(UnitTreeImage.class);

tree.getStyle().setLeafIcon(icons.getLeaf());
tree.getStyle().setNodeCloseIcon(icons.getNode());
tree.getStyle().setNodeOpenIcon(icons.getNodeOpen());


tree.setDisplayProperty("Name");
add(tree);
}

public void updateData() {
final UnitTreeDataServiceAsync service = (UnitTreeDataServiceAsync) GWT.create(UnitTreeDataService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) service;
endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "dataservice");

AsyncCallback<UnitTreeData> callback = new AsyncCallback<UnitTreeData> (){

public void onFailure(Throwable caught) {}

public void onSuccess(UnitTreeData result) {
tree.getStore().add(result.getChildren(), true);
//tree.getStore().remove(data);
}
};

Map <String, String> m = new HashMap<String, String>();
m.put("storedProcedureName", "getUnitTree");
m.put("idColumnName", "ID");
m.put("parentIdColumnName", "parentID");

service.getTreeData(m, callback);

}
}