Search in sources :

Example 1 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class BpmnAutoLayout method generateSequenceFlowDiagramInterchangeElements.

protected void generateSequenceFlowDiagramInterchangeElements() {
    for (String sequenceFlowId : generatedSequenceFlowEdges.keySet()) {
        Object edge = generatedSequenceFlowEdges.get(sequenceFlowId);
        List<mxPoint> points = graph.getView().getState(edge).getAbsolutePoints();
        // JGraphX has this funny way of generating the outgoing sequence flow of a gateway
        // Visually, we'd like them to originate from one of the corners of the rhombus,
        // hence we force the starting point of the sequence flow to the closest rhombus corner point.
        FlowElement sourceElement = handledFlowElements.get(sequenceFlows.get(sequenceFlowId).getSourceRef());
        if (sourceElement instanceof Gateway && ((Gateway) sourceElement).getOutgoingFlows().size() > 1) {
            mxPoint startPoint = points.get(0);
            Object gatewayVertex = generatedVertices.get(sourceElement.getId());
            mxCellState gatewayState = graph.getView().getState(gatewayVertex);
            mxPoint northPoint = new mxPoint(gatewayState.getX() + (gatewayState.getWidth()) / 2, gatewayState.getY());
            mxPoint southPoint = new mxPoint(gatewayState.getX() + (gatewayState.getWidth()) / 2, gatewayState.getY() + gatewayState.getHeight());
            mxPoint eastPoint = new mxPoint(gatewayState.getX() + gatewayState.getWidth(), gatewayState.getY() + (gatewayState.getHeight()) / 2);
            mxPoint westPoint = new mxPoint(gatewayState.getX(), gatewayState.getY() + (gatewayState.getHeight()) / 2);
            double closestDistance = Double.MAX_VALUE;
            mxPoint closestPoint = null;
            for (mxPoint rhombusPoint : Arrays.asList(northPoint, southPoint, eastPoint, westPoint)) {
                double distance = euclidianDistance(startPoint, rhombusPoint);
                if (distance < closestDistance) {
                    closestDistance = distance;
                    closestPoint = rhombusPoint;
                }
            }
            startPoint.setX(closestPoint.getX());
            startPoint.setY(closestPoint.getY());
            // Since we know the layout is from left to right, this is not a problem
            if (points.size() > 1) {
                mxPoint nextPoint = points.get(1);
                nextPoint.setY(closestPoint.getY());
            }
        }
        createDiagramInterchangeInformation(handledFlowElements.get(sequenceFlowId), optimizeEdgePoints(points));
    }
}
Also used : com.mxgraph.view.mxCellState(com.mxgraph.view.mxCellState) FlowElement(org.activiti.bpmn.model.FlowElement) Gateway(org.activiti.bpmn.model.Gateway) DataObject(org.activiti.bpmn.model.DataObject) com.mxgraph.util.mxPoint(com.mxgraph.util.mxPoint)

Example 2 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class BpmnAutoLayout method layout.

protected void layout(FlowElementsContainer flowElementsContainer) {
    graph = new mxGraph();
    cellParent = graph.getDefaultParent();
    graph.getModel().beginUpdate();
    // Subprocesses are handled in a new instance of BpmnAutoLayout, hence they instantiations of new maps here.
    handledFlowElements = new HashMap<String, FlowElement>();
    handledArtifacts = new HashMap<String, Artifact>();
    generatedVertices = new HashMap<String, Object>();
    generatedSequenceFlowEdges = new HashMap<String, Object>();
    generatedAssociationEdges = new HashMap<String, Object>();
    //Associations are gathered and processed afterwards, because we must be sure we alreadydiv found source and target
    associations = new HashMap<String, Association>();
    // Text Annotations are gathered and processed afterwards, because we must be sure we already found the parent.
    textAnnotations = new HashMap<String, TextAnnotation>();
    // Sequence flow are gathered and processed afterwards, because we must be sure we alreadt found source and target
    sequenceFlows = new HashMap<String, SequenceFlow>();
    // Boundary events are gathered and processed afterwards, because we must be sure we have its parent
    boundaryEvents = new ArrayList<BoundaryEvent>();
    // Process all elements
    for (FlowElement flowElement : flowElementsContainer.getFlowElements()) {
        if (flowElement instanceof SequenceFlow) {
            handleSequenceFlow((SequenceFlow) flowElement);
        } else if (flowElement instanceof Event) {
            handleEvent(flowElement);
        } else if (flowElement instanceof Gateway) {
            createGatewayVertex(flowElement);
        } else if (flowElement instanceof Task || flowElement instanceof CallActivity) {
            handleActivity(flowElement);
        } else if (flowElement instanceof SubProcess) {
            handleSubProcess(flowElement);
        }
        handledFlowElements.put(flowElement.getId(), flowElement);
    }
    // process artifacts
    for (Artifact artifact : flowElementsContainer.getArtifacts()) {
        if (artifact instanceof Association) {
            handleAssociation((Association) artifact);
        } else if (artifact instanceof TextAnnotation) {
            handleTextAnnotation((TextAnnotation) artifact);
        }
        handledArtifacts.put(artifact.getId(), artifact);
    }
    // Process gathered elements
    handleBoundaryEvents();
    handleSequenceFlow();
    handleAssociations();
    // All elements are now put in the graph. Let's layout them!
    CustomLayout layout = new CustomLayout(graph, SwingConstants.WEST);
    layout.setIntraCellSpacing(100.0);
    layout.setResizeParent(true);
    layout.setFineTuning(true);
    layout.setParentBorder(20);
    layout.setMoveParent(true);
    layout.setDisableEdgeStyle(false);
    layout.setUseBoundingBox(true);
    layout.execute(graph.getDefaultParent());
    graph.getModel().endUpdate();
    generateDiagramInterchangeElements();
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) Task(org.activiti.bpmn.model.Task) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) com.mxgraph.view.mxGraph(com.mxgraph.view.mxGraph) CallActivity(org.activiti.bpmn.model.CallActivity) Artifact(org.activiti.bpmn.model.Artifact) Association(org.activiti.bpmn.model.Association) FlowElement(org.activiti.bpmn.model.FlowElement) Gateway(org.activiti.bpmn.model.Gateway) Event(org.activiti.bpmn.model.Event) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) DataObject(org.activiti.bpmn.model.DataObject) TextAnnotation(org.activiti.bpmn.model.TextAnnotation)

Example 3 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class BpmnAutoLayout method translateNestedSubprocessElements.

protected void translateNestedSubprocessElements(SubProcess subProcess) {
    GraphicInfo subProcessGraphicInfo = bpmnModel.getLocationMap().get(subProcess.getId());
    double subProcessX = subProcessGraphicInfo.getX();
    double subProcessY = subProcessGraphicInfo.getY();
    List<SubProcess> nestedSubProcesses = new ArrayList<SubProcess>();
    for (FlowElement flowElement : subProcess.getFlowElements()) {
        if (flowElement instanceof SequenceFlow) {
            List<GraphicInfo> graphicInfos = bpmnModel.getFlowLocationMap().get(flowElement.getId());
            for (GraphicInfo graphicInfo : graphicInfos) {
                graphicInfo.setX(graphicInfo.getX() + subProcessX + subProcessMargin);
                graphicInfo.setY(graphicInfo.getY() + subProcessY + subProcessMargin);
            }
        } else if (flowElement instanceof DataObject == false) {
            // Regular element
            GraphicInfo graphicInfo = bpmnModel.getLocationMap().get(flowElement.getId());
            graphicInfo.setX(graphicInfo.getX() + subProcessX + subProcessMargin);
            graphicInfo.setY(graphicInfo.getY() + subProcessY + subProcessMargin);
        }
        if (flowElement instanceof SubProcess) {
            nestedSubProcesses.add((SubProcess) flowElement);
        }
    }
    // Continue for next level of nested subprocesses
    for (SubProcess nestedSubProcess : nestedSubProcesses) {
        translateNestedSubprocessElements(nestedSubProcess);
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) DataObject(org.activiti.bpmn.model.DataObject) FlowElement(org.activiti.bpmn.model.FlowElement) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) ArrayList(java.util.ArrayList)

Example 4 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class BpmnParse method createBPMNEdge.

public void createBPMNEdge(String key, List<GraphicInfo> graphicList) {
    FlowElement flowElement = bpmnModel.getFlowElement(key);
    if (flowElement != null && sequenceFlows.containsKey(key)) {
        TransitionImpl sequenceFlow = sequenceFlows.get(key);
        List<Integer> waypoints = new ArrayList<Integer>();
        for (GraphicInfo waypointInfo : graphicList) {
            waypoints.add((int) waypointInfo.getX());
            waypoints.add((int) waypointInfo.getY());
        }
        sequenceFlow.setWaypoints(waypoints);
    } else if (bpmnModel.getArtifact(key) != null) {
    // it's an association, so nothing to do
    } else {
        LOGGER.warn("Invalid reference in 'bpmnElement' attribute, sequenceFlow " + key + " not found");
    }
}
Also used : TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayList(java.util.ArrayList) GraphicInfo(org.activiti.bpmn.model.GraphicInfo)

Example 5 with FlowElement

use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.

the class BpmnParse method processFlowElements.

public void processFlowElements(Collection<FlowElement> flowElements) {
    // Parsing the elements is done in a strict order of types,
    // as otherwise certain information might not be available when parsing a
    // certain type.
    // Using lists as we want to keep the order in which they are defined
    List<SequenceFlow> sequenceFlowToParse = new ArrayList<SequenceFlow>();
    List<BoundaryEvent> boundaryEventsToParse = new ArrayList<BoundaryEvent>();
    // Flow elements that depend on other elements are parse after the first run-through
    List<FlowElement> defferedFlowElementsToParse = new ArrayList<FlowElement>();
    // Activities are parsed first
    for (FlowElement flowElement : flowElements) {
        // Sequence flow are also flow elements, but are only parsed once everyactivity is found
        if (flowElement instanceof SequenceFlow) {
            sequenceFlowToParse.add((SequenceFlow) flowElement);
        } else if (flowElement instanceof BoundaryEvent) {
            boundaryEventsToParse.add((BoundaryEvent) flowElement);
        } else if (flowElement instanceof Event) {
            defferedFlowElementsToParse.add(flowElement);
        } else {
            bpmnParserHandlers.parseElement(this, flowElement);
        }
    }
    // Deferred elements
    for (FlowElement flowElement : defferedFlowElementsToParse) {
        bpmnParserHandlers.parseElement(this, flowElement);
    }
    // Boundary events are parsed after all the regular activities are parsed
    for (BoundaryEvent boundaryEvent : boundaryEventsToParse) {
        bpmnParserHandlers.parseElement(this, boundaryEvent);
    }
    // sequence flows
    for (SequenceFlow sequenceFlow : sequenceFlowToParse) {
        bpmnParserHandlers.parseElement(this, sequenceFlow);
    }
}
Also used : BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayList(java.util.ArrayList) Event(org.activiti.bpmn.model.Event) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent)

Aggregations

FlowElement (org.activiti.bpmn.model.FlowElement)75 SubProcess (org.activiti.bpmn.model.SubProcess)27 UserTask (org.activiti.bpmn.model.UserTask)25 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)24 StartEvent (org.activiti.bpmn.model.StartEvent)14 Process (org.activiti.bpmn.model.Process)13 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)9 Activity (org.activiti.bpmn.model.Activity)9 ServiceTask (org.activiti.bpmn.model.ServiceTask)9 Gateway (org.activiti.bpmn.model.Gateway)8 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)7 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)7 Artifact (org.activiti.bpmn.model.Artifact)6 FlowNode (org.activiti.bpmn.model.FlowNode)6 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)6 EventDefinition (org.activiti.bpmn.model.EventDefinition)5 ExclusiveGateway (org.activiti.bpmn.model.ExclusiveGateway)5