2014-07-23 16:53:33 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-04-27 14:50:09 +00:00
|
|
|
var assign = require('lodash/object/assign'),
|
2015-05-04 12:59:26 +00:00
|
|
|
forEach = require('lodash/collection/forEach'),
|
2015-04-27 14:50:09 +00:00
|
|
|
inherits = require('inherits');
|
2014-07-23 16:53:33 +00:00
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
var Collections = require('diagram-js/lib/util/Collections'),
|
|
|
|
Model = require('diagram-js/lib/model');
|
2014-11-27 10:55:38 +00:00
|
|
|
|
2015-07-20 11:33:51 +00:00
|
|
|
var getBusinessObject = require('../../util/ModelUtil').getBusinessObject,
|
|
|
|
is = require('../../util/ModelUtil').is;
|
|
|
|
|
2015-04-27 14:50:09 +00:00
|
|
|
var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor');
|
|
|
|
|
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
|
|
|
|
*/
|
2016-02-25 16:40:56 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
////// connection cropping /////////////////////////
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////// BPMN + DI update /////////////////////////
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-08-22 13:20:48 +00:00
|
|
|
this.executed([ 'shape.move',
|
|
|
|
'shape.create',
|
|
|
|
'shape.delete',
|
|
|
|
'connection.create',
|
2014-11-21 08:19:35 +00:00
|
|
|
'connection.move',
|
2015-09-02 13:13:18 +00:00
|
|
|
'connection.delete' ], ifBpmn(updateParent));
|
2015-08-31 12:59:29 +00:00
|
|
|
|
2014-08-22 13:20:48 +00:00
|
|
|
this.reverted([ 'shape.move',
|
|
|
|
'shape.create',
|
|
|
|
'shape.delete',
|
|
|
|
'connection.create',
|
2014-11-21 08:19:35 +00:00
|
|
|
'connection.move',
|
2015-09-02 13:13:18 +00:00
|
|
|
'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
|
|
|
}
|
|
|
|
|
2015-09-02 13:13:18 +00:00
|
|
|
this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], ifBpmn(updateBounds));
|
|
|
|
this.reverted([ 'shape.move', 'shape.create', 'shape.resize' ], ifBpmn(updateBounds));
|
2014-07-30 14:07:43 +00:00
|
|
|
|
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
|
|
|
|
if (oldSource && oldSource.default) {
|
|
|
|
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') ||
|
2016-05-06 13:52:20 +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') ||
|
|
|
|
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') ||
|
2016-05-06 13:52:20 +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);
|
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
module.exports = BpmnUpdater;
|
|
|
|
|
2016-02-25 16:40:56 +00:00
|
|
|
BpmnUpdater.$inject = [ 'eventBus', 'bpmnFactory', 'connectionDocking', 'translate' ];
|
2014-07-23 16:53:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
/////// implementation //////////////////////////////////
|
|
|
|
|
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
|
|
|
|
if (element instanceof Model.Label) {
|
|
|
|
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;
|
|
|
|
|
2014-11-27 10:55:38 +00:00
|
|
|
var bounds = (shape instanceof Model.Label) ? this._getLabel(di).bounds : di.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');
|
|
|
|
Collections.remove(oldRefs, businessObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is(newContainment, 'bpmn:Lane')) {
|
|
|
|
newRefs = newContainment.get('flowNodeRef');
|
|
|
|
Collections.add(newRefs, businessObject);
|
|
|
|
}
|
|
|
|
};
|
2014-07-30 14:06:32 +00:00
|
|
|
|
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 {
|
|
|
|
Collections.remove(planeElements, di);
|
|
|
|
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) {
|
|
|
|
Collections.remove(definitions.get('rootElements'), process);
|
|
|
|
process.$parent = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newParent) {
|
|
|
|
Collections.add(definitions.get('rootElements'), process);
|
|
|
|
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);
|
2014-07-23 16:53:33 +00:00
|
|
|
Collections.remove(children, businessObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
Collections.remove(children, businessObject);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
Collections.remove(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) {
|
|
|
|
Collections.remove(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')) {
|
|
|
|
// handle obnoxious isMany sourceRef
|
|
|
|
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);
|
2014-07-23 16:53:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/////// helpers /////////////////////////////////////////
|
|
|
|
|
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
|
|
|
}
|