PDA

View Full Version : [CLOSED] [2.0] Problem with TreeLoader+TreeGrid+BeanModel



Webflash
15 Jul 2009, 7:47 AM
HostMode, OS WinXP
Show empty tree


publicclass GxtBug implements EntryPoint {


private BeanModelFactory categoryFactory = BeanModelLookup.get().getFactory(Category.class);


/**
*Thisistheentrypointmethod.
*/


publicvoid onModuleLoad() {
Viewport viewPort = new Viewport();
viewPort.setLayout(new FitLayout());


RpcProxy<List<Category>> rpc = new RpcProxy<List<Category>>() {


@Override
protectedvoid load(Object loadConfig, AsyncCallback<List<Category>> callback) {


if (loadConfig == null) {
callback.onSuccess(generate());
} else {
BeanModel model = (BeanModel) loadConfig;
callback.onSuccess(((Category) model.getBean()).getChild());
}


}
};


TreeLoader<BeanModel> loader = new BaseTreeLoader<BeanModel>(rpc, new BeanModelReader()) {
@Override
publicboolean hasChildren(BeanModel parent) {
return ((Category) parent.getBean()).getChild().size() > 0;
}


};


List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
{
ColumnConfig column = new ColumnConfig("name", "Name", 200);
column.setRenderer(new TreeGridCellRenderer<ModelData>());
columns.add(column);
}


TreeStore<BeanModel> store = new TreeStore<BeanModel>(loader);
TreeGrid<BeanModel> treeGrid = new TreeGrid<BeanModel>(store, new ColumnModel(columns));
treeGrid.setLoadMask(true);
// loader.load();
viewPort.add(treeGrid);
RootPanel.get().add(viewPort);
}


public List<Category> generate() {
List<Category> list = new ArrayList<Category>();
for (int i = 0; i < 5; i++) {
Category category = new Category("category " + i);
List<Category> child = new ArrayList<Category>();


for (int j = 0; j < 3; j++) {
Category childCategory = new Category("Child Category " + i + "_" + j);
child.add(childCategory);
}
category.setChild(child);
list.add(category);
}
return list;
}
}


public

class Category implements BeanModelTag {

private String name;
private List<Category> child = new ArrayList<Category>();


public Category(String name) {
this.name = name;
}


public String getName() {
returnname;
}


publicvoid setName(String name) {
this.name = name;
}


public List<Category> getChild() {
returnchild;
}


publicvoid setChild(List<Category> child) {
this.child = child;
}

}

if change to

RpcProxy<List<BeanModel>> rpc =


new RpcProxy<List<BeanModel>>() {


@Override
protectedvoid load(Object loadConfig, AsyncCallback<List<BeanModel>> callback) {


if (loadConfig == null) {
callback.onSuccess(categoryFactory.createModel(generate()));
} else {
BeanModel model = (BeanModel) loadConfig;
callback.onSuccess(categoryFactory.createModel(((Category)model.getBean()).getChild()));
}


}
};


TreeLoader<BeanModel> loader = new BaseTreeLoader<BeanModel>(rpc) {
@Override
publicboolean hasChildren(BeanModel parent) {
return ((Category) parent.getBean()).getChild().size() > 0;
}

};

All work normal

sven
15 Jul 2009, 8:14 AM
Why you think this is a bug?

This is the purpose of the factory. You have to use it if you have normal beans that are not an instance of ModelData. I am closing this issue.

Normally a reader is doing this for you. But as you dont use a reader, yuo have to do it manually.

Webflash
15 Jul 2009, 9:52 AM
pls test the posted code I use BeanModelReader but it not work
TreeLoader<BeanModel> loader = new BaseTreeLoader<BeanModel>(rpc, new BeanModelReader());

in bootom my post I write workaround

sven
15 Jul 2009, 10:35 AM
I tested your code. Your reader is never reached. Take a look at the RpcProxy sources. There the reader is first invoked and than onsuccess is called (as your second example that works)

jxblizzard
1 Sep 2009, 1:32 AM
RpcProxy<List<Chapter>> proxy = new RpcProxy<List<Chapter>>() {
@Override
protected void load(Object loadConfig, AsyncCallback<List<Chapter>> callback) {
service.getAllChapter((Chapter)loadConfig,callback);
}
};
How to get data from onSuccess method of RPC call ? I need get the data to convert into the BeanModel.

micgala
1 Sep 2009, 2:43 AM
Hi.

Try this:


RpcProxy<List<Chapter>> proxy = new RpcProxy<List<Chapter>>() {
@Override
protected void load(Object loadConfig, final AsyncCallback<List<Chapter>> callback) {
service.getAllChapter((Chapter)loadConfig, new AsyncCallback<List<Chapter>>() {
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}

public void onSuccess(List<Chapter> result) {
//Here you have access to it
callback.onSuccess(result);
}
});
}
};