Search in sources :

Example 6 with BPMNPlane

use of org.eclipse.bpmn2.di.BPMNPlane in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method marshallBoundaryEvent.

protected void marshallBoundaryEvent(BoundaryEvent boundaryEvent, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, Map<String, Object> catchEventProperties) throws JsonGenerationException, IOException {
    List<EventDefinition> eventDefinitions = boundaryEvent.getEventDefinitions();
    if (boundaryEvent.isCancelActivity()) {
        catchEventProperties.put(BOUNDARYCANCELACTIVITY, "true");
    } else {
        catchEventProperties.put(BOUNDARYCANCELACTIVITY, "false");
    }
    // simulation properties
    setSimulationProperties(boundaryEvent.getId(), catchEventProperties);
    if (eventDefinitions.size() == 1) {
        EventDefinition eventDefinition = eventDefinitions.get(0);
        if (eventDefinition instanceof SignalEventDefinition) {
            marshallNode(boundaryEvent, catchEventProperties, "IntermediateSignalEventCatching", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof EscalationEventDefinition) {
            marshallNode(boundaryEvent, catchEventProperties, "IntermediateEscalationEvent", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof ErrorEventDefinition) {
            marshallNode(boundaryEvent, catchEventProperties, "IntermediateErrorEvent", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof TimerEventDefinition) {
            marshallNode(boundaryEvent, catchEventProperties, "IntermediateTimerEvent", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof CompensateEventDefinition) {
            marshallNode(boundaryEvent, catchEventProperties, "IntermediateCompensationEventCatching", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof ConditionalEventDefinition) {
            marshallNode(boundaryEvent, catchEventProperties, "IntermediateConditionalEvent", plane, generator, xOffset, yOffset);
        } else if (eventDefinition instanceof MessageEventDefinition) {
            marshallNode(boundaryEvent, catchEventProperties, "IntermediateMessageEventCatching", plane, generator, xOffset, yOffset);
        } else {
            throw new UnsupportedOperationException("Event definition not supported: " + eventDefinition);
        }
    } else {
        throw new UnsupportedOperationException("None or multiple event definitions not supported for boundary event");
    }
}
Also used : EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) ConditionalEventDefinition(org.eclipse.bpmn2.ConditionalEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) EventDefinition(org.eclipse.bpmn2.EventDefinition) ConditionalEventDefinition(org.eclipse.bpmn2.ConditionalEventDefinition) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) TerminateEventDefinition(org.eclipse.bpmn2.TerminateEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) CancelEventDefinition(org.eclipse.bpmn2.CancelEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition) TimerEventDefinition(org.eclipse.bpmn2.TimerEventDefinition) TimerEventDefinition(org.eclipse.bpmn2.TimerEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition)

Example 7 with BPMNPlane

use of org.eclipse.bpmn2.di.BPMNPlane in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method findOutgoingAssociations.

protected List<Association> findOutgoingAssociations(BPMNPlane plane, BaseElement baseElement) {
    List<Association> retList = new ArrayList<Association>();
    if (!(plane.getBpmnElement() instanceof Process)) {
        throw new IllegalArgumentException("Don't know how to get associations from a non-Process Diagram");
    }
    Process process = (Process) plane.getBpmnElement();
    for (Artifact artifact : process.getArtifacts()) {
        if (artifact instanceof Association) {
            Association association = (Association) artifact;
            if (association.getSourceRef() == baseElement) {
                retList.add(association);
            }
        }
    }
    return retList;
}
Also used : Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) ArrayList(java.util.ArrayList) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) Artifact(org.eclipse.bpmn2.Artifact)

Example 8 with BPMNPlane

use of org.eclipse.bpmn2.di.BPMNPlane in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method marshallAssociation.

protected void marshallAssociation(Association association, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def) throws JsonGenerationException, IOException {
    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    Iterator<FeatureMap.Entry> iter = association.getAnyAttribute().iterator();
    boolean foundBrColor = false;
    while (iter.hasNext()) {
        FeatureMap.Entry entry = iter.next();
        if (entry.getEStructuralFeature().getName().equals("type")) {
            properties.put(TYPE, entry.getValue());
        }
        if (entry.getEStructuralFeature().getName().equals("bordercolor")) {
            properties.put(BORDERCOLOR, entry.getValue());
            foundBrColor = true;
        }
    }
    if (!foundBrColor) {
        properties.put("bordercolor", defaultSequenceflowColor);
    }
    putDocumentationProperty(association, properties);
    marshallProperties(properties, generator);
    generator.writeObjectFieldStart("stencil");
    if (association.getAssociationDirection().equals(AssociationDirection.ONE)) {
        generator.writeObjectField("id", "Association_Unidirectional");
    } else if (association.getAssociationDirection().equals(AssociationDirection.BOTH)) {
        generator.writeObjectField("id", "Association_Bidirectional");
    } else {
        generator.writeObjectField("id", "Association_Undirected");
    }
    generator.writeEndObject();
    generator.writeArrayFieldStart("childShapes");
    generator.writeEndArray();
    generator.writeArrayFieldStart("outgoing");
    generator.writeStartObject();
    generator.writeObjectField("resourceId", association.getTargetRef().getId());
    generator.writeEndObject();
    generator.writeEndArray();
    Bounds sourceBounds = ((BPMNShape) findDiagramElement(plane, association.getSourceRef())).getBounds();
    Bounds targetBounds = null;
    float tbx = 0;
    float tby = 0;
    if (findDiagramElement(plane, association.getTargetRef()) instanceof BPMNShape) {
        targetBounds = ((BPMNShape) findDiagramElement(plane, association.getTargetRef())).getBounds();
    } else if (findDiagramElement(plane, association.getTargetRef()) instanceof BPMNEdge) {
        // connect it to first waypoint on edge
        List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, association.getTargetRef())).getWaypoint();
        if (waypoints != null && waypoints.size() > 0) {
            tbx = waypoints.get(0).getX();
            tby = waypoints.get(0).getY();
        }
    }
    generator.writeArrayFieldStart("dockers");
    generator.writeStartObject();
    generator.writeObjectField("x", sourceBounds.getWidth() / 2);
    generator.writeObjectField("y", sourceBounds.getHeight() / 2);
    generator.writeEndObject();
    List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, association)).getWaypoint();
    for (int i = 1; i < waypoints.size() - 1; i++) {
        Point waypoint = waypoints.get(i);
        generator.writeStartObject();
        generator.writeObjectField("x", waypoint.getX());
        generator.writeObjectField("y", waypoint.getY());
        generator.writeEndObject();
    }
    if (targetBounds != null) {
        generator.writeStartObject();
        // text annotations have to be treated specia
        if (association.getTargetRef() instanceof TextAnnotation) {
            generator.writeObjectField("x", 1);
            generator.writeObjectField("y", targetBounds.getHeight() / 2);
        } else {
            generator.writeObjectField("x", targetBounds.getWidth() / 2);
            generator.writeObjectField("y", targetBounds.getHeight() / 2);
        }
        generator.writeEndObject();
        generator.writeEndArray();
    } else {
        generator.writeStartObject();
        generator.writeObjectField("x", tbx);
        generator.writeObjectField("y", tby);
        generator.writeEndObject();
        generator.writeEndArray();
    }
}
Also used : Bounds(org.eclipse.dd.dc.Bounds) Point(org.eclipse.dd.dc.Point) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) Point(org.eclipse.dd.dc.Point) LinkedHashMap(java.util.LinkedHashMap) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) Entry(java.util.Map.Entry) DataObject(org.eclipse.bpmn2.DataObject) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) TextAnnotation(org.eclipse.bpmn2.TextAnnotation) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Example 9 with BPMNPlane

use of org.eclipse.bpmn2.di.BPMNPlane in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method updateEdgeBoundsInLanes.

public void updateEdgeBoundsInLanes(Definitions def, BPMNPlane plane, BPMNEdge edge, BaseElement ele) {
    if (ele instanceof SequenceFlow) {
        SequenceFlow sq = (SequenceFlow) ele;
        // update the source and target on BPMNEdge
        if (sq.getSourceRef() != null) {
            edge.setSourceElement(getBPMNShapeForElement(sq.getSourceRef(), plane));
        }
        if (sq.getTargetRef() != null) {
            edge.setTargetElement(getBPMNShapeForElement(sq.getTargetRef(), plane));
        }
        List<RootElement> rootElements = def.getRootElements();
        for (RootElement root : rootElements) {
            if (root instanceof Process) {
                Process process = (Process) root;
                if (sq.getSourceRef() != null && sq.getTargetRef() != null) {
                    if (process.getLaneSets() != null && process.getLaneSets().size() > 0) {
                        for (LaneSet ls : process.getLaneSets()) {
                            for (Lane newLane : ls.getLanes()) {
                                List<FlowNode> laneFlowNodes = newLane.getFlowNodeRefs();
                                Bounds laneBounds = getBoundsForElement(newLane, plane);
                                for (FlowNode newFlowNode : laneFlowNodes) {
                                    if (newFlowNode.getId().equals(sq.getSourceRef().getId())) {
                                        List<DiagramElement> diagramElements = plane.getPlaneElement();
                                        for (DiagramElement dia : diagramElements) {
                                            if (dia instanceof BPMNShape) {
                                                BPMNShape shape = (BPMNShape) dia;
                                                if (shape.getBpmnElement().getId().equals(sq.getSourceRef().getId())) {
                                                    Bounds eleBounds = shape.getBounds();
                                                    List<Point> edgePoints = edge.getWaypoint();
                                                    if (edgePoints != null && edgePoints.size() > 1) {
                                                        if (eleBounds != null) {
                                                            Point first = edgePoints.get(0);
                                                            first.setX(first.getX() + laneBounds.getX());
                                                            first.setY(first.getY() + laneBounds.getY());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    } else if (newFlowNode.getId().equals(sq.getTargetRef().getId())) {
                                        List<DiagramElement> diagramElements = plane.getPlaneElement();
                                        for (DiagramElement dia : diagramElements) {
                                            if (dia instanceof BPMNShape) {
                                                BPMNShape shape = (BPMNShape) dia;
                                                if (shape.getBpmnElement().getId().equals(sq.getTargetRef().getId())) {
                                                    Bounds eleBounds = shape.getBounds();
                                                    List<Point> edgePoints = edge.getWaypoint();
                                                    if (edgePoints != null && edgePoints.size() > 1) {
                                                        if (eleBounds != null) {
                                                            Point last = edgePoints.get(edgePoints.size() - 1);
                                                            last.setX(last.getX() + laneBounds.getX());
                                                            last.setY(last.getY() + laneBounds.getY());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : SequenceFlow(org.eclipse.bpmn2.SequenceFlow) Bounds(org.eclipse.dd.dc.Bounds) Lane(org.eclipse.bpmn2.Lane) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) LaneSet(org.eclipse.bpmn2.LaneSet) Point(org.eclipse.dd.dc.Point) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) DiagramElement(org.eclipse.dd.di.DiagramElement) RootElement(org.eclipse.bpmn2.RootElement) ArrayList(java.util.ArrayList) List(java.util.List) FlowNode(org.eclipse.bpmn2.FlowNode)

Example 10 with BPMNPlane

use of org.eclipse.bpmn2.di.BPMNPlane in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method revisitDIColors.

public void revisitDIColors(Definitions def) {
    BPMNPlane plane = def.getDiagrams().get(0).getPlane();
    List<DiagramElement> diagramElements = plane.getPlaneElement();
    for (DiagramElement dia : diagramElements) {
        if (dia instanceof BPMNShape) {
            BPMNShape shape = (BPMNShape) dia;
            updateShapeColors(shape);
        }
        if (dia instanceof BPMNEdge) {
            BPMNEdge edge = (BPMNEdge) dia;
            updateEdgeColors(edge);
        }
    }
}
Also used : DiagramElement(org.eclipse.dd.di.DiagramElement) BPMNPlane(org.eclipse.bpmn2.di.BPMNPlane) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Aggregations

Bounds (org.eclipse.dd.dc.Bounds)16 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)15 SubProcess (org.eclipse.bpmn2.SubProcess)15 ArrayList (java.util.ArrayList)12 BPMNShape (org.eclipse.bpmn2.di.BPMNShape)12 Process (org.eclipse.bpmn2.Process)11 DataObject (org.eclipse.bpmn2.DataObject)10 FlowElement (org.eclipse.bpmn2.FlowElement)9 BPMNEdge (org.eclipse.bpmn2.di.BPMNEdge)9 LinkedHashMap (java.util.LinkedHashMap)8 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)8 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)8 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)8 Point (org.eclipse.dd.dc.Point)8 DiagramElement (org.eclipse.dd.di.DiagramElement)8 Artifact (org.eclipse.bpmn2.Artifact)7 BPMNPlane (org.eclipse.bpmn2.di.BPMNPlane)7 Entry (java.util.Map.Entry)6 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)6 Association (org.eclipse.bpmn2.Association)5