Ejemplo n.º 1
0
  private void removeDuplicates(List<DiagramElementTreeNode> children) {
    List<DiagramElementTreeNode> duplicates = new ArrayList<DiagramElementTreeNode>();
    for (DiagramElementTreeNode node : children) {
      if (node.hasChildren()) removeDuplicates(node.getChildren());

      BaseElement be = node.getBaseElement();
      if (be instanceof Collaboration) {
        Collaboration c = (Collaboration) be;
        for (Participant p : c.getParticipants()) {
          for (DiagramElementTreeNode n : children) {
            if (n.getBaseElement() == p.getProcessRef()) {
              duplicates.add(n);
            }
          }
        }
      } else if (be instanceof ChoreographyActivity) {
        ChoreographyActivity c = (ChoreographyActivity) be;
        for (Participant p : c.getParticipantRefs()) {
          for (DiagramElementTreeNode n : children) {
            if (n.getBaseElement() == p) {
              duplicates.add(n);
            }
          }
        }
      }
    }
    if (!duplicates.isEmpty()) children.removeAll(duplicates);
  }
  void createDefinitionsIfMissing() {
    EList<EObject> contents = resource.getContents();

    if (contents.isEmpty() || !(contents.get(0) instanceof DocumentRoot)) {
      TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(resource);

      if (domain != null) {
        final DocumentRoot docRoot = FACTORY.createDocumentRoot();
        final Definitions definitions = FACTORY.createDefinitions();
        //				definitions.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(definitions, resource);
        Collaboration collaboration = FACTORY.createCollaboration();
        //				collaboration.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(collaboration, resource);
        Participant participant = FACTORY.createParticipant();
        //				participant.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(participant, resource);
        participant.setName("Internal");
        collaboration.getParticipants().add(participant);
        definitions.getRootElements().add(collaboration);

        domain
            .getCommandStack()
            .execute(
                new RecordingCommand(domain) {
                  @Override
                  protected void doExecute() {
                    docRoot.setDefinitions(definitions);
                    resource.getContents().add(docRoot);
                  }
                });
        return;
      }
    }
  }
Ejemplo n.º 3
0
 public static EObject getTargetObject(ITargetContext context) {
   ContainerShape targetContainer = context.getTargetContainer();
   EObject targetObject = BusinessObjectUtil.getBusinessObjectForPictogramElement(targetContainer);
   if (targetObject instanceof BPMNDiagram) {
     targetObject = ((BPMNDiagram) targetObject).getPlane().getBpmnElement();
   }
   if (targetObject instanceof Lane) {
     while (targetObject != null) {
       targetObject = targetObject.eContainer();
       if (targetObject instanceof FlowElementsContainer) break;
     }
   }
   if (targetObject instanceof Collaboration && !(targetObject instanceof Choreography)) {
     Collaboration collaboration = (Collaboration) targetObject;
     for (Participant p : collaboration.getParticipants()) {
       if (p.getProcessRef() != null) {
         targetObject = p.getProcessRef();
         break;
       }
     }
   }
   if (targetObject instanceof Participant) {
     targetObject = ((Participant) targetObject).getProcessRef();
   }
   return targetObject;
 }
 public Participant addParticipant() {
   Collaboration collaboration = getOrCreateCollaboration();
   Participant participant = FACTORY.createParticipant();
   //		participant.setId(EcoreUtil.generateUUID());
   ModelUtil.setID(participant, resource);
   collaboration.getParticipants().add(participant);
   return participant;
 }
Ejemplo n.º 5
0
  private BPMNDiagram createDIDiagram(BaseElement bpmnElement) {

    BPMNDiagram bpmnDiagram = DIUtils.findBPMNDiagram(bpmnElement, true);

    // if this container does not have a BPMNDiagram, create one
    if (bpmnElement instanceof Process) {
      if (bpmnDiagram == null) {
        // unless this Process is referenced by a Pool
        for (Collaboration c :
            ModelUtil.getAllObjectsOfType(bpmnElement.eResource(), Collaboration.class)) {
          for (Participant p : c.getParticipants()) {
            if (!ModelUtil.isParticipantBand(p)) {
              if (p.getProcessRef() == bpmnElement) {
                bpmnDiagram = DIUtils.findBPMNDiagram(p, true);
                break;
              }
            }
          }
          if (bpmnDiagram != null) break;
        }
      } else {
        // Always create a new BPMNDiagram if this Process is being referenced by a Participant Band
        //				for (Collaboration c : ModelUtil.getAllObjectsOfType(bpmnElement.eResource(),
        // Collaboration.class)) {
        //					for (Participant p : c.getParticipants()) {
        //						if (ModelUtil.isParticipantBand(p)) {
        //							if (p.getProcessRef() == bpmnElement) {
        //								bpmnDiagram = null;
        //								break;
        //							}
        //						}
        //					}
        //					if (bpmnDiagram==null)
        //						break;
        //				}
      }
    }

    if (bpmnDiagram == null) {
      FlowElementsContainer container = getRootElementContainer(bpmnElement);
      if (container == null) {
        diagnostics.add(IStatus.ERROR, bpmnElement, Messages.DIGenerator_No_Diagram);
        return this.bpmnDiagram;
      }
      BPMNPlane plane = BpmnDiFactory.eINSTANCE.createBPMNPlane();
      plane.setBpmnElement(container);

      bpmnDiagram = BpmnDiFactory.eINSTANCE.createBPMNDiagram();
      bpmnDiagram.setName(ExtendedPropertiesProvider.getTextValue(container));
      bpmnDiagram.setPlane(plane);

      definitions.getDiagrams().add(bpmnDiagram);
    }

    return bpmnDiagram;
  }
 private void addCollaborationToRootElements(
     final List<RootElement> rootElements, final Collaboration collaboration) {
   Participant participant = FACTORY.createParticipant();
   //		participant.setId(EcoreUtil.generateUUID());
   ModelUtil.setID(participant, resource);
   participant.setName("Internal");
   for (RootElement element : rootElements) {
     if (element instanceof Process) {
       participant.setProcessRef((Process) element);
       break;
     }
   }
   collaboration.getParticipants().add(participant);
   rootElements.add(collaboration);
 }
Ejemplo n.º 7
0
  private void findMissingDIElements(DiagramElementTreeNode missing, BaseElement be) {
    if (be instanceof FlowElementsContainer) {
      // handles Process/SubProcess and Choreography/SubChoreography
      FlowElementsContainer container = (FlowElementsContainer) be;
      DiagramElementTreeNode parentNode = null;

      List<FlowElement> laneElements = new ArrayList<FlowElement>();
      for (LaneSet laneSet : container.getLaneSets()) {
        findMissingDIElements(missing, laneSet, laneElements);
      }

      for (FlowElement fe : container.getFlowElements()) {
        if (isMissingDIElement(fe) && !laneElements.contains(fe)) {
          if (fe instanceof SequenceFlow || fe instanceof DataObject || fe instanceof DataStore)
            continue;
          if (parentNode == null) parentNode = missing.addChild(container);
          parentNode.addChild(fe);
          if (fe instanceof FlowElementsContainer || fe instanceof ChoreographyActivity) {
            findMissingDIElements(parentNode, fe);
          }
        }
      }
      List<Artifact> artifacts = getArtifacts(container);
      if (artifacts != null) {
        for (Artifact a : artifacts) {
          if (isMissingDIElement(a) && !(a instanceof Association)) {
            if (parentNode == null) parentNode = missing.addChild(container);
            parentNode.addChild(a);
          }
        }
      }
    }

    // Choreography inherits both Collaboration and FlowElementsContainer
    if (be instanceof Collaboration) {
      // also handle Choreography
      Collaboration container = (Collaboration) be;
      DiagramElementTreeNode parentNode = null;
      for (Artifact a : container.getArtifacts()) {
        if (isMissingDIElement(a) && !(a instanceof Association)) {
          if (parentNode == null) parentNode = missing.addChild(container);
          parentNode.addChild(a);
        }
      }
      for (Participant p : container.getParticipants()) {
        boolean isParticipantBand = false;
        if (p.eContainer() instanceof Choreography) {
          // this may be a Choreography Activity Participant band
          Choreography choreography = (Choreography) p.eContainer();
          for (FlowElement fe : choreography.getFlowElements()) {
            if (fe instanceof ChoreographyActivity) {
              if (((ChoreographyActivity) fe).getParticipantRefs().contains(p)) {
                isParticipantBand = true;
                break;
              }
            }
          }
        }
        if (isMissingDIElement(p)
            && p.getProcessRef() != null
            && isMissingDIElement(p.getProcessRef())
            && !isParticipantBand) {
          if (parentNode == null) parentNode = missing.addChild(container);
          parentNode.addChild(p);
        }
      }
      for (ConversationNode c : container.getConversations()) {
        if (isMissingDIElement(c)) {
          if (parentNode == null) parentNode = missing.addChild(container);
          parentNode.addChild(c);
        }
      }
    } else if (be instanceof Participant) {
      Participant container = (Participant) be;
      if (container.getProcessRef() != null) {
        DiagramElementTreeNode parentNode = missing.addChild(container);
        parentNode.addChild(container.getProcessRef());
      }
    } else if (be instanceof ChoreographyActivity) {
      ChoreographyActivity container = (ChoreographyActivity) be;
      DiagramElementTreeNode parentNode = null;
      for (Participant p : container.getParticipantRefs()) {
        if (isMissingDIElement(p)) {
          if (parentNode == null) parentNode = missing.addChild(container);
          DiagramElementTreeNode child = parentNode.addChild(p);
          if (p.getProcessRef() != null) findMissingDIElements(child, p.getProcessRef());
        }
      }
    } else if (isDataElement(be)) {
      if (isMissingDIElement(be)) {
        missing.addChild(be);
      }
    }
  }