diff --git a/lib/features/modeling/behavior/CreateBehavior.js b/lib/features/modeling/behavior/CreateBehavior.js index 0db1e246..d0cb040e 100644 --- a/lib/features/modeling/behavior/CreateBehavior.js +++ b/lib/features/modeling/behavior/CreateBehavior.js @@ -25,6 +25,11 @@ function CreateBehavior(eventBus, modeling) { shape = context.shape, position = context.position; + if (is(parent, 'bpmn:SequenceFlow')){ + context.insertTarget = parent; + context.parent = context.parent.parent; + } + if (is(parent, 'bpmn:Process') && is(shape, 'bpmn:Participant')) { // this is going to detach the process root @@ -75,6 +80,20 @@ function CreateBehavior(eventBus, modeling) { var processChildren = processRoot.children.slice(); modeling.moveShapes(processChildren, { x: 0, y: 0 }, shape); } + + if (context.insertTarget) { + + var initialTarget = context.insertTarget.target; + var insertShape = context.shape; + + // reconnecting end to inserted shape + modeling.reconnectEnd(context.insertTarget, insertShape, context.position); + + // create new connection between inserted shape and initial target + modeling.createConnection(insertShape, initialTarget, { + type: context.insertTarget.type, + }, context.parent); + } }, true); } diff --git a/lib/features/modeling/rules/BpmnRules.js b/lib/features/modeling/rules/BpmnRules.js index 685dd810..a12bd182 100644 --- a/lib/features/modeling/rules/BpmnRules.js +++ b/lib/features/modeling/rules/BpmnRules.js @@ -339,6 +339,10 @@ function canCreate(shape, target, source) { return false; } + if (canInsert(shape, target)){ + return true; + } + return canDrop(shape, target); } @@ -385,4 +389,22 @@ function canConnectSequenceFlow(source, target) { isSequenceFlowTarget(target) && isSameScope(source, target) && !(is(source, 'bpmn:EventBasedGateway') && !isEventBasedTarget(target)); +} + +function canInsert(shape, target) { + + var startEvent = target.source; + var endEvent = target.target; + + if (!is(target, 'bpmn:SequenceFlow')) { + return false; + } + + if(is(shape, 'bpmn:IntermediateThrowEvent') && + is(startEvent, 'bpmn:FlowElement') && + is(endEvent, 'bpmn:FlowElement')) { + return true; + } + + return false; } \ No newline at end of file diff --git a/test/spec/features/drop-on-connection/DropOnConnectionSpec.js b/test/spec/features/drop-on-connection/DropOnConnectionSpec.js new file mode 100644 index 00000000..101915f0 --- /dev/null +++ b/test/spec/features/drop-on-connection/DropOnConnectionSpec.js @@ -0,0 +1,36 @@ +'use strict'; + +var TestHelper = require('../../../TestHelper'); + +describe('drop on conection', function(){ + + var bpmnRules = require('../../../../lib/features/modeling/rules'); + var diagramXML = require('./diagram.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, {modules: bpmnRules})); + + it('should be allowed for an IntermediateThrowEvent', inject(function(elementRegistry, bpmnRules, elementFactory) { + var sequenceFlow = elementRegistry.get('SequenceFlow_0lk9mnl'); + var intermediateThrowEvent = elementFactory.createShape({ type: 'bpmn:IntermediateThrowEvent' }); + + expect(bpmnRules.canCreate(intermediateThrowEvent, sequenceFlow)).toBe(true); + })); + + it('should rearrange connections', inject(function(modeling, elementRegistry, elementFactory){ + var intermediateThrowEvent = elementFactory.createShape({ type: 'bpmn:IntermediateThrowEvent' }); + var startEvent = elementRegistry.get('StartEvent_1'); + var sequenceFlow = elementRegistry.get('SequenceFlow_0lk9mnl'); + var task = elementRegistry.get('Task_195jx60'); + var position = {x: startEvent.x + startEvent.height/2 + 100, + y: startEvent.y + startEvent.width/2}; + + // create new intermediateThrowEvent onto sequenceFlow + modeling.createShape(intermediateThrowEvent, position, sequenceFlow); + + // check rearragned connection + expect(startEvent.outgoing[0].id).toBe(intermediateThrowEvent.incoming[0].id); + + // check newly created connection + expect(intermediateThrowEvent.outgoing[0].id).toBe(task.incoming[0].id); + })); +}); \ No newline at end of file diff --git a/test/spec/features/drop-on-connection/diagram.bpmn b/test/spec/features/drop-on-connection/diagram.bpmn new file mode 100644 index 00000000..d2c4893c --- /dev/null +++ b/test/spec/features/drop-on-connection/diagram.bpmn @@ -0,0 +1,29 @@ + + + + + SequenceFlow_0lk9mnl + + + SequenceFlow_0lk9mnl + + + + + + + + + + + + + + + + + + + + +