View Full Version : Reordering treegrid - store not updated correctly

26 Jul 2010, 9:37 AM

I'm trying to reorder EditorTreeGrid and update the model after dragdrop. I found out that calling store.getModels(), returns updated store but fetching models with getChild(i) doesn't. Is this a bug or should I "refresh" the store somehow? This only happens when model is dragged to some parent model (=new depth>0).

TreeStore<FoodModel>store = new TreeStore<FoodModel>();
EditorTreeGrid<FoodModel> grid = new EditorTreeGrid<FoodModel>(store, cm);
TreeGridDropTarget target = new TreeGridDropTarget(grid) {
protected void onDragDrop(DNDEvent e) {

final ArrayList<TreeStoreModel> arr = (ArrayList<TreeStoreModel>)e.getData();
final TreeStoreModel mT = arr.get(0);
final FoodModel m = (FoodModel)mT.getModel();
System.out.println("Dragged model: "+m.getName());

//get grid
final EditorTreeGrid<FoodModel> gridNew = (EditorTreeGrid<FoodModel>)e.getDropTarget().getComponent();
final TreeStore<FoodModel> store = (TreeStore<FoodModel>)gridNew.getTreeStore();
//print with getModels()
for(FoodModel mm : store.getModels()) {
System.out.println("With getModels(): "+mm.getName());
//print with getChild(i)
for(int i=0; i<store.getChildCount(); i++)
FoodModel mm = store.getChild(i);
System.out.println("With getChild(): "+mm.getName());
for(int j=0; j<mm.getChildCount(); j++) {
System.out.println(" - child: "+((FoodModel)mm.getChild(j)).getName());


And when "Model1" is dragged from different grid to "Parent2" that prints:

Dragged model: Model1
With getModels(): Parent1
With getModels(): Model2
With getModels(): Parent2
With getModels(): Model3
With getModels(): Model1

With getChild(): Parent1
- child: Model2
With getChild(): Parent2
- child: Model3

It seems that child models are not updated correctly? I hope somebody understands what I'm trying to say :D

26 Jul 2010, 9:42 AM
Can you please post some fully working testcase that implements EntryPoint?

26 Jul 2010, 9:45 AM
Actually, i see it.

Only the store keeps the structure. The model is not updated. Instead of calling mm.getChildCount() and mm.getChild(), you need to ask the store for the data.

26 Jul 2010, 10:01 AM
What do you mean by "ask store for the data"?

Do I have to manually add/update the dragged model to correct parent (where it was dragged)? Because it updates the grid correctly after dragdrop. (<- means that visually grid is correct after dropping the model)

26 Jul 2010, 10:05 AM
No, instead of calling mm.getChildCount, ask the store for the child count.


Same for getting the actual children

26 Jul 2010, 10:10 AM
Yes, that does the trick. Now it is working correctly. Thanks!