2015-03-31 13:02:04 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var inherits = require('inherits');
|
|
|
|
|
|
|
|
var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor');
|
|
|
|
|
2015-04-27 14:50:09 +00:00
|
|
|
var is = require('../../../util/ModelUtil').is;
|
2015-03-31 13:02:04 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-13 08:37:43 +00:00
|
|
|
* BPMN specific create participant behavior
|
2015-03-31 13:02:04 +00:00
|
|
|
*/
|
2015-07-13 08:37:43 +00:00
|
|
|
function CreateParticipantBehavior(eventBus, modeling, elementFactory, bpmnFactory) {
|
2015-03-31 13:02:04 +00:00
|
|
|
|
|
|
|
CommandInterceptor.call(this, eventBus);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* morph process into collaboration before adding
|
|
|
|
* participant onto collaboration
|
|
|
|
*/
|
|
|
|
|
|
|
|
this.preExecute('shape.create', function(context) {
|
|
|
|
|
|
|
|
var parent = context.parent,
|
|
|
|
shape = context.shape,
|
|
|
|
position = context.position;
|
|
|
|
|
2015-04-27 14:50:09 +00:00
|
|
|
if (is(parent, 'bpmn:Process') && is(shape, 'bpmn:Participant')) {
|
2015-03-31 13:02:04 +00:00
|
|
|
|
|
|
|
// this is going to detach the process root
|
|
|
|
// and set the returned collaboration element
|
|
|
|
// as the new root element
|
|
|
|
var collaborationElement = modeling.makeCollaboration();
|
|
|
|
|
|
|
|
// monkey patch the create context
|
|
|
|
// so that the participant is being dropped
|
|
|
|
// onto the new collaboration root instead
|
|
|
|
context.position = position;
|
|
|
|
context.parent = collaborationElement;
|
|
|
|
|
|
|
|
context.processRoot = parent;
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
|
2015-03-31 13:02:04 +00:00
|
|
|
this.execute('shape.create', function(context) {
|
|
|
|
|
|
|
|
var processRoot = context.processRoot,
|
|
|
|
shape = context.shape;
|
|
|
|
|
|
|
|
if (processRoot) {
|
|
|
|
context.oldProcessRef = shape.businessObject.processRef;
|
|
|
|
|
|
|
|
// assign the participant processRef
|
|
|
|
shape.businessObject.processRef = processRoot.businessObject;
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
|
2015-03-31 13:02:04 +00:00
|
|
|
this.revert('shape.create', function(context) {
|
|
|
|
var processRoot = context.processRoot,
|
|
|
|
shape = context.shape;
|
|
|
|
|
|
|
|
if (processRoot) {
|
|
|
|
// assign the participant processRef
|
|
|
|
shape.businessObject.processRef = context.oldProcessRef;
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
|
2015-03-31 13:02:04 +00:00
|
|
|
this.postExecute('shape.create', function(context) {
|
|
|
|
|
|
|
|
var processRoot = context.processRoot,
|
|
|
|
shape = context.shape;
|
|
|
|
|
|
|
|
if (processRoot) {
|
|
|
|
// process root is already detached at this point
|
|
|
|
var processChildren = processRoot.children.slice();
|
2015-08-13 08:51:52 +00:00
|
|
|
modeling.moveElements(processChildren, { x: 0, y: 0 }, shape);
|
2015-03-31 13:02:04 +00:00
|
|
|
}
|
2015-07-13 08:37:43 +00:00
|
|
|
|
2015-03-31 13:02:04 +00:00
|
|
|
}, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
CreateParticipantBehavior.$inject = [ 'eventBus', 'modeling', 'elementFactory', 'bpmnFactory' ];
|
2015-03-31 13:02:04 +00:00
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
inherits(CreateParticipantBehavior, CommandInterceptor);
|
2015-03-31 13:02:04 +00:00
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
module.exports = CreateParticipantBehavior;
|