@Override
 public void onOpen(OpenEvent<TreeItem> event) {
   TreeItem item = event.getTarget();
   currentlySelected = item;
   if (item.getChild(0).getText().equals(DatasetWidget.LOADING)) {
     CategorySerializable cat = (CategorySerializable) item.getUserObject();
     Util.getRPCService().getCategories(cat.getID(), null, categoryCallback);
   }
 }
 /** Set up the tree and the associated RPC. */
 public void init() {
   try {
     Util.getRPCService().getCategories(null, null, categoryCallback);
   } catch (RuntimeException e) {
     // Catching this exception mainly to allow WindowBuilder to work without error
     e.printStackTrace();
   }
   addOpenHandler(open);
   addSelectionHandler(selection);
 }
        @Override
        public void onESGFDatasetAdded(ESGFDatasetAddedEvent event) {
          saveSelection = currentlySelected;

          // This will cause the result to be added to the top of the tree...
          currentlySelected = null;

          // Clear the tree to re-add all the datasets in this session.
          clear();

          Util.getRPCService().getCategories(null, null, categoryCallback);
        }
 @Override
 public void onSelection(SelectionEvent<TreeItem> event) {
   TreeItem item = event.getSelectedItem();
   currentlySelected = item;
   TreeItem child = item.getChild(0);
   if (child != null && child.getText().equals(DatasetWidget.LOADING)) {
     CategorySerializable cat = (CategorySerializable) item.getUserObject();
     Util.getRPCService().getCategories(cat.getID(), null, categoryCallback);
   }
   // Open the item.  Work around double firing bug.
   // http://code.google.com/p/google-web-toolkit/issues/detail?id=3660&q=Tree%20selection&colspec=ID%20Type%20Status%20Owner%20Milestone%20Summary%20Stars
   TreeItem selItem = event.getSelectedItem();
   TreeItem parent = selItem.getParentItem();
   selItem.getTree().setSelectedItem(parent, false); // null is ok
   if (parent != null) parent.setSelected(false); // not compulsory
   selItem.setState(!selItem.getState(), false);
 }