bpmn-js/lib/features/modeling/behavior/AttachEventBehavior.js
Maciej Barelkowski 33f9e7be6e feat(modeling): allow to attach events with event definition
This feature is allowed only for events which have their boundary
counteparts, i.e. intermediate throw, message catch, timer catch,
signal catch and conditional catch events.
2019-06-04 17:44:47 +00:00

69 lines
1.5 KiB
JavaScript

import inherits from 'inherits';
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
import { isAny } from '../util/ModelingUtil';
import { getBusinessObject } from '../../../util/ModelUtil';
/**
* BPMN specific attach event behavior
*/
export default function AttachEventBehavior(eventBus, bpmnReplace) {
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,
eventDefinition,
boundaryEvent,
newShape;
if (shapes.length !== 1) {
return;
}
shape = shapes[0];
if (host && isAny(shape, [ 'bpmn:IntermediateThrowEvent', 'bpmn:IntermediateCatchEvent' ])) {
eventDefinition = getEventDefinition(shape);
boundaryEvent = {
type: 'bpmn:BoundaryEvent'
};
if (eventDefinition) {
boundaryEvent.eventDefinitionType = eventDefinition.$type;
}
newShape = bpmnReplace.replaceElement(shape, boundaryEvent);
context.shapes = [ newShape ];
}
}, true);
}
AttachEventBehavior.$inject = [
'eventBus',
'bpmnReplace'
];
inherits(AttachEventBehavior, CommandInterceptor);
// helper /////
function getEventDefinition(element) {
var bo = getBusinessObject(element);
return bo && bo.eventDefinitions && bo.eventDefinitions[0];
}