2015-01-19 11:13:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-12-10 11:48:40 +00:00
|
|
|
var pick = require('lodash/object/pick'),
|
2016-06-16 11:57:32 +00:00
|
|
|
assign = require('lodash/object/assign'),
|
|
|
|
has = require('lodash/object/has');
|
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
|
|
|
];
|
|
|
|
|
2016-06-16 11:57:32 +00:00
|
|
|
function toggeling(element, target) {
|
|
|
|
|
|
|
|
var oldCollapsed = has(element, 'collapsed') ?
|
|
|
|
element.collapsed : !isExpanded(element);
|
|
|
|
|
|
|
|
var targetCollapsed;
|
|
|
|
|
|
|
|
if (has(target, 'collapsed') || has(target, 'isExpanded')) {
|
|
|
|
// property is explicitly set so use it
|
|
|
|
targetCollapsed = has(target, 'collapsed') ?
|
|
|
|
target.collapsed : !target.isExpanded;
|
|
|
|
} else {
|
|
|
|
// keep old state
|
|
|
|
targetCollapsed = oldCollapsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldCollapsed !== targetCollapsed) {
|
|
|
|
element.collapsed = oldCollapsed;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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,
|
2016-06-16 11:57:32 +00:00
|
|
|
oldBusinessObject = element.businessObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is(oldBusinessObject, 'bpmn:SubProcess')) {
|
|
|
|
if (type === 'bpmn:SubProcess') {
|
|
|
|
if (toggeling(element, target)) {
|
|
|
|
// expanding or collapsing process
|
|
|
|
modeling.toggleCollapse(element);
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var 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:Activity')) {
|
|
|
|
|
2016-06-16 11:57:32 +00:00
|
|
|
if (is(oldBusinessObject, 'bpmn:SubProcess')) {
|
|
|
|
// no toggeling, so keep old state
|
|
|
|
newElement.isExpanded = isExpanded(oldBusinessObject);
|
|
|
|
}
|
|
|
|
// else if property is explicitly set, use it
|
|
|
|
else if (has(target, 'isExpanded')) {
|
|
|
|
newElement.isExpanded = target.isExpanded;
|
2016-04-13 15:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2016-06-07 06:46:45 +00:00
|
|
|
if (target.isExpanded === true) {
|
|
|
|
newBusinessObject.processRef = bpmnFactory.create('bpmn:Process');
|
|
|
|
} else {
|
2016-03-08 16:21:41 +00:00
|
|
|
// remove children when transforming to collapsed pool
|
2016-06-07 06:46:45 +00:00
|
|
|
hints.moveChildren = false;
|
|
|
|
}
|
2016-03-08 16:21:41 +00:00
|
|
|
|
|
|
|
// apply same size
|
2016-06-07 06:46:45 +00:00
|
|
|
newElement.width = element.width;
|
|
|
|
newElement.height = element.height;
|
2016-03-08 16:21:41 +00:00
|
|
|
}
|
|
|
|
|
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;
|