Search in sources :

Example 1 with BpmnDiFactory

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

the class Bpmn2JsonUnmarshaller method createSubProcessDiagram.

private void createSubProcessDiagram(BPMNPlane plane, FlowElement flowElement, BpmnDiFactory factory) {
    SubProcess sp = (SubProcess) flowElement;
    for (FlowElement subProcessFlowElement : sp.getFlowElements()) {
        if (subProcessFlowElement instanceof SubProcess) {
            createBpmnShapeForElement(factory, plane, subProcessFlowElement);
            createSubProcessDiagram(plane, subProcessFlowElement, factory);
        } else if (subProcessFlowElement instanceof FlowNode) {
            createBpmnShapeForElement(factory, plane, subProcessFlowElement);
            if (subProcessFlowElement instanceof BoundaryEvent) {
                createDockersForBoundaryEvent((BoundaryEvent) subProcessFlowElement);
            }
        } else if (subProcessFlowElement instanceof SequenceFlow) {
            createBpmnEdgeForSequenceFlow(factory, plane, (SequenceFlow) subProcessFlowElement);
        }
    }
    if (sp.getArtifacts() != null) {
        List<Association> incompleteAssociations = new ArrayList<Association>();
        for (Artifact artifact : sp.getArtifacts()) {
            // if (artifact instanceof TextAnnotation || artifact instanceof Group) {
            if (artifact instanceof Group) {
                createBpmnShapeForElement(factory, plane, artifact);
            }
            if (artifact instanceof Association) {
                Association association = (Association) artifact;
                if (association.getSourceRef() != null && association.getTargetRef() != null) {
                    createBpmnEdgeForAssociation(factory, plane, association);
                } else {
                    incompleteAssociations.add(association);
                }
            }
        }
        if (!incompleteAssociations.isEmpty()) {
            for (Association incompleteAssociation : incompleteAssociations) {
                sp.getArtifacts().remove(incompleteAssociation);
            }
        }
    }
}
Also used : AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Group(org.eclipse.bpmn2.Group) Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) FlowElement(org.eclipse.bpmn2.FlowElement) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList) Artifact(org.eclipse.bpmn2.Artifact) FlowNode(org.eclipse.bpmn2.FlowNode)

Example 2 with BpmnDiFactory

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

the class Bpmn2JsonUnmarshaller method createBpmnShapeForElement.

private void createBpmnShapeForElement(BpmnDiFactory factory, BPMNPlane plane, BaseElement element) {
    Bounds bounds = _bounds.get(element.getId());
    if (bounds != null) {
        BPMNShape shape = factory.createBPMNShape();
        shape.setBpmnElement(element);
        shape.setBounds(bounds);
        plane.getPlaneElement().add(shape);
    }
}
Also used : Bounds(org.eclipse.dd.dc.Bounds) BPMNShape(org.eclipse.bpmn2.di.BPMNShape)

Example 3 with BpmnDiFactory

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

the class Bpmn2JsonUnmarshaller method createBpmnEdgeForSequenceFlow.

private void createBpmnEdgeForSequenceFlow(BpmnDiFactory factory, BPMNPlane plane, SequenceFlow sequenceFlow) {
    BPMNEdge edge = factory.createBPMNEdge();
    edge.setBpmnElement(sequenceFlow);
    DcFactory dcFactory = DcFactory.eINSTANCE;
    Point point = dcFactory.createPoint();
    List<Point> dockers = _dockers.get(sequenceFlow.getId());
    if (sequenceFlow.getSourceRef() != null) {
        Bounds sourceBounds = _bounds.get(sequenceFlow.getSourceRef().getId());
        // Test for valid docker with X and Y  > -1, created by EdgeParser
        if (dockers != null && dockers.size() > 0 && dockers.get(0).getX() > -1 && dockers.get(0).getY() > -1) {
            // First docker is connection to Source
            point.setX(sourceBounds.getX() + dockers.get(0).getX());
            point.setY(sourceBounds.getY() + dockers.get(0).getY());
        } else {
            // Default is right middle of Source
            point.setX(sourceBounds.getX() + sourceBounds.getWidth());
            point.setY(sourceBounds.getY() + (sourceBounds.getHeight() / 2));
        }
    }
    edge.getWaypoint().add(point);
    for (int i = 1; i < dockers.size() - 1; i++) {
        edge.getWaypoint().add(dockers.get(i));
    }
    point = dcFactory.createPoint();
    if (sequenceFlow.getTargetRef() != null) {
        Bounds targetBounds = _bounds.get(sequenceFlow.getTargetRef().getId());
        // Test for valid docker with X and Y  > -1, created by EdgeParser
        if (dockers != null && dockers.size() > 1 && dockers.get(dockers.size() - 1).getX() > -1 && dockers.get(dockers.size() - 1).getY() > -1) {
            // Last docker is connection to Target
            point.setX(targetBounds.getX() + dockers.get(dockers.size() - 1).getX());
            point.setY(targetBounds.getY() + dockers.get(dockers.size() - 1).getY());
        } else {
            // Default is left middle of Target
            point.setX(targetBounds.getX());
            point.setY(targetBounds.getY() + (targetBounds.getHeight() / 2));
        }
    }
    edge.getWaypoint().add(point);
    plane.getPlaneElement().add(edge);
}
Also used : Bounds(org.eclipse.dd.dc.Bounds) Point(org.eclipse.dd.dc.Point) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge) DcFactory(org.eclipse.dd.dc.DcFactory) Point(org.eclipse.dd.dc.Point)

Example 4 with BpmnDiFactory

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

the class Bpmn2JsonUnmarshaller method createBpmnEdgeForAssociation.

private void createBpmnEdgeForAssociation(BpmnDiFactory factory, BPMNPlane plane, Association association) {
    BPMNEdge edge = factory.createBPMNEdge();
    edge.setBpmnElement(association);
    DcFactory dcFactory = DcFactory.eINSTANCE;
    Point point = dcFactory.createPoint();
    Bounds sourceBounds = _bounds.get(association.getSourceRef().getId());
    point.setX(sourceBounds.getX() + (sourceBounds.getWidth() / 2));
    point.setY(sourceBounds.getY() + (sourceBounds.getHeight() / 2));
    edge.getWaypoint().add(point);
    List<Point> dockers = _dockers.get(association.getId());
    for (int i = 1; i < dockers.size() - 1; i++) {
        edge.getWaypoint().add(dockers.get(i));
    }
    point = dcFactory.createPoint();
    Bounds targetBounds = _bounds.get(association.getTargetRef().getId());
    point.setX(targetBounds.getX() + (targetBounds.getWidth() / 2));
    point.setY(targetBounds.getY() + (targetBounds.getHeight() / 2));
    edge.getWaypoint().add(point);
    plane.getPlaneElement().add(edge);
}
Also used : Bounds(org.eclipse.dd.dc.Bounds) Point(org.eclipse.dd.dc.Point) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge) DcFactory(org.eclipse.dd.dc.DcFactory) Point(org.eclipse.dd.dc.Point)

Example 5 with BpmnDiFactory

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

the class Bpmn2JsonUnmarshaller method createDiagram.

private void createDiagram(Definitions def) {
    for (RootElement rootElement : def.getRootElements()) {
        if (rootElement instanceof Process) {
            Process process = (Process) rootElement;
            BpmnDiFactory factory = BpmnDiFactory.eINSTANCE;
            BPMNDiagram diagram = factory.createBPMNDiagram();
            BPMNPlane plane = factory.createBPMNPlane();
            plane.setBpmnElement(process);
            diagram.setPlane(plane);
            // first process flowNodes
            for (FlowElement flowElement : process.getFlowElements()) {
                if (flowElement instanceof FlowNode) {
                    createBpmnShapeForElement(factory, plane, flowElement);
                    if (flowElement instanceof BoundaryEvent) {
                        createDockersForBoundaryEvent((BoundaryEvent) flowElement);
                    }
                    // check if its a subprocess
                    if (flowElement instanceof SubProcess) {
                        createSubProcessDiagram(plane, flowElement, factory);
                    }
                } else if (flowElement instanceof DataObject) {
                    createBpmnShapeForElement(factory, plane, flowElement);
                } else if (flowElement instanceof SequenceFlow) {
                    createBpmnEdgeForSequenceFlow(factory, plane, (SequenceFlow) flowElement);
                }
            }
            // then process artifacts
            if (process.getArtifacts() != null) {
                List<Association> incompleteAssociations = new ArrayList<Association>();
                for (Artifact artifact : process.getArtifacts()) {
                    // if (artifact instanceof TextAnnotation || artifact instanceof Group) {
                    if (artifact instanceof Group) {
                        createBpmnShapeForElement(factory, plane, artifact);
                    }
                    if (artifact instanceof Association) {
                        Association association = (Association) artifact;
                        if (association.getSourceRef() != null && association.getTargetRef() != null) {
                            createBpmnEdgeForAssociation(factory, plane, association);
                        } else {
                            incompleteAssociations.add(association);
                        }
                    }
                }
                if (!incompleteAssociations.isEmpty()) {
                    for (Association incompleteAssociation : incompleteAssociations) {
                        process.getArtifacts().remove(incompleteAssociation);
                    }
                }
            }
            // finally process lanes
            if (process.getLaneSets() != null && process.getLaneSets().size() > 0) {
                for (LaneSet ls : process.getLaneSets()) {
                    for (Lane lane : ls.getLanes()) {
                        createBpmnShapeForElement(factory, plane, lane);
                    }
                }
            }
            def.getDiagrams().add(diagram);
        }
    }
}
Also used : AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Group(org.eclipse.bpmn2.Group) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList) 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) BpmnDiFactory(org.eclipse.bpmn2.di.BpmnDiFactory) Artifact(org.eclipse.bpmn2.Artifact) BPMNDiagram(org.eclipse.bpmn2.di.BPMNDiagram) RootElement(org.eclipse.bpmn2.RootElement) DataObject(org.eclipse.bpmn2.DataObject) Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) FlowElement(org.eclipse.bpmn2.FlowElement) BPMNPlane(org.eclipse.bpmn2.di.BPMNPlane) FlowNode(org.eclipse.bpmn2.FlowNode)

Aggregations

Bounds (org.eclipse.dd.dc.Bounds)3 ArrayList (java.util.ArrayList)2 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)2 Artifact (org.eclipse.bpmn2.Artifact)2 Association (org.eclipse.bpmn2.Association)2 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)2 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)2 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)2 FlowElement (org.eclipse.bpmn2.FlowElement)2 FlowNode (org.eclipse.bpmn2.FlowNode)2 Group (org.eclipse.bpmn2.Group)2 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)2 SubProcess (org.eclipse.bpmn2.SubProcess)2 BPMNEdge (org.eclipse.bpmn2.di.BPMNEdge)2 DcFactory (org.eclipse.dd.dc.DcFactory)2 Point (org.eclipse.dd.dc.Point)2 DataObject (org.eclipse.bpmn2.DataObject)1 Lane (org.eclipse.bpmn2.Lane)1 LaneSet (org.eclipse.bpmn2.LaneSet)1 Process (org.eclipse.bpmn2.Process)1