예제 #1
0
  public static boolean promptChangeSprint(
      final Collection<? extends Artifact> awas, boolean persist) throws OseeCoreException {
    // verify that all awas belong to the same backlog
    SprintItems items = new SprintItems(awas);

    if (items.isNoBacklogDetected()) {
      AWorkbench.popup("Workflow(s) must belong to a Backlog to set their Sprint.");
      return false;
    }
    if (items.isMultipleBacklogsDetected()) {
      AWorkbench.popup("All workflows must belong to same Backlog.");
      return false;
    }

    Artifact backlogArt = (Artifact) items.getCommonBacklog().getStoreObject();
    Artifact agileTeamArt = null;
    try {
      agileTeamArt = backlogArt.getRelatedArtifact(AtsRelationTypes.AgileTeamToBacklog_AgileTeam);
    } catch (ArtifactDoesNotExist ex) {
      // do nothing
    }
    if (agileTeamArt == null) {
      AWorkbench.popup("No Agile Team for Agile Backlog [%s]", backlogArt.toStringWithId());
    }

    Set<IAgileSprint> activeSprints = getActiveSprints(agileTeamArt);

    if (activeSprints.isEmpty()) {
      AWorkbench.popup(
          "No Active Sprints available for the Agile Team [%s]", agileTeamArt.toStringWithId());
      return false;
    }

    SprintFilteredListDialog dialog = createDialog(items, activeSprints);

    if (dialog.open() == 0) {
      if (dialog.isRemoveFromSprint()) {
        for (Artifact awa : awas) {
          Collection<Artifact> relatedSprintArts = AgileUtilClient.getRelatedSprints(awa);
          for (Artifact relatedSprint : relatedSprintArts) {
            awa.deleteRelation(AtsRelationTypes.AgileSprintToItem_Sprint, relatedSprint);
          }
        }
        Artifacts.persistInTransaction("Remove Sprint", awas);

      } else {
        IAgileSprint selectedSprint = dialog.getSelectedFirst();
        for (Artifact awa : awas) {
          Artifact newSprintArt = (Artifact) selectedSprint.getStoreObject();
          Collection<Artifact> relatedSprintArts = AgileUtilClient.getRelatedSprints(awa);
          for (Artifact relatedSprint : relatedSprintArts) {
            awa.deleteRelation(AtsRelationTypes.AgileSprintToItem_Sprint, relatedSprint);
          }
          awa.addRelation(AtsRelationTypes.AgileSprintToItem_Sprint, newSprintArt);
        }
        Artifacts.persistInTransaction("Set Sprint", awas);
      }
      return true;
    }
    return false;
  }
예제 #2
0
  @Override
  public void performDrop(DropTargetEvent event) {
    try {
      TreeItem dragOverTreeITem =
          treeViewer.getTree().getItem(treeViewer.getTree().toControl(event.x, event.y));

      // This should always be true as all items are Group Explorer Items
      if (dragOverTreeITem.getData() instanceof GroupExplorerItem) {
        final GroupExplorerItem dragOverExplorerItem =
            (GroupExplorerItem) dragOverTreeITem.getData();

        // Drag item dropped ON universal group item
        if (dragOverExplorerItem.isUniversalGroup()) {

          // Drag item came from inside Group Explorer
          if (event.data instanceof ArtifactData) {
            // If event originated outside, it's a copy event;
            // OR if event is inside and ctrl is down, this is a copy; add items to group
            if (!((ArtifactData) event.data).getSource().equals(viewId)
                || ((ArtifactData) event.data).getSource().equals(viewId) && isCtrlPressed) {
              copyArtifactsToGroup(event, dragOverExplorerItem);
            }
            // Else this is a move
            else {
              IStructuredSelection selectedItem = (IStructuredSelection) treeViewer.getSelection();
              Iterator<?> iterator = selectedItem.iterator();
              final Set<Artifact> insertArts = new HashSet<Artifact>();
              while (iterator.hasNext()) {
                Object obj = iterator.next();
                if (obj instanceof GroupExplorerItem) {
                  insertArts.add(((GroupExplorerItem) obj).getArtifact());
                }
              }
              GroupExplorerItem parentUnivGroupItem =
                  ((GroupExplorerItem) selectedItem.getFirstElement()).getParentItem();
              final Artifact parentArtifact = parentUnivGroupItem.getArtifact();
              final Artifact targetArtifact = dragOverExplorerItem.getArtifact();

              for (Artifact artifact : insertArts) {
                // Remove item from old group
                parentArtifact.deleteRelation(
                    CoreRelationTypes.Universal_Grouping__Members, artifact);
                // Add items to new group
                targetArtifact.addRelation(CoreRelationTypes.Universal_Grouping__Members, artifact);
              }
              Artifacts.persistInTransaction(
                  "Group Explorer - Drag/Drop", parentArtifact, targetArtifact);
            }
          }
        }
        // Drag item dropped before or after group member
        else if (!dragOverExplorerItem.isUniversalGroup()) {

          if (event.data instanceof ArtifactData) {

            GroupExplorerItem parentUnivGroupItem = null;
            // Drag item came from inside Group Explorer
            if (((ArtifactData) event.data).getSource().equals(viewId)) {
              IStructuredSelection selectedItem = (IStructuredSelection) treeViewer.getSelection();
              Iterator<?> iterator = selectedItem.iterator();
              Set<Artifact> insertArts = new HashSet<Artifact>();
              while (iterator.hasNext()) {
                Object obj = iterator.next();
                if (obj instanceof GroupExplorerItem) {
                  insertArts.add(((GroupExplorerItem) obj).getArtifact());
                }
              }
              parentUnivGroupItem =
                  ((GroupExplorerItem) selectedItem.getFirstElement()).getParentItem();
              insertArts.toArray(new Artifact[insertArts.size()]);

              Artifact parentArtifact = parentUnivGroupItem.getArtifact();
              Artifact targetArtifact = dragOverExplorerItem.getArtifact();

              for (Artifact art : insertArts) {
                parentArtifact.setRelationOrder(
                    CoreRelationTypes.Universal_Grouping__Members,
                    targetArtifact,
                    isFeedbackAfter,
                    art);
                targetArtifact = art;
              }
              parentArtifact.persist(getClass().getSimpleName());
            }
            // Drag item came from outside Group Explorer
            else {
              List<Artifact> insertArts = Arrays.asList(((ArtifactData) event.data).getArtifacts());
              parentUnivGroupItem = dragOverExplorerItem.getParentItem();
              insertArts.toArray(new Artifact[insertArts.size()]);

              Artifact parentArtifact = parentUnivGroupItem.getArtifact();
              Artifact targetArtifact = dragOverExplorerItem.getArtifact();

              for (Artifact art : insertArts) {
                parentArtifact.addRelation(
                    RelationOrderBaseTypes.USER_DEFINED,
                    CoreRelationTypes.Universal_Grouping__Members,
                    targetArtifact,
                    isFeedbackAfter,
                    art,
                    "");
              }
              parentArtifact.persist(getClass().getSimpleName());
            }
          }
        }
        treeViewer.refresh(dragOverExplorerItem);
      }

      isFeedbackAfter = false;
    } catch (Exception ex) {
      OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
    }
  }