PDA

View Full Version : [FIXED] TreePanel Bug



ocooper
30 Jun 2009, 2:08 AM
Hi,

We have a TreePanel widget on a TabItem. Whenever the user views that tab the tree must be rebuilt. As a result the contents of the LayoutContainer holding the TreePanel are removed and then the TreePanel created and re-added.

Whenever the TreePanel is added only 3 of the 5 root nodes (in this example) display. By expanding any one of the nodes the other 2 missing nodes then appear. When the TreePanel is removed and re-added by clicking away and then back onto that tab the Nodes are missing again.

This occurs in Hosted Mode and on all major browsers. OS is XP.

Code:



package uk.org.eduserv.GXTTreePanelBugTest.client;

import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.event.ComponentEvent;
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.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/

public class GXTTreeTest implements EntryPoint
{
LayoutContainer lCon = new LayoutContainer();

public void onModuleLoad()
{
TabPanel mainTabs = new TabPanel();
TabItem treeTab = new TabItem("Tree");
TabItem otherTab = new TabItem("Other");

updateTree();

treeTab.add(lCon);
mainTabs.add(treeTab);
mainTabs.add(otherTab);

treeTab.addListener(Events.BeforeShow, new Listener<ComponentEvent>() {

public void handleEvent(ComponentEvent be)
{
updateTree();
}
});

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

private void updateTree()
{
TreePanel<BaseTreeModel> tree = createTree();
lCon.removeAll();
lCon.add(tree);
lCon.layout();
}

private TreePanel<BaseTreeModel> createTree()
{
TreeStore<BaseTreeModel> store = new TreeStore<BaseTreeModel>();

BaseTreeModel[] m = new BaseTreeModel[5];

for(int i = 0; i < m.length; i++) {
m[i] = new BaseTreeModel();
m[i].set("displayName", "Node " + (i+1));
BaseTreeModel sub = new BaseTreeModel();
sub.set("displayName", "Sub-Node");
m[i].add(sub);
store.add(m[i], true);
}

TreePanel<BaseTreeModel> retTree = new TreePanel<BaseTreeModel>(store);
retTree.setDisplayProperty("displayName");

Info.display("Tree Nodes", "No of root nodes that SHOULD be displaying: "
+ store.getRootItems().size());

return retTree;
}
}

sven
30 Jun 2009, 2:28 AM
Fixed in SVN.

ocooper
30 Jun 2009, 6:11 AM
Hi Sven,

Although the nodes now appear correctly the first time the tree is added, if you try clicking on the 'Other' tab in my example and then back to the 'Tree' tab so that the tree is removed and rebuilt you'll see that only 3 nodes appear.

Thanks,

Oli.

sven
30 Jun 2009, 6:56 AM
The problem ist that you are doing this in the beforeshow event. While a component is hidden with display none, you cant determine its size. This will make all layoutcalls to fail. I suggest to use the Events.Show event. Than your testcase works quite good with my fix.