// TODO to implement
 @Override
 public void handleMenuAction(SelectionEvent<TreeItem> event) {
   TreeItem item = event.getSelectedItem();
   if (item.getUserObject().equals(CATEGORY_MENU)) {
     getModuleListener().connectModule(new CategoryModuleActivity());
   }
 }
Exemplo n.º 2
0
  /**
   * Exported the selected item.
   *
   * @param item Item to export.
   * @param eventListener <tt>Event Listener</tt> for the export operation.
   */
  public static void exportSelectedItem(
      TreeItem item, GetFileNameDialogEventListener eventListener) {
    if (item == null) {
      // TODO add message for internationalization purposes
      Window.alert("Please select the item to export.");
      return;
    }

    if (((Editable) item.getUserObject()).isNew()) {
      // TODO add message for internationalization purposes
      Window.alert("Please first save this item.");
      return;
    }

    String name = "";
    Object studyItem = item.getUserObject();
    if (studyItem instanceof StudyDef) name = ((StudyDef) studyItem).getName();
    else if (studyItem instanceof FormDef)
      name =
          ((StudyDef) item.getParentItem().getUserObject()).getName()
              + "-"
              + ((FormDef) studyItem).getName();
    else if (studyItem instanceof FormDefVersion)
      name =
          ((StudyDef) item.getParentItem().getParentItem().getUserObject()).getName()
              + "-"
              + ((FormDef) item.getParentItem().getUserObject()).getName()
              + "-"
              + ((FormDefVersion) studyItem).getName();

    name = name.replace(" ", "");
    new GetFileNameDialog(
            eventListener, constants.label_export_as(), constants.label_export(), name)
        .center();
  }
Exemplo n.º 3
0
 public void collapseAll() {
   Iterator<TreeItem> i = tree.treeItemIterator();
   while (i.hasNext()) {
     TreeItem ti = i.next();
     ti.setState(false);
   }
 }
 /**
  * Constructs a tree item for generic ("Advanced") component blocks for component types that
  * appear in form.
  *
  * @param form only component types that appear in this Form will be included
  * @return tree item for this form
  */
 public TreeItem getGenericComponentsTree(MockForm form) {
   Map<String, String> typesAndIcons = Maps.newHashMap();
   form.collectTypesAndIcons(typesAndIcons);
   TreeItem advanced = new TreeItem(new HTML("<span>" + MESSAGES.anyComponentLabel() + "</span>"));
   List<String> typeList = new ArrayList<String>(typesAndIcons.keySet());
   Collections.sort(typeList);
   for (final String typeName : typeList) {
     TreeItem itemNode =
         new TreeItem(
             new HTML(
                 "<span>"
                     + typesAndIcons.get(typeName)
                     + MESSAGES.textAnyComponentLabel()
                     + TranslationDesignerPallete.getCorrespondingString(typeName)
                     + "</span>"));
     SourceStructureExplorerItem sourceItem =
         new BlockSelectorItem() {
           @Override
           public void onSelected() {
             fireGenericDrawerSelected(typeName);
           }
         };
     itemNode.setUserObject(sourceItem);
     advanced.addItem(itemNode);
   }
   return advanced;
 }
Exemplo n.º 5
0
  /**
   * 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;
    }
  }
Exemplo n.º 6
0
 public void expandAll() {
   Iterator<TreeItem> i = tree.treeItemIterator();
   while (i.hasNext()) {
     TreeItem ti = i.next();
     ti.setState(true, false);
   }
 }
Exemplo n.º 7
0
  /**
   * 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);
    }
  }
 private int getLevel(TreeItem item) {
   int result = 0;
   while (item.getParentItem() != null) {
     result++;
     item = item.getParentItem();
   }
   return result;
 }
Exemplo n.º 9
0
 /**
  * Bind <tt>FormDefVersion</tt> contents.
  *
  * @param tree <tt>Tree View</tt> to bind <tt>FormDefVersion</tt> to.
  * @param item <tt>FormDefVersion</tt> we binding.
  * @param popup <tt>Popup</tt> to bind to the <tt>Tree View.</tt>
  * @param editable <tt>Editable</tt> we are checking contents for.
  */
 private static void setFormDefVersionContents(
     final Tree tree, final TreeItem item, final PopupPanel popup, Editable editable) {
   if (item == null || !(item.getUserObject() instanceof FormDef))
     Window.alert("Please first select the form to import this version into");
   else {
     ((FormDef) item.getUserObject()).addVersion((FormDefVersion) editable);
     importFormVersion(tree, item, (FormDefVersion) editable, popup);
   }
 }
Exemplo n.º 10
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);
   }
 }
 @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);
   }
 }
Exemplo n.º 12
0
  public TreeItem buildTreeItem(final CategoryItem category) {
    final TreeItem it = new TreeItem();
    it.setHTML(
        AbstractImagePrototype.create(ImageResources.INSTANCE.categorySmall()).getHTML()
            + h(category.getName()));
    it.setUserObject(category);

    return it;
  }
Exemplo n.º 13
0
 /**
  * Bind <tt>FormDef</tt> contents.
  *
  * @param tree <tt>Tree View</tt> to bind <tt>FormDefVersion</tt> to.
  * @param item <tt>FormDefVersion</tt> we binding.
  * @param popup <tt>Popup</tt> to bind to the <tt>Tree View.</tt>
  * @param editable <tt>Editable</tt> we are checking contents for.
  */
 private static void setFormContents(
     final Tree tree, final TreeItem item, final PopupPanel popup, Editable editable) {
   if (item == null || !(item.getUserObject() instanceof StudyDef))
     Window.alert("Please first select the study to import this form into");
   else {
     ((StudyDef) item.getUserObject()).addForm((FormDef) editable);
     importForm(tree, item, (FormDef) editable, popup);
   }
 }
Exemplo n.º 14
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);
    }
  }
  /** Initialize the menu */
  private void intiMenu() {

    removeAll();

    // Item 1 sub-tree
    TreeItem item1 = new TreeItem();

    item1.setText(SafeHtmlUtils.htmlEscape(CATEGORY_MENU));
    item1.setUserObject(CATEGORY_MENU);

    addItem(item1);
  }
Exemplo n.º 16
0
  private void buildPkgTree(TreeItem root, PackageHierarchy.Folder folder) {
    if (folder.getConfig() != null) {
      root.addItem(loadPackage(folder.getName(), folder.getConfig()));
    } else {
      TreeItem treeItem = new TreeItem(Util.getHeader(images.emptyPackage(), folder.getName()));
      root.addItem(treeItem);

      for (PackageHierarchy.Folder childFolder : folder.getChildren()) {
        buildPkgTree(treeItem, childFolder);
      }
    }
  }
Exemplo n.º 17
0
  /**
   * Loads a study and its contents in this view.
   *
   * @param studyDef the study definition object.
   */
  public static void loadStudy(StudyDef studyDef) {

    TreeItem studyRoot =
        new CompositeTreeItem(new TreeItemWidget(images.note(), studyDef.getName(), popup));
    studyRoot.setUserObject(studyDef);
    tree.addItem(studyRoot);

    if (studyDef.getForms() != null) {
      for (FormDef def : studyDef.getForms()) loadForm(def, studyRoot, false);
    }

    Utilities.selectFirstItemOnTreeView(tree);
  }
Exemplo n.º 18
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;
 }
Exemplo n.º 19
0
  /**
   * Removes the given <tt>Form Def Tree Item</tt> from the Parent.
   *
   * @param item <tt>TreeItem</tt> to remove.
   * @param parent <tt>Parent</tt> of <tt>Tree Item.</tt>
   */
  public static void removeFormDefItem(TreeItem item, TreeItem parent) {
    Object userObj = item.getUserObject();
    Object parentUserObj = parent.getUserObject();

    if (userObj instanceof FormDefVersion) {
      ((FormDef) parentUserObj).removeVersion((FormDefVersion) userObj);
      ((FormDef) parentUserObj).setDirty(true);
      ((StudyDef) parent.getParentItem().getUserObject()).setDirty(true);
    } else if (userObj instanceof FormDef) {
      ((StudyDef) parentUserObj).removeForm((FormDef) userObj);
      ((StudyDef) parentUserObj).setDirty(true);
    }
  }
Exemplo n.º 20
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();
 }
Exemplo n.º 21
0
  private void buildPkgTree(TreeItem root, PackageHierarchy.Folder fldr) {
    if (fldr.conf != null) {
      root.addItem(loadPackage(fldr.name, fldr.conf));
    } else {
      TreeItem tn = new TreeItem(Util.getHeader(images.emptyPackage(), fldr.name));
      // itemWidgets.put(item, AssetFormats.BUSINESS_RULE_FORMATS[0]);
      root.addItem(tn);

      for (PackageHierarchy.Folder c : fldr.children) {
        buildPkgTree(tn, c);
      }
    }
  }
Exemplo n.º 22
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());
 }
 private TreeItem add(TreeItem parent, TreeType type) {
   if (type == TreeType.TEXT) {
     return parent.addItem("text");
   } else if (type == TreeType.HTML) {
     TreeItem item = new TreeItem();
     item.setHTML("<h1>html</h1>");
     parent.addItem(item);
     return item;
   } else if (type == TreeType.CHECKBOX) {
     return parent.addItem(new CheckBox("myBox"));
   } else {
     throw new RuntimeException("What?");
   }
 }
Exemplo n.º 24
0
  /**
   * 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);
    }
  }
 private void loadItem(VariableSerializable[] vars) {
   for (int j = 0; j < vars.length; j++) {
     // Do not include variables with subset_variable="true" used to denote "selector"
     // variables in in-situ data sets like SOCAT
     // TODO and for now no variables with character string values
     // if ( Util.keep(vars[j].getDSID(), vars[j].getName()) && Util.keep(vars[j].getDSID(),
     // vars[j].getAttributes()) ) {
     TreeItem item = new TreeItem();
     item.setText(vars[j].getName());
     item.setUserObject(vars[j]);
     currentlySelected.addItem(item);
     // }
   }
 }
Exemplo n.º 26
0
  public void onClick(ClickEvent event) {
    Object sender = event.getSource();

    if (sender == rootHTML) {
      JSONRequest request = new JSONRequest();
      request.doFetchURL(AoAPI.SURVEY_INPUT + survey.getId() + "/", this);
    } else if (promptMap.containsKey(sender)) {
      tree.setSelectedItem(null);
      TreeItem leaf = leaves.get(sender);
      leaf.getTree().setSelectedItem(leaf);
      Prompt p = promptMap.get(sender);
      Messages.get().displaySurveyInput(p, 0);
    }
  }
Exemplo n.º 27
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());
        }
Exemplo n.º 28
0
  /**
   * A helper method to simplify adding tree items that have attached images. {@link
   * #addImageItem(TreeItem, String) code}
   *
   * @param root the tree item to which the new item will be added.
   * @param title the text associated with this item.
   */
  private static TreeItem addImageItem(
      TreeItem root,
      String title,
      ImageResource imageProto,
      Object userObj,
      String helpText,
      PopupPanel popup) {

    TreeItem item = new CompositeTreeItem(new TreeItemWidget(imageProto, title, popup));
    item.setUserObject(userObj);
    item.setTitle(helpText);
    root.addItem(item);
    return item;
  }
Exemplo n.º 29
0
  /**
   * Imports a Form Version.
   *
   * @param tree
   * @param parent
   * @param formDefVersion
   * @param popup
   */
  public static void importFormVersion(
      Tree tree, TreeItem parent, FormDefVersion formDefVersion, PopupPanel popup) {
    formDefVersion.setFormDef((FormDef) parent.getUserObject());

    formDefVersion.setCreator(Context.getAuthenticatedUser());
    formDefVersion.setDateCreated(new Date());
    formDefVersion.setDirty(true);

    TreeItem item =
        addImageItem(
            parent, formDefVersion.getName(), images.markRead(), formDefVersion, null, popup);
    tree.setSelectedItem(item);
    item.getParentItem().setState(true);
  }
Exemplo n.º 30
0
  /**
   * Constructs a <code>StudyDef Tree item root</code> to bind other items to.
   *
   * @param xDef <code>StudyDef</code> for whom to create root.
   * @return Constructed <code>Tree Item.</code>
   */
  private static TreeItem constructTreeItem(StudyDef xDef) {
    TreeItem root = new CompositeTreeItem(new TreeItemWidget(images.note(), xDef.getName(), popup));
    if (root.getUserObject() != null) {
      if (!root.getUserObject().equals(xDef)) {
        root.setUserObject(xDef);
        tree.addItem(root);
      }
    } else {
      root.setUserObject(xDef);
      tree.addItem(root);
    }

    return root;
  }