2015-01-19 11:13:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-12-10 11:48:40 +00:00
|
|
|
var pick = require('lodash/object/pick'),
|
2015-07-23 11:59:47 +00:00
|
|
|
assign = require('lodash/object/assign');
|
2015-03-11 15:17:19 +00:00
|
|
|
|
2015-06-12 13:46:28 +00:00
|
|
|
var is = require('../../util/ModelUtil').is,
|
2015-08-04 15:52:43 +00:00
|
|
|
isExpanded = require('../../util/DiUtil').isExpanded,
|
|
|
|
isEventSubProcess = require('../../util/DiUtil').isEventSubProcess;
|
|
|
|
|
2015-07-23 11:59:47 +00:00
|
|
|
var CUSTOM_PROPERTIES = [
|
|
|
|
'cancelActivity',
|
|
|
|
'instantiate',
|
2015-08-04 15:52:43 +00:00
|
|
|
'eventGatewayType',
|
|
|
|
'triggeredByEvent',
|
|
|
|
'isInterrupting'
|
2015-07-23 11:59:47 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
/**
|
2015-12-10 11:48:40 +00:00
|
|
|
* This module takes care of replacing BPMN elements
|
2015-03-11 15:17:19 +00:00
|
|
|
*/
|
2015-12-10 11:48:40 +00:00
|
|
|
function BpmnReplace(bpmnFactory, replace, selection, modeling) {
|
2015-03-11 15:17:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares a new business object for the replacement element
|
|
|
|
* and triggers the replace operation.
|
|
|
|
*
|
|
|
|
* @param {djs.model.Base} element
|
|
|
|
* @param {Object} target
|
2015-08-20 15:52:49 +00:00
|
|
|
* @param {Object} [hints]
|
2015-12-10 11:48:40 +00:00
|
|
|
*
|
2015-03-11 15:17:19 +00:00
|
|
|
* @return {djs.model.Base} the newly created element
|
|
|
|
*/
|
2015-08-20 15:52:49 +00:00
|
|
|
function replaceElement(element, target, hints) {
|
|
|
|
|
|
|
|
hints = hints || {};
|
2015-03-11 15:17:19 +00:00
|
|
|
|
|
|
|
var type = target.type,
|
|
|
|
oldBusinessObject = element.businessObject,
|
2016-01-20 10:31:01 +00:00
|
|
|
newBusinessObject = bpmnFactory.create(type);
|
2015-03-11 15:17:19 +00:00
|
|
|
|
|
|
|
var newElement = {
|
|
|
|
type: type,
|
2016-01-20 10:31:01 +00:00
|
|
|
businessObject: newBusinessObject
|
2015-03-11 15:17:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// initialize custom BPMN extensions
|
2016-01-20 10:31:01 +00:00
|
|
|
if (target.eventDefinitionType) {
|
|
|
|
newElement.eventDefinitionType = target.eventDefinitionType;
|
2015-03-11 15:17:19 +00:00
|
|
|
}
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-07-23 11:59:47 +00:00
|
|
|
// initialize special properties defined in target definition
|
2016-01-20 10:31:01 +00:00
|
|
|
assign(newBusinessObject, pick(target, CUSTOM_PROPERTIES));
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2016-04-13 15:13:10 +00:00
|
|
|
if (is(oldBusinessObject, 'bpmn:SubProcess')) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2016-04-13 15:13:10 +00:00
|
|
|
newElement.isExpanded = isExpanded(oldBusinessObject);
|
|
|
|
}
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2016-04-13 15:13:10 +00:00
|
|
|
// preserve adhoc state while switching collapsed/expanded subprocess
|
|
|
|
if (is(oldBusinessObject, 'bpmn:AdHocSubProcess') && target.isExpanded) {
|
|
|
|
newElement.businessObject = bpmnFactory.create('bpmn:AdHocSubProcess');
|
2015-03-11 15:17:19 +00:00
|
|
|
}
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2016-04-13 15:13:10 +00:00
|
|
|
if (is(oldBusinessObject, 'bpmn:Activity')) {
|
|
|
|
|
|
|
|
// switch collapsed/expanded subprocesses
|
|
|
|
if (target.isExpanded === true) {
|
|
|
|
newElement.isExpanded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: need also to respect min/max Size
|
|
|
|
// copy size, from an expanded subprocess to an expanded alternative subprocess
|
|
|
|
// except bpmn:Task, because Task is always expanded
|
|
|
|
if ((isExpanded(oldBusinessObject) && !is(oldBusinessObject, 'bpmn:Task')) && target.isExpanded) {
|
|
|
|
newElement.width = element.width;
|
|
|
|
newElement.height = element.height;
|
|
|
|
}
|
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 16:21:41 +00:00
|
|
|
// transform collapsed/expanded pools
|
|
|
|
if (is(oldBusinessObject, 'bpmn:Participant')) {
|
|
|
|
|
|
|
|
// create expanded pool
|
|
|
|
if (target.isExpanded === true) {
|
|
|
|
newBusinessObject.processRef = bpmnFactory.create('bpmn:Process');
|
|
|
|
} else {
|
|
|
|
// remove children when transforming to collapsed pool
|
|
|
|
hints.moveChildren = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply same size
|
|
|
|
newElement.width = element.width;
|
|
|
|
newElement.height = element.height;
|
|
|
|
}
|
|
|
|
|
2016-01-20 10:31:01 +00:00
|
|
|
newBusinessObject.name = oldBusinessObject.name;
|
2015-08-04 15:52:43 +00:00
|
|
|
|
|
|
|
// retain loop characteristics if the target element is not an event sub process
|
2016-01-20 10:31:01 +00:00
|
|
|
if (!isEventSubProcess(newBusinessObject)) {
|
|
|
|
newBusinessObject.loopCharacteristics = oldBusinessObject.loopCharacteristics;
|
2015-08-04 15:52:43 +00:00
|
|
|
}
|
2015-06-23 15:24:13 +00:00
|
|
|
|
2016-01-07 08:03:20 +00:00
|
|
|
// retain default flow's reference between inclusive <-> exclusive gateways and activities
|
|
|
|
if ((is(oldBusinessObject, 'bpmn:ExclusiveGateway') || is(oldBusinessObject, 'bpmn:InclusiveGateway') ||
|
|
|
|
is(oldBusinessObject, 'bpmn:Activity')) &&
|
2016-01-20 10:31:01 +00:00
|
|
|
(is(newBusinessObject, 'bpmn:ExclusiveGateway') || is(newBusinessObject, 'bpmn:InclusiveGateway') ||
|
|
|
|
is(newBusinessObject, 'bpmn:Activity')))
|
2015-10-06 08:50:47 +00:00
|
|
|
{
|
2016-01-20 10:31:01 +00:00
|
|
|
newBusinessObject.default = oldBusinessObject.default;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldBusinessObject.isForCompensation) {
|
|
|
|
newBusinessObject.isForCompensation = true;
|
2015-10-06 08:50:47 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 16:21:41 +00:00
|
|
|
newElement = replace.replaceElement(element, newElement, hints);
|
2015-03-11 15:31:42 +00:00
|
|
|
|
2015-08-20 15:52:49 +00:00
|
|
|
if (hints.select !== false) {
|
|
|
|
selection.select(newElement);
|
|
|
|
}
|
2015-03-11 15:31:42 +00:00
|
|
|
|
|
|
|
return newElement;
|
2015-03-11 15:17:19 +00:00
|
|
|
}
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
this.replaceElement = replaceElement;
|
|
|
|
}
|
|
|
|
|
2015-12-10 11:48:40 +00:00
|
|
|
BpmnReplace.$inject = [ 'bpmnFactory', 'replace', 'selection', 'modeling' ];
|
2015-03-11 15:17:19 +00:00
|
|
|
|
2015-06-12 13:46:28 +00:00
|
|
|
module.exports = BpmnReplace;
|