PDA

View Full Version : TreeGrid using BeanModel is Broken



cri1258
15 Aug 2009, 1:28 PM
First, please excuse the fact that my posted source code isn't run-able. I don't know how to easily insert an rpc call into sample code. A tip on doing this would be helpful.

When I run the code:


public class ScoreCard implements EntryPoint {

private Viewport viewport = new Viewport();
private TreeLoader<BeanModel> loader;

public void onModuleLoad() {
viewport.setLayout(new FillLayout());
viewport.add(new TopLevel());
RootPanel.get().add(viewport);
PerformanceNode node = new PerformanceNode();
node.setIntervalStartDate("07/01/09");
node.setIntervalEndDate("07/15/09");
node.setHierarchyLevel(0);
loader.load(node);
}

public class TopLevel extends LayoutContainer {

private PerformanceServiceAsync service = Registry
.getPerformanceService();

@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);

setLayout(new FlowLayout(10));

// data proxy
RpcProxy<List<PerformanceNode>> proxy = new RpcProxy<List<PerformanceNode>>() {
@Override
protected void load(Object performanceNode, AsyncCallback<List<PerformanceNode>> callback) {
if (performanceNode != null){
service.getPerformanceHierarchyChildren(
PerformanceService.BY_MANAGEMENT_HIERARCHY,
(PerformanceNode) performanceNode, callback);
}
}
};

BeanModelReader reader = new BeanModelReader();

// tree loader
loader = new BaseTreeLoader<BeanModel>(proxy, reader) {
@Override
public boolean hasChildren(BeanModel parent) {
return false;
}
};

// trees store
final TreeStore<BeanModel> store = new TreeStore<BeanModel>(loader);
store.setStoreSorter(new StoreSorter<BeanModel>() {

@Override
public int compare(Store<BeanModel> store, BeanModel m1,
BeanModel m2, String property) {
// TODO Auto-generated method stub
return -1;
}
});


ColumnConfig name = new ColumnConfig("name", "Name", 100);
name.setRenderer(new TreeGridCellRenderer<ModelData>());

ColumnModel cm = new ColumnModel(Arrays.asList(name));

ContentPanel cp = new ContentPanel();
cp.setBodyBorder(false);
cp.setHeading("Async TreeGrid");
cp.setButtonAlign(HorizontalAlignment.CENTER);
cp.setLayout(new FitLayout());
cp.setFrame(true);
cp.setSize(600, 300);

TreeGrid<BeanModel> tree = new TreeGrid<BeanModel>(store, cm);
tree.setBorders(true);
tree.getStyle().setLeafIcon(IconHelper.createStyle("icon-page"));
tree.setSize(400, 400);
tree.setAutoExpandColumn("name");
tree.setTrackMouseOver(false);
cp.add(tree);

add(cp);
}

}

}I get the exception:


[ERROR] Uncaught exception escaped
java.lang.ClassCastException: com.embarq.scorecard.client.domain.PerformanceNode cannot be cast to com.extjs.gxt.ui.client.data.ModelData
at com.extjs.gxt.ui.client.data.BaseTreeLoader.onLoadFailure(BaseTreeLoader.java:113)
at com.extjs.gxt.ui.client.data.BaseLoader$1.onFailure(BaseLoader.java:123)
at com.extjs.gxt.ui.client.data.RpcProxy$1.onSuccess(RpcProxy.java:38)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:215)
at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:264)
at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:236)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:227)

I guess that somewhere I need to convert my Java Bean (PerformanceNode) to a BeanModel using a BeanModelFactory, but I can't figure out where to do this, e.g. in a over loaded method perhaps.

I'm embarrassed to admit how long I've spent trying to figure this out, but I'm been at it quite a long while. Any pointers would be greatly appreciated.

Thanks, Chuck