PDA

View Full Version : Tree XML Loading



stormblow
3 Feb 2010, 10:41 PM
Hi,

I'm trying to create a tree which loads its children on demand using a remote service which returns xml ( http://www.extjs.com/examples-dev/explorer.html#asyncxmltree (http://www.extjs.com/forum/../examples-dev/explorer.html#asyncxmltree))

My XML file is the following :


<items>
<item id="1" name="root" folder="true">
<item id="2" name="gestion objets" folder="false">gestion objets</item>
</item>
</items>
And the code is the following :


public void onModuleLoad() {
Log.setCurrentLogLevel(Log.getLowestLogLevel());
Log.setUncaughtExceptionHandler();

ContentPanel west = new ContentPanel();
west.setBodyBorder(false);
west.setLayout(new AccordionLayout());
west.setLayoutOnChange(true);
west.setHeading("Admin navigation");
west.setWidth(200);

ContentPanel navigation = new ContentPanel();
navigation.setHeading("Navigation");
navigation.setAnimCollapse(false);
navigation.setHeight(600);

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "/resources/xml/xmltreeloader.xml");
HttpProxy<ListLoadResult<ModelData>> proxy = new HttpProxy<ListLoadResult<ModelData>>(builder);

ModelType type = new ModelType();
type.setRecordName("item");
type.setRoot("items");
type.addField("id", "@id");
type.addField("name", "@name");
type.addField("folder", "@folder");

XmlReader<List<ModelData>> reader = new XmlReader<List<ModelData>>(type);

TreeLoader<ModelData> loader = new BaseTreeLoader<ModelData>(proxy,reader) {
@Override
public boolean hasChildren(ModelData parent) {
return "true".equals(parent.get("folder"));
}

@Override
protected Object prepareLoadConfig(Object config) {
return super.prepareLoadConfig(config);
}
};
TreeStore<ModelData> store = new TreeStore<ModelData>(loader);
Log.info(" "+store.getAllItems().isEmpty());

final TreePanel<ModelData> tree = new TreePanel<ModelData>(store);
tree.setDisplayProperty("name");
tree.setWidth(315);

loader.load();

navigation.add(tree);
west.add(navigation);
RootPanel.get().add(west);
}
This code returns no errors. Unfortunately the tree isn't loaded and


Log.info(" "+store.getAllItems().isEmpty());
returns true...

Does anyone have any idea?

Thank you very much.