Esempio n. 1
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();
  }
 private int getLevel(TreeItem item) {
   int result = 0;
   while (item.getParentItem() != null) {
     result++;
     item = item.getParentItem();
   }
   return result;
 }
Esempio n. 3
0
  /**
   * 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);
    }
  }
Esempio n. 4
0
  /**
   * Adds a Child Item to the selected item on the <tt>Tree View.</tt>
   *
   * <p>If a <tt>Study</tt> is selected, a <tt>Form</tt> will be added,
   *
   * <p>If a <tt>Form</tt> is selected, a <tt>Form Version</tt> will be added.
   *
   * <p>
   */
  public static void addNewChildItem(Tree tree, List<StudyDef> studies, PopupPanel popup) {
    String studyName = ""; // Name of study

    TreeItem item = tree.getSelectedItem();
    if (item == null) {
      addNewItem(
          null, tree, studies,
          popup); // Automatically add a new study/form/version to better usability
      return;
    }

    if (item.getUserObject() instanceof StudyDef) {
      studyName =
          ((StudyDef) item.getUserObject()).getName(); // set the value of the study from here

      FormDef formDef =
          new FormDef(
              0, studyName + " Form" + (item.getChildCount() + 1), (StudyDef) item.getUserObject());
      formDef.setCreator(Context.getAuthenticatedUser());
      formDef.setDateCreated(new Date());
      formDef.setDirty(true);

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

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

      item =
          addImageItem(
              item, formDefVersion.getName(), images.markRead(), formDefVersion, null, popup);
      ((FormDef) item.getParentItem().getUserObject()).addVersion(formDefVersion);
      tree.setSelectedItem(item);
      item.getParentItem().setState(true);
    } else addNewItem(null, tree, studies, popup);
  }
Esempio n. 5
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);
    }
  }
Esempio n. 6
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();
 }
Esempio n. 7
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);
  }
 @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);
 }
Esempio n. 9
0
  /**
   * Imports a <tt>FormDef.</tt>
   *
   * @param tree <tt>Tree View</tt> we importing too.
   * @param parent <tt>FormDef</tt> parent. Should be a <tt>StudyDef.</tt>
   * @param formDef <tt>FormDef</tt> we are importing.
   * @param popup <tt>Popup</tt> for the <tt>Tree View.</tt>
   */
  public static void importForm(Tree tree, TreeItem parent, FormDef formDef, PopupPanel popup) {
    formDef.setStudy((StudyDef) parent.getUserObject());

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

    TreeItem item = addImageItem(parent, formDef.getName(), images.drafts(), formDef, null, popup);
    tree.setSelectedItem(item);
    item.getParentItem().setState(true);

    TreeItem versionParent = item;
    List<FormDefVersion> versions = formDef.getVersions();
    if (versions != null) {
      for (FormDefVersion formDefVersion : versions)
        importFormVersion(tree, versionParent, formDefVersion, popup);
    }
  }
Esempio n. 10
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.");
      }
    }
  }