예제 #1
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);
    }
  }
예제 #2
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);
  }
예제 #3
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);
  }
예제 #4
0
  /**
   * Bind <tt>StudyDef</tt> contents.
   *
   * @param tree <tt>Tree View</tt> to bind <tt>StudyDef</tt> to.
   * @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 setStudyContent(final Tree tree, final PopupPanel popup, Editable editable) {
    StudyDef studyDef = (StudyDef) editable;
    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);
    Context.getStudies().add(studyDef);
    tree.setSelectedItem(root);

    List<FormDef> forms = studyDef.getForms();
    if (forms != null) {
      for (FormDef formDef : forms) importForm(tree, root, formDef, popup);
    }
  }
예제 #5
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);
    }
  }