Пример #1
0
  public void onOpen(OpenEvent<TreeItem> event) {
    TreeItem node = event.getTarget();
    Object userObject = node.getUserObject();

    if (userObject != null
        && userObject instanceof String
        && "rootNode".equals((String) userObject)) {
      node.removeItems();
      setupPackageNode(node);
    }
  }
 public void onSuccess(Object result) {
   CategorySerializable[] cats = (CategorySerializable[]) result;
   if (cats != null && cats.length > 0) {
     if (currentlySelected == null) {
       for (int i = 0; i < cats.length; i++) {
         CategorySerializable cat = cats[i];
         String children = cat.getAttributes().get("children");
         boolean empty = false;
         if (children != null && children.equals("none")) empty = true;
         if (applyFilters(cat) && !empty) {
           TreeItem item = new TreeItem();
           item.addItem(
               new SafeHtmlBuilder().appendEscaped(DatasetWidget.LOADING).toSafeHtml());
           InnerItem inner = new InnerItem(cat);
           item.setWidget(inner);
           item.setUserObject(cat);
           addItem(item);
         }
       }
     } else {
       for (int i = 0; i < cats.length; i++) {
         CategorySerializable cat = cats[i];
         if (cat.isCategoryChildren()) {
           String name = cat.getName();
           TreeItem item;
           if (i == 0) {
             item = currentlySelected.getChild(0);
           } else {
             item = new TreeItem();
           }
           item.addItem(
               new SafeHtmlBuilder().appendEscaped(DatasetWidget.LOADING).toSafeHtml());
           InnerItem inner = new InnerItem(cat);
           item.setWidget(inner);
           item.setUserObject(cat);
           if (i > 0) {
             currentlySelected.addItem(item);
           }
         } else if (cat.isVariableChildren()) {
           // Must have variable children...
           TreeItem item = currentlySelected.getChild(0);
           if (cat.hasMultipleDatasets()) {
             DatasetSerializable[] dses = cat.getDatasetSerializableArray();
             DatasetSerializable ds = dses[0];
             VariableSerializable[] vars = ds.getVariablesSerializable();
             currentlySelected.removeItems();
             for (int j = 0; j < dses.length; j++) {
               ds = dses[j];
               vars = ds.getVariablesSerializable();
               loadItem(vars);
             }
           } else {
             DatasetSerializable ds = cat.getDatasetSerializable();
             VariableSerializable[] vars = ds.getVariablesSerializable();
             currentlySelected.removeItems();
             loadItem(vars);
           }
         }
       }
     }
   } else {
     // A category was selected, but it came back empty...
     if (currentlySelected != null) {
       TreeItem item = currentlySelected.getChild(0);
       item.setText("No data sets found.");
     }
   }
   if (saveSelection != null) {
     currentlySelected = saveSelection;
     saveSelection = null;
   }
 }