PDA

View Full Version : [2.0 Trunk]: Index out of Bounds Exception in BaseTreeModel after calling add Method



mgoerdes
25 Apr 2009, 8:12 AM
Hi Dev-Team,

after using changing from M1 to the current trunk, we get an IndexOutOfBoundsException when adding a Model to a BaseTreeModel. The last change in rev 1442 of TreeStore regarding line 507 (add(parent, child, false); to insert(parent, child, ce.getIndex(), false); ) dosnt work. Any ideas for that?

Regards,
Mark

[ERROR] Uncaught exception escaped
java.lang.IndexOutOfBoundsException: Index: 3, Size: 0
at java.util.ArrayList.add(Unknown Source)
at com.extjs.gxt.ui.client.data.BaseTreeModel.insert(BaseTreeModel.java:117)
at com.extjs.gxt.ui.client.store.TreeStore.doInsert(TreeStore.java:552)
at com.extjs.gxt.ui.client.store.TreeStore.insert(TreeStore.java:345)
at com.extjs.gxt.ui.client.store.TreeStore.insert(TreeStore.java:359)
at com.extjs.gxt.ui.client.store.TreeStore.onModelChange(TreeStore.java:507)
at com.extjs.gxt.ui.client.store.Store$1.modelChanged(Store.java:480)
at com.extjs.gxt.ui.client.data.ChangeEventSupport.notify(ChangeEventSupport.java:33)
at com.extjs.gxt.ui.client.data.BaseModel.notify(BaseModel.java:103)
at com.bearingpoint.davinci.frontend.gwt.client.mvc.model.BaseDaVinciTreeModel.notify(BaseDaVinciTreeModel.java:149)
at com.bearingpoint.davinci.frontend.gwt.client.mvc.model.BaseDaVinciTreeModel.insert(BaseDaVinciTreeModel.java:128)
at com.bearingpoint.davinci.frontend.gwt.client.mvc.model.BaseDaVinciTreeModel.add(BaseDaVinciTreeModel.java:64)

sven
25 Apr 2009, 9:16 AM
Can you please post some example code demonstrating this issue?

mgoerdes
25 Apr 2009, 11:05 AM
Hi Sven,

this sample code shows the problem.

Start the code in Hosted mode and then expand "Parent 1". In the code you see, that I add two childs to "Parent 1", but they are not displayed after expand. Instead of these two children, the loaded child "Child 1" is dispayed. If you now press the test-button you will see the the java.lang.IndexOutOfBoundsException.

treeBinder.setAutoLoad(true); solves this problem, but sometimes it is not usefull.

Regards,
Mark


package com.bearingpoint.davinci.frontend.gwt.test.client;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.binder.TreeBinder;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.BaseTreeLoader;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.data.DataReader;
import com.extjs.gxt.ui.client.data.MemoryProxy;
import com.extjs.gxt.ui.client.data.TreeLoader;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
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.tree.Tree;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;

public class TreeTest implements EntryPoint {

BaseTreeModel firstItem;

public void onModuleLoad() {

ContentPanel contentPanel = new ContentPanel();
contentPanel.setLayout(new FlowLayout());
contentPanel.setLayoutOnChange(true);

final Tree t = createTree();
t.setHeight(400);
t.setWidth(200);
contentPanel.add(t);

Button b = new Button("test");

BaseModel test = new BaseModel();
test.set("caption", "Add successfull");
firstItem.add(test);
test = new BaseModel();
test.set("caption", "Add successfull");
firstItem.add(test);

b.addListener(Events.OnClick, new Listener(){
public void handleEvent(BaseEvent be) {
// TODO Auto-generated method stub
BaseModel test = new BaseModel();
test.set("caption", "Failed");
firstItem.add(test);
}
});
contentPanel.add(b);

RootPanel.get().add(contentPanel);
}

private Tree createTree() {

List<BaseModel> l = new ArrayList<BaseModel>();
MemoryProxy<List<BaseModel>> proxy = new MemoryProxy<List<BaseModel>>(
l) {
@Override

public void load(DataReader<List<BaseModel>> reader,
Object loadConfig,
AsyncCallback<List<BaseModel>> callback) {
// TODO Auto-generated method stub
if (loadConfig == null || loadConfig instanceof BaseTreeModel) {
List<BaseModel> l = new ArrayList<BaseModel>();
for (int i=0; i < 1; i++) {
BaseModel b;
if (loadConfig==null) {
b = new BaseTreeModel();

if (firstItem == null)
firstItem = (BaseTreeModel) b;
b.set("caption","Parent "+i);


} else
{
b = new BaseModel();
b.set("caption","Child "+i);

}
l.add(b);
}
callback.onSuccess(l);
}
}
};

TreeLoader<BaseModel> loader = new BaseTreeLoader<BaseModel>(proxy) {
@Override
public boolean hasChildren(BaseModel parent) {
return parent instanceof BaseTreeModel;
};
};

TreeStore<BaseModel> store = new TreeStore<BaseModel>(loader);
store.setMonitorChanges(true);

final Tree tree = new Tree();
tree.setSelectionMode(SelectionMode.MULTI);


TreeBinder<BaseModel> treeBinder = new TreeBinder<BaseModel>(tree, store);
treeBinder.setDisplayProperty("caption");
//treeBinder.setAutoLoad(true);
loader.load(null);


return tree;

}

}