title: Trying to populate details section when clicking on Node of a GWT CellTree
body: <p>Been a user of stackoverflow for the last 2 years but this is my first post.   I have built a CellTree that is populated from a db (RPC call) where each level of the tree is a different object (class).  Host -> Group -> Object -> Element.  What I am trying to do is populate a "details" section on my form that allows the user to edit the details of the node clicked, ultimately displaying the attributes of the class.  In the getNodeInfo section of my TreeViewModel I created an AbstractCell for each class / object.  I then added a click handler to each cell to capture the value / object the user clicks on.  I am able to see the correct value where I have the "System.out.println" line of code.  Where I'm stuck is being able to pass that object back to the form.  </p>
  
  <p>Here's my code, let me know if you need more info ... I blocked out the code for 3 of the levels as its basically the same except for a different class.</p>
  
  <pre class="lang-java prettyprint-override"><code>public &lt;T&gt; NodeInfo&lt;?&gt; getNodeInfo(final T value) {
    // build root host nodes
    if (value == null) {
      final ListDataProvider&lt;Host&gt; dataProvider = new ListDataProvider&lt;Host&gt;();
      AsyncCallback&lt;ArrayList&lt;Host&gt;&gt; callback = new AsyncCallback&lt;ArrayList&lt;Host&gt;&gt;() {
      public void onFailure(Throwable caught) {
        String details = caught.getMessage();
        System.out.println ("Error:  " + details);
      }
      @Override
      public void onSuccess(ArrayList&lt;Host&gt; result) {
        // Add the data to the data provider, which automatically pushes it to the widget.
        final List&lt;Host&gt; hostList = dataProvider.getList();
        for (int i = 0; i &lt; result.size(); i++) {
          Host host = new Host();
          host.setHost_id(result.get(i).getHost_id());
          host.setHost(result.get(i).getHost());
          hostList.add(host);
        }  
      }
    };  
    termSvc.getHosts(callback);
    Cell&lt;Host&gt; cell = new AbstractCell&lt;Host&gt;() {
      public void render(Context context, Host value, SafeHtmlBuilder sb) {
        if (value != null) {
          sb.appendEscaped(value.getHost());
        }
      }
    };
    selectionModelHost.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
      public void onSelectionChange(SelectionChangeEvent event) {
        // TODO Auto-generated method stub
        Host selected = ((SingleSelectionModel&lt;Host&gt;) selectionModelHost).getSelectedObject();
        System.out.println ("Value: " + selected.getHost());
      }
    });
    return new DefaultNodeInfo&lt;Host&gt;(dataProvider, cell, selectionModelHost, null);
    }
    // if its a host then go get the objects
    else if (value instanceof Host) {
      // ....................
    }
    // if its a Group then go get the objects
    else if (value instanceof Group) {
      // ....................
    }
    // if its an object, go get the elements
    else if (value instanceof DGObject) {
      // ....................
    }
    return null;
  }
  </code></pre>
  
  <p>I saw this one which helped:  <a href="https://stackoverflow.com/questions/8843405/gwt-celltree-with-an-optional-pop-up-menu-triggered-on-click-of-a-treenode">GWT CellTree with an optional pop-up menu triggered on click of a TreeNode</a>   And I based a lot of my code on the GWT examples. I searched for an answer already so hopefully I'm headed in the right direction and not asking something that has already been answered.  Thanks </p>
  
  <p>------------- added after Andrea's answer:</p>
  
  <p>Here is the form that calls the celltree.  Currently I only have a label and the celltree on the form as I am trying to determine on the form what node the user is clicking.   I'm populating the tree successfully (and will look into cleaning it up a bit) but struggling to know what the object (node) selected in the tree is to populate the label.</p>
  
  <pre class="lang-java prettyprint-override"><code>public class TabAssetPanel extends Composite {
  
    interface MyUiBinder extends UiBinder&lt;Widget, TabAssetPanel&gt; {
      Widget createAndBindUi(TabAssetPanel tabAssetPanel);
    }
  
    private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
  
    @UiField
    CellTree assetCellTree;
    @UiField
    Label assetSelected;
  
    public TabAssetPanel () {
      initWidget(uiBinder.createAndBindUi(this));
  
      final SingleSelectionModel&lt;String&gt; selectionModel = new SingleSelectionModel&lt;String&gt;();
      selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
          String selected = selectionModel.getSelectedObject();
          assetSelected.setText(selected);
        }
      }); 
  
      AssetTreeViewModel model = new AssetTreeViewModel(selectionModel);
      CellTree assetCellTree = new CellTree(model, "root");
      assetCellTree.setVisible(true);
    }
  
    @UiFactory
    CellTree makeCellTree() { 
  
      final SingleSelectionModel&lt;String&gt; selectionModel = new SingleSelectionModel&lt;String&gt;();
      selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
          String selected = selectionModel.getSelectedObject();
          assetSelected.setText(selected);
        }
      }); 
  
      AssetTreeViewModel model = new AssetTreeViewModel(selectionModel);
      return new CellTree(model, null);
    }
  }
  </code></pre>