2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
assign,
|
|
|
|
forEach
|
|
|
|
} from 'min-dash';
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2014-11-27 10:55:38 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
remove as collectionRemove,
|
|
|
|
add as collectionAdd
|
|
|
|
} from 'diagram-js/lib/util/Collections';
|
2015-07-20 11:33:51 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
Label
|
|
|
|
} from 'diagram-js/lib/model';
|
|
|
|
|
|
|
|
import {
|
|
|
|
getBusinessObject,
|
|
|
|
is
|
|
|
|
} from '../../util/ModelUtil';
|
|
|
|
|
|
|
|
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
2015-04-27 14:50:09 +00:00
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
/**
|
|
|
|
* A handler responsible for updating the underlying BPMN 2.0 XML + DI
|
|
|
|
* once changes on the diagram happen
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function BpmnUpdater(
|
|
|
|
eventBus, bpmnFactory, connectionDocking,
|
|
|
|
translate) {
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-04-27 14:50:09 +00:00
|
|
|
CommandInterceptor.call(this, eventBus);
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
this._bpmnFactory = bpmnFactory;
|
2016-02-25 16:40:56 +00:00
|
|
|
this._translate = translate;
|
2014-07-23 16:53:33 +00:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// connection cropping //////////////////////
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
// crop connection ends during create/update
|
|
|
|
function cropConnection(e) {
|
|
|
|
var context = e.context,
|
|
|
|
connection;
|
|
|
|
|
|
|
|
if (!context.cropped) {
|
|
|
|
connection = context.connection;
|
|
|
|
connection.waypoints = connectionDocking.getCroppedWaypoints(connection);
|
|
|
|
context.cropped = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-14 17:48:06 +00:00
|
|
|
this.executed([
|
|
|
|
'connection.layout',
|
|
|
|
'connection.create',
|
|
|
|
'connection.reconnectEnd',
|
|
|
|
'connection.reconnectStart'
|
|
|
|
], cropConnection);
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
this.reverted([ 'connection.layout' ], function(e) {
|
|
|
|
delete e.context.cropped;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// BPMN + DI update //////////////////////
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
// update parent
|
2014-11-21 08:19:35 +00:00
|
|
|
function updateParent(e) {
|
2015-08-31 12:59:29 +00:00
|
|
|
var context = e.context;
|
|
|
|
|
|
|
|
self.updateParent(context.shape || context.connection, context.oldParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
function reverseUpdateParent(e) {
|
|
|
|
var context = e.context;
|
|
|
|
|
|
|
|
var element = context.shape || context.connection,
|
|
|
|
// oldParent is the (old) new parent, because we are undoing
|
|
|
|
oldParent = context.parent || context.newParent;
|
|
|
|
|
|
|
|
self.updateParent(element, oldParent);
|
2014-07-23 16:53:33 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 07:47:04 +00:00
|
|
|
this.executed([
|
|
|
|
'shape.move',
|
|
|
|
'shape.create',
|
|
|
|
'shape.delete',
|
|
|
|
'connection.create',
|
|
|
|
'connection.move',
|
|
|
|
'connection.delete'
|
|
|
|
], ifBpmn(updateParent));
|
|
|
|
|
|
|
|
this.reverted([
|
|
|
|
'shape.move',
|
|
|
|
'shape.create',
|
|
|
|
'shape.delete',
|
|
|
|
'connection.create',
|
|
|
|
'connection.move',
|
|
|
|
'connection.delete'
|
|
|
|
], ifBpmn(reverseUpdateParent));
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-05-04 12:59:26 +00:00
|
|
|
/*
|
|
|
|
* ## Updating Parent
|
|
|
|
*
|
2015-07-20 11:33:51 +00:00
|
|
|
* When morphing a Process into a Collaboration or vice-versa,
|
2015-05-04 12:59:26 +00:00
|
|
|
* make sure that both the *semantic* and *di* parent of each element
|
|
|
|
* is updated.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function updateRoot(event) {
|
|
|
|
var context = event.context,
|
|
|
|
oldRoot = context.oldRoot,
|
|
|
|
children = oldRoot.children;
|
|
|
|
|
|
|
|
forEach(children, function(child) {
|
2016-05-30 17:42:46 +00:00
|
|
|
if (is(child, 'bpmn:BaseElement')) {
|
|
|
|
self.updateParent(child);
|
|
|
|
}
|
2015-05-04 12:59:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.executed([ 'canvas.updateRoot' ], updateRoot);
|
|
|
|
this.reverted([ 'canvas.updateRoot' ], updateRoot);
|
|
|
|
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
// update bounds
|
2014-07-30 14:07:43 +00:00
|
|
|
function updateBounds(e) {
|
2015-09-02 13:13:18 +00:00
|
|
|
var shape = e.context.shape;
|
|
|
|
|
|
|
|
if (!is(shape, 'bpmn:BaseElement')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.updateBounds(shape);
|
2014-07-30 14:07:43 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 16:06:50 +00:00
|
|
|
this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], ifBpmn(function(event) {
|
|
|
|
|
|
|
|
// exclude labels because they're handled separately during shape.changed
|
|
|
|
if (event.context.shape.type === 'label') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateBounds(event);
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.reverted([ 'shape.move', 'shape.create', 'shape.resize' ], ifBpmn(function(event) {
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2016-09-01 16:06:50 +00:00
|
|
|
// exclude labels because they're handled separately during shape.changed
|
|
|
|
if (event.context.shape.type === 'label') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateBounds(event);
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Handle labels separately. This is necessary, because the label bounds have to be updated
|
|
|
|
// every time its shape changes, not only on move, create and resize.
|
|
|
|
eventBus.on('shape.changed', function(event) {
|
|
|
|
if (event.element.type === 'label') {
|
|
|
|
updateBounds({ context: { shape: event.element } });
|
|
|
|
}
|
|
|
|
});
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
// attach / detach connection
|
2014-07-23 16:53:33 +00:00
|
|
|
function updateConnection(e) {
|
2015-10-06 08:50:47 +00:00
|
|
|
self.updateConnection(e.context);
|
2014-07-23 16:53:33 +00:00
|
|
|
}
|
|
|
|
|
2015-01-14 17:48:06 +00:00
|
|
|
this.executed([
|
|
|
|
'connection.create',
|
|
|
|
'connection.move',
|
|
|
|
'connection.delete',
|
|
|
|
'connection.reconnectEnd',
|
|
|
|
'connection.reconnectStart'
|
2015-09-02 13:13:18 +00:00
|
|
|
], ifBpmn(updateConnection));
|
2015-01-14 17:48:06 +00:00
|
|
|
|
|
|
|
this.reverted([
|
|
|
|
'connection.create',
|
|
|
|
'connection.move',
|
|
|
|
'connection.delete',
|
|
|
|
'connection.reconnectEnd',
|
|
|
|
'connection.reconnectStart'
|
2015-09-02 13:13:18 +00:00
|
|
|
], ifBpmn(updateConnection));
|
2014-07-30 14:06:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
// update waypoints
|
|
|
|
function updateConnectionWaypoints(e) {
|
|
|
|
self.updateConnectionWaypoints(e.context.connection);
|
|
|
|
}
|
|
|
|
|
2015-01-14 17:48:06 +00:00
|
|
|
this.executed([
|
|
|
|
'connection.layout',
|
|
|
|
'connection.move',
|
|
|
|
'connection.updateWaypoints',
|
|
|
|
'connection.reconnectEnd',
|
|
|
|
'connection.reconnectStart'
|
2015-09-02 13:13:18 +00:00
|
|
|
], ifBpmn(updateConnectionWaypoints));
|
2015-01-14 17:48:06 +00:00
|
|
|
|
|
|
|
this.reverted([
|
|
|
|
'connection.layout',
|
|
|
|
'connection.move',
|
|
|
|
'connection.updateWaypoints',
|
|
|
|
'connection.reconnectEnd',
|
|
|
|
'connection.reconnectStart'
|
2015-09-02 13:13:18 +00:00
|
|
|
], ifBpmn(updateConnectionWaypoints));
|
2015-07-13 08:37:43 +00:00
|
|
|
|
2015-10-06 08:50:47 +00:00
|
|
|
|
|
|
|
// update Default & Conditional flows
|
|
|
|
this.executed([
|
|
|
|
'connection.reconnectEnd',
|
|
|
|
'connection.reconnectStart'
|
|
|
|
], ifBpmn(function(e) {
|
|
|
|
var context = e.context,
|
|
|
|
connection = context.connection,
|
|
|
|
businessObject = getBusinessObject(connection),
|
|
|
|
oldSource = getBusinessObject(context.oldSource),
|
|
|
|
oldTarget = getBusinessObject(context.oldTarget),
|
|
|
|
newSource = getBusinessObject(connection.source),
|
|
|
|
newTarget = getBusinessObject(connection.target);
|
|
|
|
|
|
|
|
if (oldSource === newSource || oldTarget === newTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// on reconnectStart -> default flow
|
2016-10-18 11:18:13 +00:00
|
|
|
if (oldSource && oldSource.default === businessObject) {
|
2015-10-06 08:50:47 +00:00
|
|
|
context.default = oldSource.default;
|
|
|
|
oldSource.default = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
// on reconnectEnd -> default flow
|
2016-05-06 13:52:20 +00:00
|
|
|
if ((businessObject.sourceRef && businessObject.sourceRef.default) &&
|
|
|
|
!(is(newTarget, 'bpmn:Activity') ||
|
|
|
|
is(newTarget, 'bpmn:EndEvent') ||
|
2016-06-20 14:27:36 +00:00
|
|
|
is(newTarget, 'bpmn:Gateway') ||
|
2018-02-27 09:08:31 +00:00
|
|
|
is(newTarget, 'bpmn:IntermediateThrowEvent'))) {
|
2015-10-06 08:50:47 +00:00
|
|
|
context.default = businessObject.sourceRef.default;
|
|
|
|
businessObject.sourceRef.default = undefined;
|
|
|
|
}
|
|
|
|
|
2016-05-06 13:52:20 +00:00
|
|
|
// on reconnectStart -> conditional flow
|
2016-06-20 14:27:36 +00:00
|
|
|
if (oldSource && (businessObject.conditionExpression) &&
|
|
|
|
!(is(newSource, 'bpmn:Activity') ||
|
2018-02-27 09:08:31 +00:00
|
|
|
is(newSource, 'bpmn:Gateway'))) {
|
2015-10-06 08:50:47 +00:00
|
|
|
context.conditionExpression = businessObject.conditionExpression;
|
|
|
|
businessObject.conditionExpression = undefined;
|
|
|
|
}
|
|
|
|
|
2016-05-06 13:52:20 +00:00
|
|
|
// on reconnectEnd -> conditional flow
|
2016-06-20 14:27:36 +00:00
|
|
|
if (oldTarget && (businessObject.conditionExpression) &&
|
2016-05-06 13:52:20 +00:00
|
|
|
!(is(newTarget, 'bpmn:Activity') ||
|
|
|
|
is(newTarget, 'bpmn:EndEvent') ||
|
2016-06-20 14:27:36 +00:00
|
|
|
is(newTarget, 'bpmn:Gateway') ||
|
2018-02-27 09:08:31 +00:00
|
|
|
is(newTarget, 'bpmn:IntermediateThrowEvent'))) {
|
2015-10-06 08:50:47 +00:00
|
|
|
context.conditionExpression = businessObject.conditionExpression;
|
|
|
|
businessObject.conditionExpression = undefined;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.reverted([
|
|
|
|
'connection.reconnectEnd',
|
|
|
|
'connection.reconnectStart'
|
|
|
|
], ifBpmn(function(e) {
|
|
|
|
var context = e.context,
|
|
|
|
connection = context.connection,
|
|
|
|
businessObject = getBusinessObject(connection),
|
|
|
|
newSource = getBusinessObject(connection.source);
|
|
|
|
|
|
|
|
// default flow
|
|
|
|
if (context.default) {
|
2016-01-07 08:03:20 +00:00
|
|
|
if (is(newSource, 'bpmn:ExclusiveGateway') || is(newSource, 'bpmn:InclusiveGateway') ||
|
|
|
|
is(newSource, 'bpmn:Activity')) {
|
2015-10-06 08:50:47 +00:00
|
|
|
newSource.default = context.default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// conditional flow
|
|
|
|
if (context.conditionExpression && is(newSource, 'bpmn:Activity')) {
|
|
|
|
businessObject.conditionExpression = context.conditionExpression;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
// update attachments
|
|
|
|
function updateAttachment(e) {
|
|
|
|
self.updateAttachment(e.context);
|
|
|
|
}
|
|
|
|
|
2015-09-02 13:13:18 +00:00
|
|
|
this.executed([ 'element.updateAttachment' ], ifBpmn(updateAttachment));
|
|
|
|
this.reverted([ 'element.updateAttachment' ], ifBpmn(updateAttachment));
|
2014-07-23 16:53:33 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 14:50:09 +00:00
|
|
|
inherits(BpmnUpdater, CommandInterceptor);
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
BpmnUpdater.$inject = [
|
|
|
|
'eventBus',
|
|
|
|
'bpmnFactory',
|
|
|
|
'connectionDocking',
|
|
|
|
'translate'
|
|
|
|
];
|
2014-07-23 16:53:33 +00:00
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// implementation //////////////////////
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
BpmnUpdater.prototype.updateAttachment = function(context) {
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
var shape = context.shape,
|
|
|
|
businessObject = shape.businessObject,
|
|
|
|
host = shape.host;
|
2014-10-27 11:07:57 +00:00
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
businessObject.attachedToRef = host && host.businessObject;
|
|
|
|
};
|
|
|
|
|
2015-08-31 12:59:29 +00:00
|
|
|
BpmnUpdater.prototype.updateParent = function(element, oldParent) {
|
2014-11-27 10:55:38 +00:00
|
|
|
// do not update BPMN 2.0 label parent
|
2018-04-02 19:01:53 +00:00
|
|
|
if (element instanceof Label) {
|
2014-11-27 10:55:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-03 14:02:41 +00:00
|
|
|
// data stores in collaborations are handled seperately by DataStoreBehavior
|
|
|
|
if (is(element, 'bpmn:DataStoreReference') &&
|
|
|
|
element.parent &&
|
|
|
|
is(element.parent, 'bpmn:Collaboration')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-21 08:19:35 +00:00
|
|
|
var parentShape = element.parent;
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2014-11-21 08:19:35 +00:00
|
|
|
var businessObject = element.businessObject,
|
2014-07-23 16:53:33 +00:00
|
|
|
parentBusinessObject = parentShape && parentShape.businessObject,
|
|
|
|
parentDi = parentBusinessObject && parentBusinessObject.di;
|
|
|
|
|
2015-08-31 12:59:29 +00:00
|
|
|
if (is(element, 'bpmn:FlowNode')) {
|
|
|
|
this.updateFlowNodeRefs(businessObject, parentBusinessObject, oldParent && oldParent.businessObject);
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
if (is(element, 'bpmn:DataOutputAssociation')) {
|
|
|
|
if (element.source) {
|
|
|
|
parentBusinessObject = element.source.businessObject;
|
|
|
|
} else {
|
|
|
|
parentBusinessObject = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is(element, 'bpmn:DataInputAssociation')) {
|
|
|
|
if (element.target) {
|
|
|
|
parentBusinessObject = element.target.businessObject;
|
|
|
|
} else {
|
|
|
|
parentBusinessObject = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
this.updateSemanticParent(businessObject, parentBusinessObject);
|
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
if (is(element, 'bpmn:DataObjectReference') && businessObject.dataObjectRef) {
|
|
|
|
this.updateSemanticParent(businessObject.dataObjectRef, parentBusinessObject);
|
|
|
|
}
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
this.updateDiParent(businessObject.di, parentDi);
|
|
|
|
};
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2014-07-30 14:07:43 +00:00
|
|
|
BpmnUpdater.prototype.updateBounds = function(shape) {
|
|
|
|
|
|
|
|
var di = shape.businessObject.di;
|
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
var target = (shape instanceof Label) ? this._getLabel(di) : di;
|
|
|
|
|
|
|
|
var bounds = target.bounds;
|
|
|
|
|
|
|
|
if (!bounds) {
|
|
|
|
bounds = this._bpmnFactory.createDiBounds();
|
|
|
|
target.set('bounds', bounds);
|
|
|
|
}
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
assign(bounds, {
|
2014-07-30 14:07:43 +00:00
|
|
|
x: shape.x,
|
2014-08-02 14:38:25 +00:00
|
|
|
y: shape.y,
|
|
|
|
width: shape.width,
|
|
|
|
height: shape.height
|
2014-07-30 14:07:43 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-31 12:59:29 +00:00
|
|
|
BpmnUpdater.prototype.updateFlowNodeRefs = function(businessObject, newContainment, oldContainment) {
|
|
|
|
|
|
|
|
if (oldContainment === newContainment) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var oldRefs, newRefs;
|
|
|
|
|
|
|
|
if (is (oldContainment, 'bpmn:Lane')) {
|
|
|
|
oldRefs = oldContainment.get('flowNodeRef');
|
2018-04-02 19:01:53 +00:00
|
|
|
collectionRemove(oldRefs, businessObject);
|
2015-08-31 12:59:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is(newContainment, 'bpmn:Lane')) {
|
|
|
|
newRefs = newContainment.get('flowNodeRef');
|
2018-04-02 19:01:53 +00:00
|
|
|
collectionAdd(newRefs, businessObject);
|
2015-08-31 12:59:29 +00:00
|
|
|
}
|
|
|
|
};
|
2014-07-30 14:06:32 +00:00
|
|
|
|
2016-10-28 15:42:42 +00:00
|
|
|
|
|
|
|
// update existing sourceElement and targetElement di information
|
|
|
|
BpmnUpdater.prototype.updateDiConnection = function(di, newSource, newTarget) {
|
|
|
|
|
|
|
|
if (di.sourceElement && di.sourceElement.bpmnElement !== newSource) {
|
|
|
|
di.sourceElement = newSource && newSource.di;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (di.targetElement && di.targetElement.bpmnElement !== newTarget) {
|
|
|
|
di.targetElement = newTarget && newTarget.di;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {
|
|
|
|
|
2015-07-20 11:33:51 +00:00
|
|
|
if (parentDi && !is(parentDi, 'bpmndi:BPMNPlane')) {
|
2014-07-23 16:53:33 +00:00
|
|
|
parentDi = parentDi.$parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (di.$parent === parentDi) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var planeElements = (parentDi || di.$parent).get('planeElement');
|
|
|
|
|
|
|
|
if (parentDi) {
|
|
|
|
planeElements.push(di);
|
|
|
|
di.$parent = parentDi;
|
|
|
|
} else {
|
2018-04-02 19:01:53 +00:00
|
|
|
collectionRemove(planeElements, di);
|
2014-07-23 16:53:33 +00:00
|
|
|
di.$parent = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-31 13:02:04 +00:00
|
|
|
function getDefinitions(element) {
|
2015-07-20 11:33:51 +00:00
|
|
|
while (element && !is(element, 'bpmn:Definitions')) {
|
2015-03-31 13:02:04 +00:00
|
|
|
element = element.$parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-08-11 09:53:24 +00:00
|
|
|
BpmnUpdater.prototype.getLaneSet = function(container) {
|
|
|
|
|
|
|
|
var laneSet, laneSets;
|
|
|
|
|
|
|
|
// bpmn:Lane
|
|
|
|
if (is(container, 'bpmn:Lane')) {
|
|
|
|
laneSet = container.childLaneSet;
|
|
|
|
|
|
|
|
if (!laneSet) {
|
|
|
|
laneSet = this._bpmnFactory.create('bpmn:LaneSet');
|
|
|
|
container.childLaneSet = laneSet;
|
|
|
|
laneSet.$parent = container;
|
|
|
|
}
|
|
|
|
|
|
|
|
return laneSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// bpmn:Participant
|
|
|
|
if (is(container, 'bpmn:Participant')) {
|
|
|
|
container = container.processRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
// bpmn:FlowElementsContainer
|
|
|
|
laneSets = container.get('laneSets');
|
|
|
|
laneSet = laneSets[0];
|
|
|
|
|
|
|
|
if (!laneSet) {
|
|
|
|
laneSet = this._bpmnFactory.create('bpmn:LaneSet');
|
|
|
|
laneSet.$parent = container;
|
|
|
|
laneSets.push(laneSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return laneSet;
|
|
|
|
};
|
|
|
|
|
2016-05-09 10:38:01 +00:00
|
|
|
BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent, visualParent) {
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2016-02-25 16:40:56 +00:00
|
|
|
var containment,
|
|
|
|
translate = this._translate;
|
2014-12-02 07:36:15 +00:00
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
if (businessObject.$parent === newParent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-11 09:53:24 +00:00
|
|
|
if (is(businessObject, 'bpmn:Lane')) {
|
|
|
|
|
|
|
|
if (newParent) {
|
|
|
|
newParent = this.getLaneSet(newParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
containment = 'lanes';
|
|
|
|
} else
|
|
|
|
|
2015-07-20 11:33:51 +00:00
|
|
|
if (is(businessObject, 'bpmn:FlowElement')) {
|
2014-12-02 07:36:15 +00:00
|
|
|
|
2015-08-11 09:53:24 +00:00
|
|
|
if (newParent) {
|
|
|
|
|
|
|
|
if (is(newParent, 'bpmn:Participant')) {
|
|
|
|
newParent = newParent.processRef;
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (is(newParent, 'bpmn:Lane')) {
|
|
|
|
do {
|
|
|
|
// unwrap Lane -> LaneSet -> (Lane | FlowElementsContainer)
|
|
|
|
newParent = newParent.$parent.$parent;
|
2016-06-07 06:46:45 +00:00
|
|
|
} while (is(newParent, 'bpmn:Lane'));
|
2015-08-11 09:53:24 +00:00
|
|
|
|
|
|
|
}
|
2014-12-02 07:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
containment = 'flowElements';
|
2015-04-16 07:11:04 +00:00
|
|
|
|
2014-12-02 07:36:15 +00:00
|
|
|
} else
|
|
|
|
|
2015-07-20 11:33:51 +00:00
|
|
|
if (is(businessObject, 'bpmn:Artifact')) {
|
2014-12-02 07:36:15 +00:00
|
|
|
|
|
|
|
while (newParent &&
|
2015-07-20 11:33:51 +00:00
|
|
|
!is(newParent, 'bpmn:Process') &&
|
|
|
|
!is(newParent, 'bpmn:SubProcess') &&
|
|
|
|
!is(newParent, 'bpmn:Collaboration')) {
|
2014-12-02 07:36:15 +00:00
|
|
|
|
2015-07-20 11:33:51 +00:00
|
|
|
if (is(newParent, 'bpmn:Participant')) {
|
2014-12-02 07:36:15 +00:00
|
|
|
newParent = newParent.processRef;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
newParent = newParent.$parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
containment = 'artifacts';
|
2015-04-16 07:11:04 +00:00
|
|
|
} else
|
|
|
|
|
2015-07-20 11:33:51 +00:00
|
|
|
if (is(businessObject, 'bpmn:MessageFlow')) {
|
2015-04-16 07:11:04 +00:00
|
|
|
containment = 'messageFlows';
|
|
|
|
|
|
|
|
} else
|
2014-12-02 07:36:15 +00:00
|
|
|
|
2015-07-20 11:33:51 +00:00
|
|
|
if (is(businessObject, 'bpmn:Participant')) {
|
2015-03-31 13:02:04 +00:00
|
|
|
containment = 'participants';
|
|
|
|
|
|
|
|
// make sure the participants process is properly attached / detached
|
|
|
|
// from the XML document
|
|
|
|
|
|
|
|
var process = businessObject.processRef,
|
|
|
|
definitions;
|
|
|
|
|
|
|
|
if (process) {
|
|
|
|
definitions = getDefinitions(businessObject.$parent || newParent);
|
|
|
|
|
|
|
|
if (businessObject.$parent) {
|
2018-04-02 19:01:53 +00:00
|
|
|
collectionRemove(definitions.get('rootElements'), process);
|
2015-03-31 13:02:04 +00:00
|
|
|
process.$parent = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newParent) {
|
2018-04-02 19:01:53 +00:00
|
|
|
collectionAdd(definitions.get('rootElements'), process);
|
2015-03-31 13:02:04 +00:00
|
|
|
process.$parent = definitions;
|
|
|
|
}
|
|
|
|
}
|
2015-10-06 10:33:21 +00:00
|
|
|
} else
|
|
|
|
|
|
|
|
if (is(businessObject, 'bpmn:DataOutputAssociation')) {
|
|
|
|
containment = 'dataOutputAssociations';
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (is(businessObject, 'bpmn:DataInputAssociation')) {
|
|
|
|
containment = 'dataInputAssociations';
|
2015-03-31 13:02:04 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 07:36:15 +00:00
|
|
|
if (!containment) {
|
2016-02-25 16:40:56 +00:00
|
|
|
throw new Error(translate(
|
|
|
|
'no parent for {element} in {parent}',
|
|
|
|
{
|
|
|
|
element: businessObject.id,
|
|
|
|
parent: newParent.id
|
|
|
|
}
|
|
|
|
));
|
2014-12-02 07:36:15 +00:00
|
|
|
}
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
var children;
|
|
|
|
|
|
|
|
if (businessObject.$parent) {
|
|
|
|
// remove from old parent
|
2014-12-02 07:36:15 +00:00
|
|
|
children = businessObject.$parent.get(containment);
|
2018-04-02 19:01:53 +00:00
|
|
|
collectionRemove(children, businessObject);
|
2014-07-23 16:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!newParent) {
|
|
|
|
businessObject.$parent = null;
|
|
|
|
} else {
|
|
|
|
// add to new parent
|
2014-12-02 07:36:15 +00:00
|
|
|
children = newParent.get(containment);
|
2014-07-23 16:53:33 +00:00
|
|
|
children.push(businessObject);
|
|
|
|
businessObject.$parent = newParent;
|
|
|
|
}
|
2016-05-09 10:38:01 +00:00
|
|
|
|
|
|
|
if (visualParent) {
|
|
|
|
var diChildren = visualParent.get(containment);
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
collectionRemove(children, businessObject);
|
2016-05-09 10:38:01 +00:00
|
|
|
|
|
|
|
if (newParent) {
|
|
|
|
|
|
|
|
if (!diChildren) {
|
|
|
|
diChildren = [];
|
|
|
|
newParent.set(containment, diChildren);
|
|
|
|
}
|
2016-05-30 17:42:46 +00:00
|
|
|
|
2016-05-09 10:38:01 +00:00
|
|
|
diChildren.push(businessObject);
|
|
|
|
}
|
|
|
|
}
|
2014-07-23 16:53:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
BpmnUpdater.prototype.updateConnectionWaypoints = function(connection) {
|
|
|
|
connection.businessObject.di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-10-06 08:50:47 +00:00
|
|
|
BpmnUpdater.prototype.updateConnection = function(context) {
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-10-06 08:50:47 +00:00
|
|
|
var connection = context.connection,
|
|
|
|
businessObject = getBusinessObject(connection),
|
2015-07-20 11:33:51 +00:00
|
|
|
newSource = getBusinessObject(connection.source),
|
2016-05-09 10:38:01 +00:00
|
|
|
newTarget = getBusinessObject(connection.target),
|
|
|
|
visualParent;
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
if (!is(businessObject, 'bpmn:DataAssociation')) {
|
|
|
|
|
|
|
|
var inverseSet = is(businessObject, 'bpmn:SequenceFlow');
|
2014-08-05 11:57:32 +00:00
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
if (businessObject.sourceRef !== newSource) {
|
|
|
|
if (inverseSet) {
|
2018-04-02 19:01:53 +00:00
|
|
|
collectionRemove(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject);
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
if (newSource && newSource.get('outgoing')) {
|
|
|
|
newSource.get('outgoing').push(businessObject);
|
|
|
|
}
|
2014-08-05 15:57:19 +00:00
|
|
|
}
|
2015-10-06 10:33:21 +00:00
|
|
|
|
|
|
|
businessObject.sourceRef = newSource;
|
2014-07-23 16:53:33 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
if (businessObject.targetRef !== newTarget) {
|
|
|
|
if (inverseSet) {
|
2018-04-02 19:01:53 +00:00
|
|
|
collectionRemove(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject);
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
if (newTarget && newTarget.get('incoming')) {
|
|
|
|
newTarget.get('incoming').push(businessObject);
|
|
|
|
}
|
2014-08-05 15:57:19 +00:00
|
|
|
}
|
2015-10-06 10:33:21 +00:00
|
|
|
|
|
|
|
businessObject.targetRef = newTarget;
|
2014-07-23 16:53:33 +00:00
|
|
|
}
|
2015-10-06 10:33:21 +00:00
|
|
|
} else
|
|
|
|
|
|
|
|
if (is(businessObject, 'bpmn:DataInputAssociation')) {
|
2018-03-22 09:22:37 +00:00
|
|
|
// handle obnoxious isMsome sourceRef
|
2015-10-06 10:33:21 +00:00
|
|
|
businessObject.get('sourceRef')[0] = newSource;
|
|
|
|
|
2016-05-09 10:38:01 +00:00
|
|
|
visualParent = context.parent || context.newParent || newTarget;
|
|
|
|
|
|
|
|
this.updateSemanticParent(businessObject, newTarget, parent.businessObject);
|
2015-10-06 10:33:21 +00:00
|
|
|
} else
|
|
|
|
|
|
|
|
if (is(businessObject, 'bpmn:DataOutputAssociation')) {
|
2016-05-09 10:38:01 +00:00
|
|
|
visualParent = context.parent || context.newParent || newSource;
|
|
|
|
|
|
|
|
this.updateSemanticParent(businessObject, newSource, visualParent);
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-10-06 10:33:21 +00:00
|
|
|
// targetRef = new target
|
2014-07-23 16:53:33 +00:00
|
|
|
businessObject.targetRef = newTarget;
|
|
|
|
}
|
|
|
|
|
2015-10-21 14:25:56 +00:00
|
|
|
this.updateConnectionWaypoints(connection);
|
2016-10-28 15:42:42 +00:00
|
|
|
|
|
|
|
this.updateDiConnection(businessObject.di, newSource, newTarget);
|
2014-07-23 16:53:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// helpers //////////////////////
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2014-07-30 14:07:43 +00:00
|
|
|
BpmnUpdater.prototype._getLabel = function(di) {
|
|
|
|
if (!di.label) {
|
|
|
|
di.label = this._bpmnFactory.createDiLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
return di.label;
|
2015-07-20 11:33:51 +00:00
|
|
|
};
|
2015-09-02 13:13:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure the event listener is only called
|
|
|
|
* if the touched element is a BPMN element.
|
|
|
|
*
|
|
|
|
* @param {Function} fn
|
|
|
|
* @return {Function} guarded function
|
|
|
|
*/
|
|
|
|
function ifBpmn(fn) {
|
|
|
|
|
|
|
|
return function(event) {
|
|
|
|
|
|
|
|
var context = event.context,
|
|
|
|
element = context.shape || context.connection;
|
|
|
|
|
|
|
|
if (is(element, 'bpmn:BaseElement')) {
|
|
|
|
fn(event);
|
|
|
|
}
|
|
|
|
};
|
2015-10-06 08:50:47 +00:00
|
|
|
}
|