Example #1
0
  private void buildLessonTree(Response response) {
    TreeItem item = null;
    JsArray<LessonCategoryJS> lessonJSArray = JsonUtils.safeEval(response.getText());

    for (int i = 0; i < lessonJSArray.length(); i++) {
      LessonCategoryJS lessonCategoryJS = lessonJSArray.get(i);
      TreeItem category = new TreeItem();
      category.setText(lessonCategoryJS.getName());

      JsArray<LessonJS> lessons = lessonCategoryJS.getChildren();
      for (int j = 0; j < lessons.length(); j++) {
        LessonJS lesson = lessons.get(j);

        TreeItem lessonItem = new TreeItem();
        Storage sessionStorage = Storage.getSessionStorageIfSupported();
        String lastUrl = sessionStorage.getItem("lastUrl");
        lessonItem.setText(lesson.getText());
        category.addItem(lessonItem);
        lessonsTreeMap.put(lessonItem.getText(), lesson);
        if (lesson.getTechnology().equals(LessonTechnology.GWT.toString())) {
          addLessonToMap(lesson);
        }
        if (lastUrl != null && lastUrl.equals(lesson.getUrl())) {
          item = lessonItem;
          lessonPanel.setSelectedLesson(lesson);
          category.setState(true);
        }
      }
      lessonTree.addItem(category);
    }
    lessonTree.setSelectedItem(item);
  }
Example #2
0
 public void onResponseReceived(Request request, Response response) {
   if (200 == response.getStatusCode()) {
     addTreeItems(response);
     if (treeItem.getText().equals(constants.rootItemDescription()))
       treeItem.setState(true, true);
   } else {
     GWT.log("ResourceTree - Couldn't retrieve JSON for request : " + request.toString(), null);
   }
 }
  /**
   * 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;
  }
Example #4
0
 private String getPath(TreeItem treeItem) {
   Stack<String> pathStack = new Stack<String>();
   while (treeItem != trtmRoot) {
     pathStack.add(treeItem.getText());
     treeItem = treeItem.getParentItem();
   }
   StringBuilder path = new StringBuilder("/");
   while (!pathStack.isEmpty()) {
     path.append(pathStack.pop());
     path.append('/');
   }
   return path.toString();
 }
 @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);
 }
Example #6
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--;
    }
  }
Example #7
0
  // Show the associated widget in the deck panel
  public void onSelection(SelectionEvent<TreeItem> event) {
    TreeItem node = event.getSelectedItem();
    Object userObject = node.getUserObject();

    TabOpener opener = TabOpener.getInstance();

    if (userObject != null) {
      if (userObject instanceof PackageConfigData && !((PackageConfigData) userObject).isGlobal()) {
        PackageConfigData pc = (PackageConfigData) userObject;
        RulePackageSelector.currentlySelectedPackage = pc.name;

        String uuid = pc.uuid;
        opener.openPackageEditor(
            uuid,
            new Command() {
              public void execute() {
                // refresh the package tree.
                refreshTree();
              }
            });
      } else if (userObject instanceof String[]) {
        final String[] formats = (String[]) userObject;
        final PackageConfigData packageConfigData =
            (PackageConfigData) node.getParentItem().getUserObject();
        RulePackageSelector.currentlySelectedPackage = packageConfigData.name;
        String key = key(formats, packageConfigData);
        opener.openPackageViewAssets(
            packageConfigData.uuid,
            packageConfigData.name,
            key,
            formats.length == 0 ? null : Arrays.asList(formats),
            formats.length == 0 ? Boolean.TRUE : null,
            node.getText());
      } else if (userObject instanceof String) {
        // Ignore, there is no click event for this.
      } else {
        throw new IllegalArgumentException("The userObject (" + userObject + ") is not supported.");
      }
    }
  }
  /**
   * 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;
  }