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

100% Statements 12/12
100% Branches 6/6
100% Functions 3/3
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                        1189×               1189×   333× 333×       333× 27×       1189×   333×   333×   10×            
import inherits from 'inherits';
 
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
 
import { is } from '../../../util/ModelUtil';
 
 
/**
 * BPMN specific remove behavior
 */
export default function RemoveParticipantBehavior(eventBus, modeling) {
 
  CommandInterceptor.call(this, eventBus);
 
 
  /**
   * morph collaboration diagram into process diagram
   * after the last participant has been removed
   */
 
  this.preExecute('shape.delete', function(context) {
 
    var shape = context.shape,
        parent = shape.parent;
 
    // activate the behavior if the shape to be removed
    // is a participant
    if (is(shape, 'bpmn:Participant')) {
      context.collaborationRoot = parent;
    }
  }, true);
 
  this.postExecute('shape.delete', function(context) {
 
    var collaborationRoot = context.collaborationRoot;
 
    if (collaborationRoot && !collaborationRoot.businessObject.participants.length) {
      // replace empty collaboration with process diagram
      modeling.makeProcess();
    }
  }, true);
 
}
 
RemoveParticipantBehavior.$inject = [ 'eventBus', 'modeling' ];
 
inherits(RemoveParticipantBehavior, CommandInterceptor);