2019-05-17 12:26:13 +00:00
|
|
|
import inherits from 'inherits';
|
|
|
|
|
|
|
|
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
|
|
|
|
2019-05-22 08:42:07 +00:00
|
|
|
import { isAny } from '../util/ModelingUtil';
|
|
|
|
import { getBusinessObject } from '../../../util/ModelUtil';
|
2019-05-17 12:26:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BPMN specific attach event behavior
|
|
|
|
*/
|
2019-05-22 08:42:07 +00:00
|
|
|
export default function AttachEventBehavior(eventBus, bpmnReplace) {
|
2019-05-17 12:26:13 +00:00
|
|
|
|
|
|
|
CommandInterceptor.call(this, eventBus);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* replace intermediate event with boundary event when
|
|
|
|
* attaching it to a shape
|
|
|
|
*/
|
|
|
|
|
|
|
|
this.preExecute('elements.move', function(context) {
|
|
|
|
var shapes = context.shapes,
|
|
|
|
host = context.newHost,
|
|
|
|
shape,
|
2019-05-22 08:42:07 +00:00
|
|
|
eventDefinition,
|
|
|
|
boundaryEvent,
|
|
|
|
newShape;
|
2019-05-17 12:26:13 +00:00
|
|
|
|
|
|
|
if (shapes.length !== 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
shape = shapes[0];
|
|
|
|
|
2019-05-22 08:42:07 +00:00
|
|
|
if (host && isAny(shape, [ 'bpmn:IntermediateThrowEvent', 'bpmn:IntermediateCatchEvent' ])) {
|
2019-05-17 12:26:13 +00:00
|
|
|
|
2019-05-22 08:42:07 +00:00
|
|
|
eventDefinition = getEventDefinition(shape);
|
2019-05-17 12:26:13 +00:00
|
|
|
|
|
|
|
boundaryEvent = {
|
2019-05-23 06:38:18 +00:00
|
|
|
type: 'bpmn:BoundaryEvent',
|
|
|
|
host: host
|
2019-05-17 12:26:13 +00:00
|
|
|
};
|
|
|
|
|
2019-05-22 08:42:07 +00:00
|
|
|
if (eventDefinition) {
|
|
|
|
boundaryEvent.eventDefinitionType = eventDefinition.$type;
|
|
|
|
}
|
|
|
|
|
2019-06-04 10:07:55 +00:00
|
|
|
newShape = bpmnReplace.replaceElement(shape, boundaryEvent, { layoutConnection: false });
|
2019-05-17 12:26:13 +00:00
|
|
|
|
|
|
|
context.shapes = [ newShape ];
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
AttachEventBehavior.$inject = [
|
|
|
|
'eventBus',
|
|
|
|
'bpmnReplace'
|
|
|
|
];
|
|
|
|
|
|
|
|
inherits(AttachEventBehavior, CommandInterceptor);
|
2019-05-22 08:42:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// helper /////
|
|
|
|
function getEventDefinition(element) {
|
|
|
|
var bo = getBusinessObject(element);
|
|
|
|
|
|
|
|
return bo && bo.eventDefinitions && bo.eventDefinitions[0];
|
|
|
|
}
|