Beispiel #1
0
 public void testTree() {
   Tree tree = widgetUi.myTree;
   TreeItem complexItem = widgetUi.myTreeItemC;
   // top level items
   assertEquals(3, tree.getItemCount());
   assertSame(widgetUi.myTreeItemA, tree.getItem(0));
   assertSame(widgetUi.myTreeWidgetB, tree.getItem(1).getWidget());
   assertSame(complexItem, tree.getItem(2));
   // complex item
   assertSame(2, complexItem.getChildCount());
   assertSame(widgetUi.myTreeItemCA, complexItem.getChild(0));
   assertSame(widgetUi.myTreeWidgetCB, complexItem.getChild(1).getWidget());
 }
  /**
   * Change de tree view
   *
   * @param view New view to see
   */
  public void changeView(int view) {
    actualItem = rootItem;
    while (actualItem.getChildCount() > 0) {
      actualItem.getChild(0).remove();
    }

    switch (view) {
      case UIDesktopConstants.NAVIGATOR_TAXONOMY:
        Main.get().activeFolderTree.folderSelectPopup.enableTaxonomy();
      case UIDesktopConstants.NAVIGATOR_TRASH:
        getRoot();
        break;

      case UIDesktopConstants.NAVIGATOR_CATEGORIES:
        Main.get().activeFolderTree.folderSelectPopup.enableCategories();
        getTemplatesFolder();
        break;

      case UIDesktopConstants.NAVIGATOR_TEMPLATES:
        Main.get().activeFolderTree.folderSelectPopup.enableTemplates();
        getTemplatesFolder();
        break;

      case UIDesktopConstants.NAVIGATOR_PERSONAL:
        Main.get().activeFolderTree.folderSelectPopup.enableMyDocuments();
        getPersonal();
        break;

      case UIDesktopConstants.NAVIGATOR_MAIL:
        Main.get().activeFolderTree.folderSelectPopup.enableMails();
        getMail();
        break;
    }
  }
  /**
   * Hides all items on a brach
   *
   * @param actualItem The actual item active
   */
  public void hideAllBranch(TreeItem actualItem) {
    int i = 0;
    int count = actualItem.getChildCount();

    for (i = 0; i < count; i++) {
      actualItem.getChild(i).setVisible(false);
    }
  }
 @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);
   }
 }
Beispiel #5
0
  public void updateTreeItems(TreeItem treeItem, List<FileWrapper> list) {
    if (treeItem == null) treeItem = trtmRoot;

    int index = 0, numberOfChildren = treeItem.getChildCount();
    int newIndex = 0, numberOfNewChildren = list.size();
    while (newIndex < numberOfNewChildren && index < numberOfChildren) {
      FileWrapper fileWrapper = list.get(newIndex);
      if (fileWrapper.getKind() != FileType.DIR) {
        break;
      }
      TreeItem child = treeItem.getChild(index);
      int diff = child.getText().compareTo(fileWrapper.getName());
      if (diff < 0) {
        treeItem.removeItem(child);
      } else if (diff > 0) {
        TreeItem trtmNewItem = new TreeItem();
        treeItem.insertItem(index, trtmNewItem);
        trtmNewItem.setText(fileWrapper.getName());
        index++;
        numberOfChildren++;
        newIndex++;
        presenter.getFiles(trtmNewItem, getPath(trtmNewItem));
      } else {
        index++;
        newIndex++;
        presenter.getFiles(child, getPath(child));
      }
    }
    while (newIndex < numberOfNewChildren) {
      FileWrapper fileWrapper = list.get(newIndex++);
      if (fileWrapper.getKind() != FileType.DIR) {
        break;
      }
      TreeItem trtmNewItem = new TreeItem();
      treeItem.addItem(trtmNewItem);
      trtmNewItem.setText(fileWrapper.getName());
      presenter.getFiles(trtmNewItem, getPath(trtmNewItem));
    }
    while (index < numberOfChildren) {
      treeItem.removeItem(treeItem.getChild(index));
      numberOfChildren--;
    }
  }
  /**
   * Prevents folder inconsistences between server ( multi user deletes folder ) and tree nodes
   * drawn
   *
   * @param item The tree node
   */
  public void preventFolderInconsitences(TreeItem item) {
    GWTFolder folderItem = (GWTFolder) item.getUserObject();

    // Case that must remove all items node
    if (item.getChildCount() > 0 && !folderItem.isHasChildren()) {
      while (item.getChildCount() > 0) {
        item.getChild(0).remove();
      }
    }

    if (item.getChildCount() < 1 && !folderItem.isHasChildren()) {
      folderItem.setHasChildren(false);
    }
  }
Beispiel #7
0
 private int getTreeItemIndex(TreeItem treeItem, String name) {
   int left = 0;
   int right = treeItem.getChildCount() - 1;
   int center = (left + right) / 2;
   while (left <= right) {
     if (treeItem.getChild(center).getText().compareTo(name) < 0) {
       left = center + 1;
     } else {
       right = center - 1;
     }
     center = (left + right) / 2;
   }
   return left;
 }
  /**
   * Adds folders to actual item if not exists or refreshes it values
   *
   * @param actualItem The actual item active
   * @param newItem New item to be added, or refreshed
   */
  public void addFolder(TreeItem actualItem, TreeItem newItem) {
    int i = 0;
    boolean found = false;
    int count = actualItem.getChildCount();
    GWTFolder folder;
    GWTFolder newFolder = (GWTFolder) newItem.getUserObject();
    String folderPath = newFolder.getPath();

    for (i = 0; i < count; i++) {
      folder = (GWTFolder) actualItem.getChild(i).getUserObject();
      // If item is found actualizate values
      if ((folder).getPath().equals(folderPath)) {
        found = true;
        actualItem.getChild(i).setVisible(true);
        actualItem.getChild(i).setUserObject(newFolder);
        evaluesFolderIcon(actualItem.getChild(i));
      }
    }

    if (!found) {
      evaluesFolderIcon(newItem);
      actualItem.addItem(newItem);
    }
  }
  /** Resets all tree values */
  public void reset() {
    actualItem = rootItem;
    actualItem.setSelected(true);
    while (actualItem.getChildCount() > 0) {
      actualItem.getChild(0).remove();
    }

    int mainPanelView = Main.get().mainPanel.desktop.navigator.getStackIndex();

    switch (mainPanelView) {
      case UIDesktopConstants.NAVIGATOR_TAXONOMY:
      case UIDesktopConstants.NAVIGATOR_TRASH:
        Main.get().activeFolderTree.folderSelectPopup.enableTaxonomy();
        getRoot();
        break;

      case UIDesktopConstants.NAVIGATOR_CATEGORIES:
        Main.get().activeFolderTree.folderSelectPopup.enableCategories();
        getCategories();
        break;

      case UIDesktopConstants.NAVIGATOR_TEMPLATES:
        switch (Main.get().activeFolderTree.folderSelectPopup.getAction()) {
          case FolderSelectPopup.ACTION_CREATE_FROM_TEMPLATE:
            Main.get().activeFolderTree.folderSelectPopup.enableTaxonomy();
            getRoot();
            break;

          default:
            Main.get().activeFolderTree.folderSelectPopup.enableTemplates();
            getTemplatesFolder();
            break;
        }

        break;

      case UIDesktopConstants.NAVIGATOR_PERSONAL:
        Main.get().activeFolderTree.folderSelectPopup.enableMyDocuments();
        getPersonal();
        break;

      case UIDesktopConstants.NAVIGATOR_MAIL:
        Main.get().activeFolderTree.folderSelectPopup.enableMails();
        getMail();
        break;
    }
  }
 @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);
 }
Beispiel #11
0
  public void selectFirst() {
    root.setState(true);
    TreeItem firstPrompt = root.getChild(0);
    tree.setSelectedItem(firstPrompt);
    root.setState(true);

    HTML leaf = null;
    for (Entry<HTML, TreeItem> entry : leaves.entrySet()) {
      if (entry.getValue().equals(firstPrompt)) {
        leaf = entry.getKey();
        break;
      }
    }

    if (leaf != null) {
      Prompt p = promptMap.get(leaf);
      Messages.get().displaySurveyInput(p, 0);
    }
  }
  /**
   * Checks if the list of studies is valid for saving.
   *
   * @return true if valid, else false.
   */
  public static boolean isValidStudyList(Tree tree) {
    int index = tree.getItemCount();
    Map<String, String> map = new HashMap<String, String>();

    for (int j = 0; j < index; j++) {

      TreeItem studyItem = tree.getItem(j);
      if (map.containsKey(tree.getItem(j).getText().toLowerCase())) {

        tree.setSelectedItem(studyItem);
        // TODO add message for internationalization purposes
        Window.alert("A study with that same name already exists :" + studyItem.getText());
        return false;
      } else {
        map.put(studyItem.getText().toLowerCase(), studyItem.getText());
      }

      if (studyItem.getChildCount() > 0) {

        Map<String, String> formMap = new HashMap<String, String>();
        int ct = studyItem.getChildCount();

        for (int k = 0; k < ct; ) {
          TreeItem formItem = studyItem.getChild(k);
          if (formMap.containsKey(formItem.getText().toLowerCase())) {

            tree.setSelectedItem(formItem);
            // TODO add message for internationalization purposes
            Window.alert("A form with that same name already exists :" + formItem.getText());
            return false;
          } else {
            formMap.put(formItem.getText().toLowerCase(), formItem.getText());
          }

          return checkFormVersionItems(tree, formItem);
        }
      }
    }

    return true;
  }
  /**
   * Checks if the <tt>FormDefVersion (s)</tt> on the <tt>Tree View</tt> are unique.
   *
   * @param tree <tt>Tree</tt> we checking <tt>FormDef</tt> items from.
   * @param formItem <tt>FormDef</tt> we checking for unique <tt>FormDefVersion (s).</tt>
   */
  private static boolean checkFormVersionItems(Tree tree, TreeItem formItem) {

    if (formItem.getChildCount() > 0) {
      Map<String, String> formVersionMap = new HashMap<String, String>();
      int ct1 = formItem.getChildCount();
      for (int l = 0; l < ct1; ) {

        TreeItem formVItem = formItem.getChild(l);
        if (formVersionMap.containsKey(formVItem.getText().toLowerCase())) {
          tree.setSelectedItem(formVItem);
          // TODO add message for internationalization purposes
          Window.alert("A form version with that same name already exists :" + formVItem.getText());
          return false;
        } else {
          formVersionMap.put(formVItem.getText().toLowerCase(), formVItem.getText());
          return true;
        }
      }
    }
    return true;
  }
 private boolean needsLoading(final TreeItem item) {
   return item.getChildCount() == 1 && LAZY_LOAD.equals(item.getChild(0).getText());
 }
 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;
   }
 }