Results 1 to 2 of 2

Thread: [CLOSED] Tree Panel Bug

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext User
    Join Date
    May 2008
    Posts
    12
    Vote Rating
    0
      0  

    Default [CLOSED] Tree Panel Bug

    Tree Panel doesn't refresh when a leaf's state changes from having no children to having children.

    (add5 works as expected, add1 doesn't)


    public class T1 implements EntryPoint {

    public void onModuleLoad() {

    Window window = new Window();
    window.setSize(500,500);

    TreePanelTest tpt = new TreePanelTest();
    window.setLayout( new FitLayout() );
    window.add(tpt);

    }

    public class TreePanelTest extends ContentPanel {

    protected RpcProxy<List<SimpleItem>> proxy;
    protected TreeLoader<SimpleItem> loader;

    protected TreePanel<SimpleItem> tree;
    protected TreeStore<SimpleItem> treeStore;

    protected Button add1;
    protected Button add5;

    public int childIndex = 1;

    public TreePanelTest() {

    proxy = new RpcProxy<List<SimpleItem>>() {

    @Override
    protected void load(Object loadConfig,
    AsyncCallback<List<SimpleItem>> callback) {

    if( loadConfig instanceof SimpleItem ) {

    callback.onSuccess( getData(1) );
    }
    else
    callback.onSuccess( getData(10) );
    }
    };

    loader = new BaseTreeLoader<SimpleItem>(proxy) {

    @Override
    public boolean hasChildren(SimpleItem parent) {
    return parent.hasChildren();
    }
    };

    treeStore = new TreeStore<SimpleItem>(loader);

    tree = new TreePanel<SimpleItem>(treeStore);
    tree.setDisplayProperty("name");

    setLayout( new FitLayout() );
    add(tree);

    ToolBar toolbar = new ToolBar();

    add1 = new Button("Add to First", new SelectionListener<ButtonEvent>() {

    public void componentSelected(ButtonEvent ce) {

    SimpleItem parent = treeStore.getChild(0);
    SimpleItem item = new SimpleItem("New Child " + childIndex++ );
    treeStore.add( parent, item, true );
    };
    });

    add5 = new Button("Add to Fifth", new SelectionListener<ButtonEvent>() {

    public void componentSelected(ButtonEvent ce) {

    SimpleItem parent = treeStore.getChild(5);
    SimpleItem item = new SimpleItem("New Child " + childIndex++ );
    treeStore.add( parent, item, true );
    };
    });

    toolbar.add(add1);
    toolbar.add(add5);

    setTopComponent(toolbar);

    }


    List<SimpleItem> getData( int n ) {

    List<SimpleItem> list = new ArrayList<SimpleItem>();

    for( int i = 0; i < n; i++ ) {

    SimpleItem item = new SimpleItem( "Item " + i );

    if( i == 5 ) {
    SimpleItem child = new SimpleItem( "Item " + i + " Child" );
    item.getChildren().add(child);
    }

    list.add(item);
    }

    return list;
    }

    public class SimpleItem extends BaseModelData {

    List<SimpleItem> children;

    public SimpleItem() {

    children = new ArrayList<SimpleItem>();
    set( "children", children );
    }

    public SimpleItem( String name ) {
    this();
    set( "name", name );
    }

    public List<SimpleItem> getChildren() {
    return children;
    }

    public boolean hasChildren () {
    return children.size() > 0;
    }
    }

    }

  2. #2
    Sencha User darrellmeyer's Avatar
    Join Date
    May 2007
    Location
    Washington, DC
    Posts
    2,242
    Vote Rating
    2
      0  

    Default

    Before a node has been "loaded", it's leaf state is determined by the hasChildren method in the Loader. You code does not return true after add1.

    A point to note is that when the first node is expanded, the added node will be removed, and the children from the remote call will be added. You will need to decide how you want to handle that making changes to the TreeStore before data has been loaded.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •