function CreateParticipantBehavior(canvas, eventBus, modeling) {
  CommandInterceptor.call(this, eventBus);

  // fit participant
  eventBus.on([
    'create.start',
    'shape.move.start'
  ], HIGH_PRIORITY, function(event) {
    var context = event.context,
        shape = context.shape,
        rootElement = canvas.getRootElement();

    if (!is(shape, 'bpmn:Participant') ||
      !is(rootElement, 'bpmn:Process') ||
      !rootElement.children.length) {
      return;
    }

    // ignore connections, groups and labels
    var children = rootElement.children.filter(function(element) {
      return !is(element, 'bpmn:Group') &&
        !isLabel(element) &&
        !isConnection(element);
    });

    // ensure for available children to calculate bounds
    if (!children.length) {
      return;
    }

    var childrenBBox = getBBox(children);

    var participantBounds = getParticipantBounds(shape, childrenBBox);

    // assign width and height
    assign(shape, participantBounds);

    // assign create constraints
    context.createConstraints = getParticipantCreateConstraints(shape, childrenBBox);
  });

  // force hovering process when creating first participant
  eventBus.on('create.start', HIGH_PRIORITY, function(event) {
    var context = event.context,
        shape = context.shape,
        rootElement = canvas.getRootElement(),
        rootElementGfx = canvas.getGraphics(rootElement);

    function ensureHoveringProcess(event) {
      event.element = rootElement;
      event.gfx = rootElementGfx;
    }

    if (is(shape, 'bpmn:Participant') && is(rootElement, 'bpmn:Process')) {
      eventBus.on('element.hover', HIGH_PRIORITY, ensureHoveringProcess);

      eventBus.once('create.cleanup', function() {
        eventBus.off('element.hover', ensureHoveringProcess);
      });
    }
  });

  function ensureCollaboration(context) {
    var parent = context.parent,
        collaboration;

    var rootElement = canvas.getRootElement();

    if (is(rootElement, 'bpmn:Collaboration')) {
      collaboration = rootElement;
    } else {

      // update root element by making collaboration
      collaboration = modeling.makeCollaboration();

      // re-use process when creating first participant
      context.process = parent;
    }

    context.parent = collaboration;
  }

  // turn process into collaboration before adding participant
  this.preExecute('shape.create', function(context) {
    var parent = context.parent,
        shape = context.shape;

    if (is(shape, 'bpmn:Participant') && is(parent, 'bpmn:Process')) {
      ensureCollaboration(context);
    }
  }, true);

  this.execute('shape.create', function(context) {
    var process = context.process,
        shape = context.shape;

    if (process) {
      context.oldProcessRef = shape.businessObject.processRef;

      // re-use process when creating first participant
      shape.businessObject.processRef = process.businessObject;
    }
  }, true);

  this.revert('shape.create', function(context) {
    var process = context.process,
        shape = context.shape;

    if (process) {

      // re-use process when creating first participant
      shape.businessObject.processRef = context.oldProcessRef;
    }
  }, true);

  this.postExecute('shape.create', function(context) {
    var process = context.process,
        shape = context.shape;

    if (process) {

      // move children from process to participant
      var processChildren = process.children.slice();

      modeling.moveElements(processChildren, { x: 0, y: 0 }, shape);
    }

  }, true);

  // turn process into collaboration when creating participants
  this.preExecute('elements.create', HIGH_PRIORITY, function(context) {
    var elements = context.elements,
        parent = context.parent,
        participant;

    var hasParticipants = findParticipant(elements);

    if (hasParticipants && is(parent, 'bpmn:Process')) {
      ensureCollaboration(context);

      participant = findParticipant(elements);

      context.oldProcessRef = participant.businessObject.processRef;

      // re-use process when creating first participant
      participant.businessObject.processRef = parent.businessObject;
    }
  }, true);

  this.revert('elements.create', function(context) {
    var elements = context.elements,
        process = context.process,
        participant;

    if (process) {
      participant = findParticipant(elements);

      // re-use process when creating first participant
      participant.businessObject.processRef = context.oldProcessRef;
    }
  }, true);

  this.postExecute('elements.create', function(context) {
    var elements = context.elements,
        process = context.process,
        participant;

    if (process) {
      participant = findParticipant(elements);

      // move children from process to first participant
      var processChildren = process.children.slice();

      modeling.moveElements(processChildren, { x: 0, y: 0 }, participant);
    }

  }, true);

}
/**
 * BPMN-specific behavior for creating participants.
 */
BPMN-specific behavior for creating participants.
BPMN - specific behavior for creating participants .
function CreateParticipantBehavior(canvas, eventBus, modeling) {
  CommandInterceptor.call(this, eventBus);
  eventBus.on([
    'create.start',
    'shape.move.start'
  ], HIGH_PRIORITY, function(event) {
    var context = event.context,
        shape = context.shape,
        rootElement = canvas.getRootElement();
    if (!is(shape, 'bpmn:Participant') ||
      !is(rootElement, 'bpmn:Process') ||
      !rootElement.children.length) {
      return;
    }
    var children = rootElement.children.filter(function(element) {
      return !is(element, 'bpmn:Group') &&
        !isLabel(element) &&
        !isConnection(element);
    });
    if (!children.length) {
      return;
    }
    var childrenBBox = getBBox(children);
    var participantBounds = getParticipantBounds(shape, childrenBBox);
    assign(shape, participantBounds);
    context.createConstraints = getParticipantCreateConstraints(shape, childrenBBox);
  });
  eventBus.on('create.start', HIGH_PRIORITY, function(event) {
    var context = event.context,
        shape = context.shape,
        rootElement = canvas.getRootElement(),
        rootElementGfx = canvas.getGraphics(rootElement);
    function ensureHoveringProcess(event) {
      event.element = rootElement;
      event.gfx = rootElementGfx;
    }
    if (is(shape, 'bpmn:Participant') && is(rootElement, 'bpmn:Process')) {
      eventBus.on('element.hover', HIGH_PRIORITY, ensureHoveringProcess);
      eventBus.once('create.cleanup', function() {
        eventBus.off('element.hover', ensureHoveringProcess);
      });
    }
  });
  function ensureCollaboration(context) {
    var parent = context.parent,
        collaboration;
    var rootElement = canvas.getRootElement();
    if (is(rootElement, 'bpmn:Collaboration')) {
      collaboration = rootElement;
    } else {
      collaboration = modeling.makeCollaboration();
      context.process = parent;
    }
    context.parent = collaboration;
  }
  this.preExecute('shape.create', function(context) {
    var parent = context.parent,
        shape = context.shape;
    if (is(shape, 'bpmn:Participant') && is(parent, 'bpmn:Process')) {
      ensureCollaboration(context);
    }
  }, true);
  this.execute('shape.create', function(context) {
    var process = context.process,
        shape = context.shape;
    if (process) {
      context.oldProcessRef = shape.businessObject.processRef;
      shape.businessObject.processRef = process.businessObject;
    }
  }, true);
  this.revert('shape.create', function(context) {
    var process = context.process,
        shape = context.shape;
    if (process) {
      shape.businessObject.processRef = context.oldProcessRef;
    }
  }, true);
  this.postExecute('shape.create', function(context) {
    var process = context.process,
        shape = context.shape;
    if (process) {
      var processChildren = process.children.slice();
      modeling.moveElements(processChildren, { x: 0, y: 0 }, shape);
    }
  }, true);
  this.preExecute('elements.create', HIGH_PRIORITY, function(context) {
    var elements = context.elements,
        parent = context.parent,
        participant;
    var hasParticipants = findParticipant(elements);
    if (hasParticipants && is(parent, 'bpmn:Process')) {
      ensureCollaboration(context);
      participant = findParticipant(elements);
      context.oldProcessRef = participant.businessObject.processRef;
      participant.businessObject.processRef = parent.businessObject;
    }
  }, true);
  this.revert('elements.create', function(context) {
    var elements = context.elements,
        process = context.process,
        participant;
    if (process) {
      participant = findParticipant(elements);
      participant.businessObject.processRef = context.oldProcessRef;
    }
  }, true);
  this.postExecute('elements.create', function(context) {
    var elements = context.elements,
        process = context.process,
        participant;
    if (process) {
      participant = findParticipant(elements);
      var processChildren = process.children.slice();
      modeling.moveElements(processChildren, { x: 0, y: 0 }, participant);
    }
  }, true);
}
function CreateParticipantBehavior ( canvas , eventBus , modeling ) { CommandInterceptor . call ( this , eventBus ) ; eventBus . on ( [ 'create.start' , 'shape.move.start' ] , HIGH_PRIORITY , function ( event ) { var context = event . context , shape = context . shape , rootElement = canvas . getRootElement ( ) ; if ( ! is ( shape , 'bpmn:Participant' ) || ! is ( rootElement , 'bpmn:Process' ) || ! rootElement . children . length ) { return ; } var children = rootElement . children . filter ( function ( element ) { return ! is ( element , 'bpmn:Group' ) && ! isLabel ( element ) && ! isConnection ( element ) ; } ) ; if ( ! children . length ) { return ; } var childrenBBox = getBBox ( children ) ; var participantBounds = getParticipantBounds ( shape , childrenBBox ) ; assign ( shape , participantBounds ) ; context . createConstraints = getParticipantCreateConstraints ( shape , childrenBBox ) ; } ) ; eventBus . on ( 'create.start' , HIGH_PRIORITY , function ( event ) { var context = event . context , shape = context . shape , rootElement = canvas . getRootElement ( ) , rootElementGfx = canvas . getGraphics ( rootElement ) ; function ensureHoveringProcess ( event ) { event . element = rootElement ; event . gfx = rootElementGfx ; } if ( is ( shape , 'bpmn:Participant' ) && is ( rootElement , 'bpmn:Process' ) ) { eventBus . on ( 'element.hover' , HIGH_PRIORITY , ensureHoveringProcess ) ; eventBus . once ( 'create.cleanup' , function ( ) { eventBus . off ( 'element.hover' , ensureHoveringProcess ) ; } ) ; } } ) ; function ensureCollaboration ( context ) { var parent = context . parent , collaboration ; var rootElement = canvas . getRootElement ( ) ; if ( is ( rootElement , 'bpmn:Collaboration' ) ) { collaboration = rootElement ; } else { collaboration = modeling . makeCollaboration ( ) ; context . process = parent ; } context . parent = collaboration ; } this . preExecute ( 'shape.create' , function ( context ) { var parent = context . parent , shape = context . shape ; if ( is ( shape , 'bpmn:Participant' ) && is ( parent , 'bpmn:Process' ) ) { ensureCollaboration ( context ) ; } } , true ) ; this . execute ( 'shape.create' , function ( context ) { var process = context . process , shape = context . shape ; if ( process ) { context . oldProcessRef = shape . businessObject . processRef ; shape . businessObject . processRef = process . businessObject ; } } , true ) ; this . revert ( 'shape.create' , function ( context ) { var process = context . process , shape = context . shape ; if ( process ) { shape . businessObject . processRef = context . oldProcessRef ; } } , true ) ; this . postExecute ( 'shape.create' , function ( context ) { var process = context . process , shape = context . shape ; if ( process ) { var processChildren = process . children . slice ( ) ; modeling . moveElements ( processChildren , { x : 0 , y : 0 } , shape ) ; } } , true ) ; this . preExecute ( 'elements.create' , HIGH_PRIORITY , function ( context ) { var elements = context . elements , parent = context . parent , participant ; var hasParticipants = findParticipant ( elements ) ; if ( hasParticipants && is ( parent , 'bpmn:Process' ) ) { ensureCollaboration ( context ) ; participant = findParticipant ( elements ) ; context . oldProcessRef = participant . businessObject . processRef ; participant . businessObject . processRef = parent . businessObject ; } } , true ) ; this . revert ( 'elements.create' , function ( context ) { var elements = context . elements , process = context . process , participant ; if ( process ) { participant = findParticipant ( elements ) ; participant . businessObject . processRef = context . oldProcessRef ; } } , true ) ; this . postExecute ( 'elements.create' , function ( context ) { var elements = context . elements , process = context . process , participant ; if ( process ) { participant = findParticipant ( elements ) ; var processChildren = process . children . slice ( ) ; modeling . moveElements ( processChildren , { x : 0 , y : 0 } , participant ) ; } } , true ) ; }
BPMN-specific behavior for creating participants.
BPMN - specific behavior for creating participants .
// fit participant // ignore connections, groups and labels // ensure for available children to calculate bounds // assign width and height // assign create constraints // force hovering process when creating first participant // update root element by making collaboration // re-use process when creating first participant // turn process into collaboration before adding participant // re-use process when creating first participant // re-use process when creating first participant // move children from process to participant // turn process into collaboration when creating participants // re-use process when creating first participant // re-use process when creating first participant // move children from process to first participant