PDA

View Full Version : Problem within TreeGrid



A.Rothe
17 Nov 2011, 4:58 AM
Hi,

I have a TreeGrid and a TreeStore. If I add a new record to the store manually, I try to expand the parent node of the new record:



Parent parent = new Parent("parent");
Record record = new Record("record");
store.add(parent, record, false);
Version version = new Version("a version");
store.add(record, version, false);


I have added a StoreListener to the store:



store = new TreeStore<ModelData>();
store.addStoreListener(new RecordStoreListener());


The listener is implemented as:



private class RecordStoreListener extends StoreListener<ModelData> {
public void storeAdd(StoreEvent<ModelData> se) {
TreeStoreEvent<ModelData> tse = (TreeStoreEvent<ModelData>) se;
tree.setExpanded(tse.getParent(), true);
Info.display("haha", (String) tse.getParent().get("name"));
}
}

Parent, Record and Version store the given String as property "name". The Info is displayed twice, one for the first add() and one for the second add(). The store seems to be okay.

But the TreeGrid displays the newly added records twice! If I remove the listener, all is fine, but with the listener, the nodes are duplicated within the tree.

Any ideas?
Thanks
Andre :((

sven
17 Nov 2011, 5:03 AM
Try to put that

tree.setExpanded(tse.getParent(), true); within a finally command.

A.Rothe
17 Nov 2011, 5:30 AM
The surrounding class is defined as:



public class RecordPanel extends ContentPanel {

private final TreeStore<ModelData> store;
private final TreeGrid<ModelData> tree;

public RecordPanel() {

// ...

store = new TreeStore<ModelData>();
store.addStoreListener(new RecordStoreListener());

tree = new TreeGrid<ModelData>(store, new RecordTreeGridColumnModel());

// ...
}

private class RecordStoreListener extends StoreListener<ModelData> {

public void storeAdd(StoreEvent<ModelData> se) {
TreeStoreEvent<ModelData> tse = (TreeStoreEvent<ModelData>) se;
tree.setExpanded(tse.getParent(), true);
Info.display("haha", (String) tse.getParent().get("name"));
}
}}


What do you mean with "finally"?

At the moment I have sub-classed TreeGrid, but I would like to use listeners instead.



protected void onAdd(TreeStoreEvent<ModelData> se) {
super.onAdd(se);
ModelData parent = se.getParent();
if (parent != null) {
setExpanded(parent, true);
}
}


This seems to work.
~André

sven
17 Nov 2011, 5:32 AM
Scheduler.get().scheduleFinally