View Full Version : refresh async tree after uptade
jescot
30 Jun 2008, 3:02 AM
Hello,
I have an async tree with a context menu to add, edit and delete items. These actions calls a service and when they finish I want to refresh my tree.
My problem is that i'm not able to show my tree expandes as it was with the changes made.
I'm trying something like this:
private void refresh(TreeItem parent){
loader.loadChildren((StringModelData)parent.getData());
tree.expandPath(parent.getPath());
}
but it takes no effect.
Could someone help me? Thanks in advance.
Juan.
mmm. getData() is deprecated. Try with getModel()
darrellmeyer
30 Jun 2008, 8:14 PM
Tree paths use the TreeItem's item id, or TreeItem id if the item id is not specified. When using binders, the approach will not work as the TreeItem's are created internally, so the id's after a refresh will not be the same. Also, the loadChildren call is asynchronous and your are calling expandPath immediately following the load call.
When using a binder, you should preserve the expanded model objects. After the load is complete, you can use a listener on the loader, you can use the selected models with binder.findItem to get the TreeItem and then set their expand state as needed. findModel uses the ModelComparer from the Store, so you must ensure that the refreshed objects are "equal".
This functionality is probably something the TreeBinder should provide. I have added this to the list of things to consider in 1.1.
Christian Hemker
10 Jul 2008, 12:33 AM
Hello,
I want to use the feature to expand a few TreeItems in the tree.
I have done it with your Idea to use the loader.addLoadListener()
and then I get the TreeItems from the binder.findItem() to call the treeItem.setExpanded( true).
This works if I call setExpanded on only one TreeItem.
If I call it on more than one in the same level I get an NullPointerException.
java.lang.NullPointerException: null
at com.extjs.gxt.ui.client.widget.tree.TreeItemUI.afterExpand(TreeItemUI.java:74)
at com.extjs.gxt.ui.client.widget.tree.TreeItemUI$2.handleEvent(TreeItemUI.java:91)
at com.extjs.gxt.ui.client.widget.tree.TreeItemUI$2.handleEvent(TreeItemUI.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:74)
at com.extjs.gxt.ui.client.fx.Fx.onComplete(Fx.java:165)
at com.extjs.gxt.ui.client.fx.Fx$1.onComplete(Fx.java:67)
at com.google.gwt.animation.client.Animation.update(Animation.java:217)
at com.google.gwt.animation.client.Animation.updateAnimations(Animation.java:52)
at com.google.gwt.animation.client.Animation.access$0(Animation.java:47)
at com.google.gwt.animation.client.Animation$1.run(Animation.java:133)
I can get a workaround to avoid the exception if I call tree.setAnimate(false);
But the result ist, that the tree only shows the children of one parent,
and not the whole tree. And not all children for them I have called setExpanded(true).
I have changed the newest explorer Sample from gxt-1.0 so that you can reproduce this.
I have changed the Files in my attachment.
com.extjs.gxt.samples.explorer.client.pages.AsyncTreePage
com.extjs.gxt.samples.explorer.server.FileServiceImpl
How can I expand more than one TreeItem directly in Java?
Thanks,
Christian
Christian Hemker
10 Jul 2008, 11:54 AM
http://extjs.com/forum/showthread.php?t=40995
sz_146
27 Mar 2009, 1:23 AM
I have a similar problem and I have tried the above suggested procedure by Darrell but it doesn't work for me. I save the tree state (each item) in a HashMap (treeState) using the Model's ID as the keys, just before the update and then after the tree reload, (in the loaderLoad) I check if the HashMap size is greater than 0, I go through the rootItems and try to expand but it doesn't work :
// Method that saves tree state
private static HashMap<String, TreeItem> treeState = new HashMap<String, TreeItem>();
public static void saveTreeState(){
List<GenericTreeModel> list = store.getAllItems();
for(GenericTreeModel m : list){
TreeItem item = (TreeItem) binder.findItem(m);
if( !(item.isRoot() || m.isPatient() || item.isLeaf() || m.isLeaf()) ){
treeState.put(m.getID(), item);
}
}
}
// Loader listener (expansion state recovery attempt)
loader.addLoadListener(new LoadListener(){update
public void loaderLoad(LoadEvent le) {
if(treeState.size() > 0){
// just testing on rootItems. NO LUCK
List<GenericTreeModel> rootItems = store.getRootItems();
for(GenericTreeModel m : rootItems){
if(treeState.get(m.getID()) != null){
TreeItem storedItem = treeState.get(m.getID());
if(m.getChildren().size() > 0 && storedItem.isExpanded()){
TreeItem item = (TreeItem) binder.findItem(m);
if(item != null){
// Shows expanded already in Eclipse while it is not, so the statement below does not affect anything
item.setExpanded(true);
}
}
}
}
treeState.clear();
}
super.loaderLoad(le);
}
});
maxpert-gxt
3 Jul 2009, 12:30 AM
Any luck with this ? ? ?
I have a similar problem and I have tried the above suggested procedure by Darrell but it doesn't work for me. I save the tree state (each item) in a HashMap (treeState) using the Model's ID as the keys, just before the update and then after the tree reload, (in the loaderLoad) I check if the HashMap size is greater than 0, I go through the rootItems and try to expand but it doesn't work :
// Method that saves tree state
private static HashMap<String, TreeItem> treeState = new HashMap<String, TreeItem>();
public static void saveTreeState(){
List<GenericTreeModel> list = store.getAllItems();
for(GenericTreeModel m : list){
TreeItem item = (TreeItem) binder.findItem(m);
if( !(item.isRoot() || m.isPatient() || item.isLeaf() || m.isLeaf()) ){
treeState.put(m.getID(), item);
}
}
}
// Loader listener (expansion state recovery attempt)
loader.addLoadListener(new LoadListener(){update
public void loaderLoad(LoadEvent le) {
if(treeState.size() > 0){
// just testing on rootItems. NO LUCK
List<GenericTreeModel> rootItems = store.getRootItems();
for(GenericTreeModel m : rootItems){
if(treeState.get(m.getID()) != null){
TreeItem storedItem = treeState.get(m.getID());
if(m.getChildren().size() > 0 && storedItem.isExpanded()){
TreeItem item = (TreeItem) binder.findItem(m);
if(item != null){
// Shows expanded already in Eclipse while it is not, so the statement below does not affect anything
item.setExpanded(true);
}
}
}
}
treeState.clear();
}
super.loaderLoad(le);
}
});
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.