mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-01-29 10:15:43 +00:00
33f9e7be6e
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.
69 lines
1.5 KiB
JavaScript
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];
|
|
}
|