/**
   * Adds a new Item according to selected item on the <tt>Tree View.</tt>
   *
   * <p>If a <Study</tt> is selected, a new <tt>Study</tt> will be added.
   *
   * <p>If a <tt>Form</tt> is selected, a new <tt>Form</tt> will be added.
   *
   * <p>If a <tt>Form Version</tt> is selected, a new <tt>Form Version</tt> will be added.
   */
  public static void addNewItem(String xForm, Tree tree, List<StudyDef> studies, PopupPanel popup) {

    TreeItem item = tree.getSelectedItem();
    if (item == null || item.getUserObject() instanceof StudyDef) {
      StudyDef studyDef = new StudyDef(0, "New Study" + (tree.getItemCount() + 1));
      studyDef.setCreator(Context.getAuthenticatedUser());
      studyDef.setDateCreated(new Date());
      studyDef.setDirty(true);

      TreeItem root =
          new CompositeTreeItem(new TreeItemWidget(images.note(), studyDef.getName(), popup));
      root.setUserObject(studyDef);
      tree.addItem(root);
      studies.add(studyDef);
      tree.setSelectedItem(root);

      // Automatically add a new form
      addNewChildItem(tree, studies, popup);

    } else if (item.getUserObject() instanceof FormDef) {
      TreeItem parent = item.getParentItem();
      FormDef formDef =
          new FormDef(
              0, "New Form" + (parent.getChildCount() + 1), (StudyDef) parent.getUserObject());
      formDef.setCreator(Context.getAuthenticatedUser());
      formDef.setDateCreated(new Date());
      formDef.setDirty(true);

      item = addImageItem(parent, formDef.getName(), images.drafts(), formDef, null, popup);
      ((StudyDef) parent.getUserObject()).addForm(formDef);
      tree.setSelectedItem(item);
      parent.setState(true);

      // Automatically add a new form version
      addNewChildItem(tree, studies, popup);
    } else if (item.getUserObject() instanceof FormDefVersion) {
      TreeItem parent = item.getParentItem();
      FormDefVersion formDefVersion =
          new FormDefVersion(
              0, "v" + (parent.getChildCount() + 1), (FormDef) parent.getUserObject());
      formDefVersion.setCreator(Context.getAuthenticatedUser());
      formDefVersion.setDateCreated(new Date());
      formDefVersion.getFormDef().turnOffOtherDefaults(formDefVersion);
      formDefVersion.setDirty(true);

      if (xForm != null) formDefVersion.setXform(xForm);

      item =
          addImageItem(
              parent, formDefVersion.getName(), images.markRead(), formDefVersion, null, popup);
      ((FormDef) parent.getUserObject()).addVersion(formDefVersion);
      tree.setSelectedItem(item);
      parent.setState(true);
    }
  }
 public void expandAll() {
   Iterator<TreeItem> i = tree.treeItemIterator();
   while (i.hasNext()) {
     TreeItem ti = i.next();
     ti.setState(true, false);
   }
 }
 public void collapseAll() {
   Iterator<TreeItem> i = tree.treeItemIterator();
   while (i.hasNext()) {
     TreeItem ti = i.next();
     ti.setState(false);
   }
 }
Example #4
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 #5
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);
   }
 }
Example #6
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);
    }
  }
Example #7
0
 /**
  * Create the {@link Tree} of Mail options.
  *
  * @param images the {@link Images} used in the Mail options
  * @return the {@link Tree} of mail options
  */
 @ShowcaseSource
 private Tree createMailItem(Images images) {
   Tree mailPanel = new Tree(images);
   TreeItem mailPanelRoot = mailPanel.addItem("*****@*****.**");
   String[] mailFolders = constants.cwStackPanelMailFolders();
   addItem(mailPanelRoot, images.inbox(), mailFolders[0]);
   addItem(mailPanelRoot, images.drafts(), mailFolders[1]);
   addItem(mailPanelRoot, images.templates(), mailFolders[2]);
   addItem(mailPanelRoot, images.sent(), mailFolders[3]);
   addItem(mailPanelRoot, images.trash(), mailFolders[4]);
   mailPanelRoot.setState(true);
   return mailPanel;
 }
  public void addChildren(final CategoryItem parent, final String name, final String description) {
    final CategoryItem child = parent.addChildren(name, description);

    final TreeItem parentTree;
    if (getSelectedCategory() == null) {
      parentTree = navTreeWidget.getItem(0);
    } else {
      parentTree = navTreeWidget.getSelectedItem();
    }

    final TreeItem ct = buildTreeItem(child);
    parentTree.addItem(ct);
    parentTree.setState(true);
  }
Example #9
0
        public void onSuccess(GWTFolder result) {
          // Only executes on initalization and the actualItem is root
          // element on initialization
          // We put the id on root
          actualItem.setUserObject(result);
          evaluesFolderIcon(actualItem);
          actualItem.setState(true);
          actualItem.setSelected(true);

          // Enables or disables move button ( evalues security to move to folder with permissions )
          evaluateSecurityToAction(actualItem);

          getChilds(result.getPath());
        }
  protected void buildTree(final Categories categories) {
    final TreeItem root = new TreeItem();
    root.setHTML(AbstractImagePrototype.create(ImageResources.INSTANCE.desc()).getHTML());
    navTreeWidget.addItem(root);

    for (final CategoryItem category : categories) {
      final TreeItem it = buildTreeItem(category);
      root.addItem(it);

      if (category.hasChild()) {
        loadChildren(it, category);
      }
    }

    root.setState(true);
  }
 @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);
 }
  /**
   * Loads a form and its contents in the view.
   *
   * @param formDef the form definition object.
   * @param studyRoot the tree item for the study which is the parent of this form.
   * @param select set to true to automatically select the given study.
   */
  private static void loadForm(FormDef formDef, TreeItem studyRoot, boolean select) {

    TreeItem formRoot =
        StudiesTreeViewHelper.addImageItem(
            studyRoot, formDef.getName(), images.drafts(), formDef, "", popup);

    List<FormDefVersion> versions = formDef.getVersions();
    if (versions != null) {
      for (FormDefVersion versionDef : versions) {
        addImageItem(formRoot, versionDef.getName(), images.markRead(), versionDef, null, popup);
      }
    }

    if (select) {
      tree.setSelectedItem(studyRoot);
      studyRoot.setState(true);
    }
  }
Example #13
0
  /** Folder Tree */
  public FolderSelectTree() {
    tree = new Tree();
    rootItem.setStyleName("okm-TreeItem");
    rootItem.setUserObject(new GWTFolder());
    rootItem.setSelected(true);
    rootItem.setState(true);
    tree.setStyleName("okm-Tree");
    tree.addItem(rootItem);
    tree.addSelectionHandler(
        new SelectionHandler<TreeItem>() {

          @Override
          public void onSelection(SelectionEvent<TreeItem> event) {
            boolean refresh = true;
            TreeItem item = event.getSelectedItem();

            // Enables or disables move button ( evalues security to move to folder with permissions
            // )
            evaluateSecurityToAction(item);

            // Case that not refreshing tree and file browser ( right click )
            if (actualItem.equals(item)) {
              refresh = false;
            } else {
              // Disables actual item because on changing active node by
              // application this it's not changed automatically
              if (!actualItem.equals(item)) {
                actualItem.setSelected(false);
                actualItem = item;
              } else {
                refresh = false;
              }
            }

            if (refresh) {
              refresh(true);
            }
          }
        });
    actualItem = tree.getItem(0);
    initWidget(tree);
  }
Example #14
0
  private void setupPackageNode(final TreeItem packageRootNode) {
    packageRootNode.setState(true);
    packageRootNode.setUserObject(new String("rootNode"));

    RepositoryServiceFactory.getService()
        .listPackages(
            new GenericCallback<PackageConfigData[]>() {
              public void onSuccess(PackageConfigData[] packageConfigDatas) {
                PackageHierarchy packageHierarchy = new PackageHierarchy();

                for (PackageConfigData packageConfigData : packageConfigDatas) {
                  packageHierarchy.addPackage(packageConfigData);
                }

                for (PackageHierarchy.Folder folder : packageHierarchy.getRoot().getChildren()) {
                  buildPkgTree(packageRootNode, folder);
                }
              }
            });
  }
Example #15
0
        public void onSuccess(List<GWTFolder> result) {
          boolean directAdd = true;

          // If has no childs directly add values is permited
          if (actualItem.getChildCount() > 0) {
            directAdd = false;
            // to prevent remote folder remove it disables all tree branch
            // items and after sequentially activate
            hideAllBranch(actualItem);
          }

          // On refreshing not refreshed the actual item values but must
          // ensure that has childs value is consistent
          if (result.isEmpty()) {
            ((GWTFolder) actualItem.getUserObject()).setHasChildren(false);
          } else {
            ((GWTFolder) actualItem.getUserObject()).setHasChildren(true);
          }

          // Ads folders childs if exists
          for (Iterator<GWTFolder> it = result.iterator(); it.hasNext(); ) {
            GWTFolder folder = it.next();
            TreeItem folderItem = new TreeItem(folder.getName());
            folderItem.setUserObject(folder);
            folderItem.setStyleName("okm-TreeItem");

            // If has no childs directly add values is permited, else
            // evalues each node to refresh, remove or add
            if (directAdd) {
              evaluesFolderIcon(folderItem);
              actualItem.addItem(folderItem);
            } else {
              // sequentially activate items and refreshes values
              addFolder(actualItem, folderItem);
            }
          }

          actualItem.setState(true);
          evaluesFolderIcon(actualItem);
        }
Example #16
0
  private void setupPackagesTree() {
    TreeItem packageRootNode =
        mainTree.addItem(Util.getHeader(images.chartOrganisation(), constants.Packages()));
    packageRootNode.setState(true);
    loadPackages(packageRootNode, itemWidgets);
    mainTree.addItem(packageRootNode);

    loadGlobal(mainTree, itemWidgets);

    /*            @Override
    public void onCollapseNode(final TreeItem node) {
        if (node.getText().equals(constants.Packages())) {
            Node[] children = node.getChildNodes();
            for (Node child : children) {
                node.removeChild(child);
            }
            loadPackages(node, itemWidgets);
        }
    }*/

    // return mainTree;
  }
 /**
  * Constructs a tree item for built-in blocks.
  *
  * @return tree item
  */
 public TreeItem getBuiltInBlocksTree() {
   initBundledImages();
   TreeItem builtinNode =
       new TreeItem(new HTML("<span>" + MESSAGES.builtinBlocksLabel() + "</span>"));
   for (final String drawerName : BUILTIN_DRAWER_NAMES) {
     Image drawerImage = new Image(bundledImages.get(drawerName));
     TreeItem itemNode =
         new TreeItem(
             new HTML("<span>" + drawerImage + getBuiltinDrawerNames(drawerName) + "</span>"));
     SourceStructureExplorerItem sourceItem =
         new BlockSelectorItem() {
           @Override
           public void onSelected() {
             fireBuiltinDrawerSelected(drawerName);
           }
         };
     itemNode.setUserObject(sourceItem);
     builtinNode.addItem(itemNode);
   }
   builtinNode.setState(true);
   return builtinNode;
 }
Example #18
0
  public void addTag(final String tagInstanceID) {

    ClientTagInstance tagInstance = vTagger.getTagInstance(tagInstanceID);

    Grid grid = new Grid(1, 3);
    Label l = new HTML("#" + tagInstanceID);
    grid.setWidget(0, 0, l);

    PushButton tagRemoveButton = new PushButton("remove");
    // tagRemoveButton.addStyleName("tagger-pushButton");
    grid.setWidget(0, 1, tagRemoveButton);
    HandlerRegistration tagRemoveBtReg =
        tagRemoveButton.addClickHandler(
            new ClickHandler() {

              public void onClick(ClickEvent event) {
                vTagger.removeTagInstance(tagInstanceID);
                hide();
              }
            });
    handlerRegistrations.add(tagRemoveBtReg);

    PushButton tagEditButton = new PushButton("edit");
    // tagEditButton.addStyleName("tagger-pushButton");
    tagEditButton.setEnabled(false);
    grid.setWidget(0, 2, tagEditButton);
    HandlerRegistration tagEditBtReg =
        tagEditButton.addClickHandler(
            new ClickHandler() {

              public void onClick(ClickEvent event) {}
            });
    handlerRegistrations.add(tagEditBtReg);
    root.addItem(grid);
    root.setState(true);
  }
Example #19
0
 public void close() {
   tree.setSelectedItem(null);
   root.setState(false);
 }
Example #20
0
  public TagMenuPopup(TaggerEditor vTagger, String lastSelectedColor) {
    super(true);
    getElement().addClassName("tagmenu-popup");
    this.setText("Annotations");
    this.vTagger = vTagger;
    this.lastSelectedColor = lastSelectedColor;
    root = new TreeItem("Available annotations");
    final Tree tree = new Tree();
    tree.addItem(root);
    root.setState(true);
    root.setStyleName("tagger_menu_root");

    final VerticalPanel vPanel = new VerticalPanel();

    if (vTagger.hasSelection()) {

      final VerticalPanel annotationCreationPanel = new VerticalPanel();
      annotationCreationPanel.setSpacing(5);
      annotationCreationPanel.setWidth("100%");
      final TextArea annotationBodyInput = new TextArea();
      annotationBodyInput.setWidth("90%");
      annotationCreationPanel.add(annotationBodyInput);
      final HorizontalPanel annotationCreationButtonPanel = new HorizontalPanel();
      annotationCreationButtonPanel.setSpacing(5);
      final Label colorLabel = new HTML("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
      final ColorPicker colorPicker =
          new ColorPicker() {
            @Override
            public void onChange(Widget sender) {
              super.onChange(sender);
              colorLabel
                  .getElement()
                  .setAttribute("style", "background:#" + this.getHexColor() + ";");
            }
          };
      try {
        if (lastSelectedColor != null) {
          colorPicker.setHex(lastSelectedColor);
        } else {
          int[] randomColor = getRandomColor();
          colorPicker.setRGB(randomColor[0], randomColor[1], randomColor[2]);
        }
      } catch (Exception e) {
        // well...
      }
      colorLabel
          .getElement()
          .setAttribute("style", "background:#" + colorPicker.getHexColor() + ";");

      HorizontalPanel colorPanel = new HorizontalPanel();
      colorPanel.setSpacing(5);
      PushButton colorButton = new PushButton("Change color...");
      colorPanel.add(colorButton);

      colorPanel.add(colorLabel);

      HandlerRegistration colorButtonReg =
          colorButton.addClickHandler(
              new ClickHandler() {

                public void onClick(ClickEvent event) {

                  annotationCreationPanel.insert(
                      colorPicker,
                      annotationCreationPanel.getWidgetIndex(annotationCreationButtonPanel));
                  TagMenuPopup.this.center();
                }
              });
      handlerRegistrations.add(colorButtonReg);
      annotationCreationPanel.add(colorPanel);

      PushButton saveButton = new PushButton("Save");
      // saveButton.setStylePrimaryName("tagger-pushButton");
      HandlerRegistration saveButtonReg =
          saveButton.addClickHandler(
              new ClickHandler() {

                public void onClick(ClickEvent event) {
                  //	TagMenuPopup.this.vTagger.createAndAddTagIntance(colorPicker.getHexColor());
                  TagMenuPopup.this.lastSelectedColor = colorPicker.getHexColor();
                  hide();
                }
              });
      handlerRegistrations.add(saveButtonReg);

      PushButton cancelButton = new PushButton("Cancel");
      // cancelButton.setStylePrimaryName("tagger-pushButton");

      annotationCreationButtonPanel.add(saveButton);
      annotationCreationButtonPanel.add(cancelButton);
      annotationCreationPanel.add(annotationCreationButtonPanel);

      PushButton addAnnotationButton = new PushButton("Add annotation...");
      // addAnnotationButton.setStylePrimaryName("tagger-pushButton");

      HandlerRegistration addAnnotationBtReg =
          addAnnotationButton.addClickHandler(
              new ClickHandler() {

                public void onClick(ClickEvent event) {
                  vPanel.insert(annotationCreationPanel, vPanel.getWidgetIndex(tree));
                }
              });
      handlerRegistrations.add(addAnnotationBtReg);
      vPanel.add(addAnnotationButton);

      HandlerRegistration cancelButtonReg =
          cancelButton.addClickHandler(
              new ClickHandler() {
                public void onClick(ClickEvent event) {
                  annotationBodyInput.setText("");
                  vPanel.remove(annotationCreationPanel);
                }
              });

      handlerRegistrations.add(cancelButtonReg);
    }

    vPanel.add(tree);
    vPanel.setStylePrimaryName("tagger_menu");
    setWidget(vPanel);
  }