예제 #1
0
  public static void updateCategoryValues(IFeatureProvider fp, PictogramElement pe) {

    Resource resource = ObjectPropertyProvider.getResource(pe);
    if (Bpmn2Preferences.getInstance(resource).getPropagateGroupCategories()) {
      // only do this if User Preference is enabled: assign the Group's CategoryValue
      // to the FlowElement represented by the given PictogramElement
      Diagram diagram = fp.getDiagramTypeProvider().getDiagram();
      FlowElement flowElement = BusinessObjectUtil.getFirstElementOfType(pe, FlowElement.class);
      if (flowElement == null) return;
      // remove any previous Category Values from this FlowElement
      flowElement.getCategoryValueRef().clear();

      // find all Groups in this Resource and check if it contains the given FlowElement
      if (pe instanceof ContainerShape) {
        for (Group group : ModelUtil.getAllObjectsOfType(resource, Group.class)) {
          CategoryValue cv = group.getCategoryValueRef();
          if (cv == null) continue;

          for (PictogramElement groupShape :
              Graphiti.getLinkService().getPictogramElements(diagram, group)) {
            if (groupShape instanceof ContainerShape) {
              for (ContainerShape flowElementShape :
                  FeatureSupport.findGroupedShapes((ContainerShape) groupShape)) {
                FlowElement fe =
                    BusinessObjectUtil.getFirstElementOfType(flowElementShape, FlowElement.class);
                if (fe == flowElement) {
                  fe.getCategoryValueRef().add(cv);
                  break;
                }
              }
            }
          }
        }
      } else if (pe instanceof Connection && flowElement instanceof SequenceFlow) {
        SequenceFlow sf = (SequenceFlow) flowElement;
        FlowNode source = sf.getSourceRef();
        FlowNode target = sf.getTargetRef();

        sf.getCategoryValueRef().clear();
        sf.getCategoryValueRef().addAll(source.getCategoryValueRef());
        sf.getCategoryValueRef().addAll(target.getCategoryValueRef());
      }
    }
  }
 @Test
 public void testSequenceFlowUnmarshalling() throws Exception {
   Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
   Definitions definitions =
       ((Definitions)
           unmarshaller.unmarshall(getTestJsonFile("sequenceFlow.json"), "").getContents().get(0));
   assertTrue(definitions.getRootElements().size() == 1);
   Process process = getRootProcess(definitions);
   assertTrue(process.getFlowElements().get(0) instanceof Task);
   Task task = (Task) process.getFlowElements().get(0);
   assertEquals("task1", task.getName());
   Task task2 = (Task) process.getFlowElements().get(1);
   assertEquals("task2", task2.getName());
   SequenceFlow flow = (SequenceFlow) process.getFlowElements().get(2);
   assertEquals("seqFlow", flow.getName());
   assertEquals(task, flow.getSourceRef());
   assertEquals(task2, flow.getTargetRef());
   definitions.eResource().save(System.out, Collections.emptyMap());
 }
  public static List<Object> getFlowElementsContainerChildren(FlowElementsContainer container) {
    List<Object> retList = new ArrayList<Object>();
    List<FlowElement> flowElements = new ArrayList<FlowElement>();
    for (FlowElement fe : container.getFlowElements()) {
      if (!(fe instanceof BoundaryEvent)) flowElements.add(fe);
    }

    if (container.getLaneSets().size() == 0) retList.addAll(flowElements);
    else {
      for (LaneSet ls : container.getLaneSets()) {
        retList.addAll(ls.getLanes());
      }
      // only add the flow element if it's not contained in a Lane
      List<Object> laneElements = new ArrayList<Object>();
      for (FlowElement fe : flowElements) {
        boolean inLane = false;
        for (LaneSet ls : container.getLaneSets()) {
          if (isInLane(fe, ls)) {
            inLane = true;
            break;
          }
        }
        if (inLane) laneElements.add(fe);
        else retList.add(fe);
      }

      // don't include any sequence flows that connect flow
      // nodes that are contained in Lanes
      List<SequenceFlow> flows = new ArrayList<SequenceFlow>();
      for (Object fn : laneElements) {
        if (fn instanceof FlowNode) {
          for (SequenceFlow sf : ((FlowNode) fn).getIncoming()) {
            if (laneElements.contains(sf.getSourceRef())
                && laneElements.contains(sf.getTargetRef())
                && !flows.contains(sf)) {
              flows.add(sf);
            }
          }
          for (SequenceFlow sf : ((FlowNode) fn).getOutgoing()) {
            if (laneElements.contains(sf.getSourceRef())
                && laneElements.contains(sf.getTargetRef())
                && !flows.contains(sf)) {
              flows.add(sf);
            }
          }
        }
      }
      retList.removeAll(flows);
    }

    // add the list of Artifacts
    if (container instanceof Process) {
      retList.addAll(((Process) container).getArtifacts());
    } else if (container instanceof SubProcess) {
      retList.addAll(((SubProcess) container).getArtifacts());
    }
    if (container instanceof SubChoreography) {
      retList.addAll(((SubChoreography) container).getArtifacts());
    }
    if (container instanceof Choreography) {
      // Add Pools as children if the Pool has a Process associated with it,
      // or if the Participant is NOT referenced by a Choreography Activity.
      for (Participant p : ((Choreography) container).getParticipants()) {
        if (p.getProcessRef() != null) retList.add(p);
        else {
          for (FlowElement fe : flowElements) {
            if (fe instanceof ChoreographyActivity) {
              if (!((ChoreographyActivity) fe).getParticipantRefs().contains(p)) {
                retList.add(p);
              }
            }
          }
        }
      }
    }
    return retList;
  }
예제 #4
0
 /* (non-Javadoc)
  * @see org.eclipse.gef.editparts.AbstractConnectionEditPart#getTarget()
  */
 @Override
 public EditPart getTarget() {
   FlowNode targetNode = fUnderlyingSequenceFlow.getTargetRef();
   ShapeEditPartAdapter shapeEditPart = AdapterFactory.getShapeEditPartAdapter(targetNode);
   return shapeEditPart;
 }