all files / bpmn-js/lib/features/modeling/behavior/ CreateBoundaryEventBehavior.js

100% Statements 12/12
100% Branches 4/4
100% Functions 2/2
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                            1189×             1189× 420× 420×       420×       420×                                  
import inherits from 'inherits';
 
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
 
import { is } from '../../../util/ModelUtil';
 
 
/**
 * BPMN specific create boundary event behavior
 */
export default function CreateBoundaryEventBehavior(
    eventBus, modeling, elementFactory,
    bpmnFactory) {
 
  CommandInterceptor.call(this, eventBus);
 
  /**
   * replace intermediate event with boundary event when
   * attaching it to a shape
   */
 
  this.preExecute('shape.create', function(context) {
    var shape = context.shape,
        host = context.host,
        businessObject,
        boundaryEvent;
 
    var attrs = {
      cancelActivity: true
    };
 
    if (host && is(shape, 'bpmn:IntermediateThrowEvent')) {
      attrs.attachedToRef = host.businessObject;
 
      businessObject = bpmnFactory.create('bpmn:BoundaryEvent', attrs);
 
      boundaryEvent = {
        type: 'bpmn:BoundaryEvent',
        businessObject: businessObject
      };
 
      context.shape = elementFactory.createShape(boundaryEvent);
    }
  }, true);
}
 
CreateBoundaryEventBehavior.$inject = [
  'eventBus',
  'modeling',
  'elementFactory',
  'bpmnFactory'
];
 
inherits(CreateBoundaryEventBehavior, CommandInterceptor);