Search code examples
javagxtuibinder

Expand and select node in Ext GWT 3.0 Tree


I've added an accordion layout container with a tree in its first content pane to my layout. No, a requirement calls to expand and select one node when the application is loaded (it's a mockup).

Then I've added this to the constructor of the class, that corresponds with the uibinder layout:

widget = uiBinder.createAndBindUi(this);               // everything's bound

accordionLayoutContainer.setActiveWidget(firstPanel);  // OK, expands first pane
tree.getSelectionModel().select(mynode, true);        // no visible effect
tree.setExpanded(mynode, false);                       // no visible effect

What's missing here? Do I have to force the layout of "something" after setting the states or is it the wrong place to select and expand nodes?


Solution

  • Found the solution. The call to setExpand has to be deferred until the tree has been attached. So I added an AttachEvent.Handler to a parent widget - adding it to directly to the tree doesn't work, because the handler is called to early, before the models are registered.

    widget = uiBinder.createAndBindUi(this);               // everything's bound
    
    accordionLayoutContainer.setActiveWidget(firstPanel);  // OK, expands first pane
    accordionLayoutContainer.addAttachHandler(new AttachEvent.Handler() {
    
      @Override
      public void onAttachOrDetach(AttachEvent event) {
        clientsTree.getSelectionModel().select(mynode, true);
        clientsTree.setExpanded(mynode, true);              
      }
    });