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;
      }
    }
  }
  public Definitions createAndInitResource(URI uri) {
    DroolsFactoryImpl.init();
    BpsimFactoryImpl.init();
    Resource resource = createResource(uri);
    Bpmn2Factory factory = Bpmn2Factory.eINSTANCE;
    Definitions definitions = factory.createDefinitions();
    DocumentRoot docummentRoot = factory.createDocumentRoot();
    docummentRoot.setDefinitions(definitions);
    resource.getContents().add(docummentRoot);

    return definitions;
  }
 public Lane createLane(Object target) {
   Lane lane = FACTORY.createLane();
   //		lane.setId(EcoreUtil.generateUUID());
   ModelUtil.setID(lane, resource);
   FlowElementsContainer container = getFlowElementContainer(target);
   if (container.getLaneSets().isEmpty()) {
     LaneSet laneSet = FACTORY.createLaneSet();
     //			laneSet.setId(EcoreUtil.generateUUID());
     container.getLaneSets().add(laneSet);
   }
   container.getLaneSets().get(0).getLanes().add(lane);
   ModelUtil.setID(lane);
   return lane;
 }
  private Collaboration getOrCreateCollaboration() {
    final List<RootElement> rootElements = getDefinitions().getRootElements();

    for (RootElement element : rootElements) {
      if (element instanceof Collaboration) {
        return (Collaboration) element;
      }
    }
    TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(resource);
    final Collaboration collaboration = FACTORY.createCollaboration();
    //		collaboration.setId(EcoreUtil.generateUUID());
    ModelUtil.setID(collaboration, resource);
    if (domain != null) {
      domain
          .getCommandStack()
          .execute(
              new RecordingCommand(domain) {

                @Override
                protected void doExecute() {
                  addCollaborationToRootElements(rootElements, collaboration);
                }
              });
    }
    return collaboration;
  }
 public ConversationLink createConversationLink(InteractionNode source, InteractionNode target) {
   ConversationLink link = FACTORY.createConversationLink();
   link.setSourceRef(source);
   link.setTargetRef(target);
   getOrCreateCollaboration().getConversationLinks().add(link);
   return link;
 }
  @Test
  @DiagramResource("org/camunda/bpm/modeler/test/ui/change/ChangeSupportTest.testBase.bpmn")
  public void testAttributeUpdate() {
    final SequenceFlow sequenceFlow2 =
        findBusinessObjectById(diagram, "SequenceFlow_2", SequenceFlow.class);

    FeatureChangeFilter filter =
        new FeatureChangeFilter(sequenceFlow2, CONDITION_EXPRESSION_FEATURE);
    CustomResourceSetListener listener = new CustomResourceSetListener(sequenceFlow2, filter);
    listener.register();

    final FormalExpression expression = bpmn2factory.createFormalExpression();
    expression.setBody("FOOO");

    transactionalExecute(
        new RecordingCommand(editingDomain) {

          @Override
          protected void doExecute() {
            sequenceFlow2.setConditionExpression(expression);
          }
        });

    assertThat(listener.getCapturedEvents()).hasSize(1);
  }
 public void laneToTop(Lane lane) {
   LaneSet laneSet = FACTORY.createLaneSet();
   //		laneSet.setId(EcoreUtil.generateUUID());
   ModelUtil.setID(laneSet, resource);
   laneSet.getLanes().add(lane);
   Process process = getOrCreateProcess(getInternalParticipant());
   process.getLaneSets().add(laneSet);
 }
 public Participant addParticipant() {
   Collaboration collaboration = getOrCreateCollaboration();
   Participant participant = FACTORY.createParticipant();
   //		participant.setId(EcoreUtil.generateUUID());
   ModelUtil.setID(participant, resource);
   collaboration.getParticipants().add(participant);
   return participant;
 }
 public MessageFlow createMessageFlow(InteractionNode source, InteractionNode target) {
   MessageFlow messageFlow = FACTORY.createMessageFlow();
   //		messageFlow.setId(EcoreUtil.generateUUID());
   ModelUtil.setID(messageFlow, resource);
   messageFlow.setSourceRef(source);
   messageFlow.setTargetRef(target);
   getOrCreateCollaboration().getMessageFlows().add(messageFlow);
   return messageFlow;
 }
  public SequenceFlow createSequenceFlow(FlowNode source, FlowNode target) {
    SequenceFlow sequenceFlow = FACTORY.createSequenceFlow();
    //		sequenceFlow.setId(EcoreUtil.generateUUID());
    ModelUtil.setID(sequenceFlow, resource);

    addFlowElement(source, sequenceFlow);
    sequenceFlow.setSourceRef(source);
    sequenceFlow.setTargetRef(target);
    return sequenceFlow;
  }
 private InputOutputSpecification getOrCreateIOSpecification(Object target) {
   Process process = getOrCreateProcess(getParticipant(target));
   if (process.getIoSpecification() == null) {
     InputOutputSpecification ioSpec = FACTORY.createInputOutputSpecification();
     //			ioSpec.setId(EcoreUtil.generateUUID());
     ModelUtil.setID(ioSpec, resource);
     process.setIoSpecification(ioSpec);
   }
   return process.getIoSpecification();
 }
 public Process getOrCreateProcess(Participant participant) {
   if (participant.getProcessRef() == null) {
     Process process = FACTORY.createProcess();
     //			process.setId(EcoreUtil.generateUUID());
     ModelUtil.setID(process, resource);
     process.setName("Process for " + participant.getName());
     getDefinitions().getRootElements().add(process);
     participant.setProcessRef(process);
   }
   return participant.getProcessRef();
 }
 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);
 }
 public Association createAssociation(BaseElement source, BaseElement target) {
   BaseElement e = null;
   if (getParticipant(source) != null) {
     e = source;
   } else if (getParticipant(target) != null) {
     e = target;
   } else {
     e = getInternalParticipant();
   }
   Association association = FACTORY.createAssociation();
   addArtifact(e, association);
   //		association.setId(EcoreUtil.generateUUID());
   ModelUtil.setID(association, resource);
   association.setSourceRef(source);
   association.setTargetRef(target);
   return association;
 }
  public Lane createLane(Lane targetLane) {
    Lane lane = FACTORY.createLane();
    //		lane.setId(EcoreUtil.generateUUID());
    ModelUtil.setID(lane, resource);

    if (targetLane.getChildLaneSet() == null) {
      targetLane.setChildLaneSet(ModelHandler.FACTORY.createLaneSet());
    }

    LaneSet targetLaneSet = targetLane.getChildLaneSet();
    targetLaneSet.getLanes().add(lane);

    lane.getFlowNodeRefs().addAll(targetLane.getFlowNodeRefs());
    targetLane.getFlowNodeRefs().clear();

    return lane;
  }
Exemplo n.º 16
0
  @Test
  @DiagramResource("org/camunda/bpm/modeler/test/ui/change/ChangeSupportTest.testBase.bpmn")
  public void testListElementAdd() {
    final Process process1 = findBusinessObjectById(diagram, "Process_1", Process.class);

    final Task task2 = bpmn2factory.createTask();

    FeatureChangeFilter filter = new FeatureChangeFilter(process1, FLOW_ELEMENTS_FEATURE);
    CustomResourceSetListener listener = new CustomResourceSetListener(process1, filter);
    listener.register();

    transactionalExecute(
        new RecordingCommand(editingDomain) {

          @Override
          protected void doExecute() {
            process1.getFlowElements().add(task2);
          }
        });

    assertThat(listener.getCapturedEvents()).hasSize(1);
  }