2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
getBusinessObject,
|
2021-08-06 08:45:10 +00:00
|
|
|
getDi,
|
2018-04-02 19:01:53 +00:00
|
|
|
is
|
|
|
|
} from '../../util/ModelUtil';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
2019-08-07 13:17:28 +00:00
|
|
|
forEach,
|
|
|
|
isArray,
|
|
|
|
isUndefined,
|
|
|
|
omit,
|
|
|
|
reduce
|
2018-04-02 19:01:53 +00:00
|
|
|
} from 'min-dash';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
function copyProperties(source, target, properties) {
|
|
|
|
if (!isArray(properties)) {
|
|
|
|
properties = [ properties ];
|
|
|
|
}
|
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
forEach(properties, function(property) {
|
2019-08-07 13:17:28 +00:00
|
|
|
if (!isUndefined(source[property])) {
|
|
|
|
target[property] = source[property];
|
2016-04-20 15:31:42 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeProperties(element, properties) {
|
2019-08-07 13:17:28 +00:00
|
|
|
if (!isArray(properties)) {
|
|
|
|
properties = [ properties ];
|
|
|
|
}
|
|
|
|
|
|
|
|
forEach(properties, function(property) {
|
|
|
|
if (element[property]) {
|
|
|
|
delete element[property];
|
2016-04-20 15:31:42 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var LOW_PRIORITY = 750;
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
export default function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) {
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
eventBus.on('copyPaste.copyElement', LOW_PRIORITY, function(context) {
|
|
|
|
var descriptor = context.descriptor,
|
|
|
|
element = context.element;
|
|
|
|
|
|
|
|
var businessObject = descriptor.oldBusinessObject = getBusinessObject(element);
|
2021-08-06 08:45:10 +00:00
|
|
|
var di = descriptor.oldDi = getDi(element);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
descriptor.type = element.type;
|
|
|
|
|
2019-08-07 18:32:47 +00:00
|
|
|
copyProperties(businessObject, descriptor, 'name');
|
|
|
|
|
2021-08-06 08:45:10 +00:00
|
|
|
copyProperties(di, descriptor, 'isExpanded');
|
2017-02-03 10:03:50 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
if (isLabel(descriptor)) {
|
2016-04-20 15:31:42 +00:00
|
|
|
return descriptor;
|
|
|
|
}
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// default sequence flow
|
2016-04-20 15:31:42 +00:00
|
|
|
if (businessObject.default) {
|
|
|
|
descriptor.default = businessObject.default.id;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
eventBus.on('moddleCopy.canCopyProperty', function(context) {
|
|
|
|
var parent = context.parent,
|
|
|
|
property = context.property,
|
2019-09-05 19:37:41 +00:00
|
|
|
propertyName = context.propertyName,
|
|
|
|
bpmnProcess;
|
|
|
|
|
|
|
|
if (
|
|
|
|
propertyName === 'processRef' &&
|
|
|
|
is(parent, 'bpmn:Participant') &&
|
|
|
|
is(property, 'bpmn:Process')
|
|
|
|
) {
|
|
|
|
bpmnProcess = bpmnFactory.create('bpmn:Process');
|
|
|
|
|
|
|
|
// return copy of process
|
|
|
|
return moddleCopy.copyElement(property, bpmnProcess);
|
2019-08-07 13:17:28 +00:00
|
|
|
}
|
|
|
|
});
|
2017-06-20 13:51:19 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
var references;
|
2017-06-20 13:51:19 +00:00
|
|
|
|
2019-09-20 14:12:59 +00:00
|
|
|
function resolveReferences(descriptor, cache) {
|
2019-08-07 13:17:28 +00:00
|
|
|
var businessObject = getBusinessObject(descriptor);
|
2017-06-20 13:51:19 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// default sequence flows
|
|
|
|
if (descriptor.default) {
|
2019-09-20 14:12:59 +00:00
|
|
|
|
|
|
|
// relationship cannot be resolved immediately
|
2019-08-07 13:17:28 +00:00
|
|
|
references[ descriptor.default ] = {
|
|
|
|
element: businessObject,
|
|
|
|
property: 'default'
|
|
|
|
};
|
2016-04-20 15:31:42 +00:00
|
|
|
}
|
|
|
|
|
2019-09-20 14:12:59 +00:00
|
|
|
// boundary events
|
|
|
|
if (descriptor.host) {
|
|
|
|
|
|
|
|
// relationship can be resolved immediately
|
|
|
|
getBusinessObject(descriptor).attachedToRef = getBusinessObject(cache[ descriptor.host ]);
|
|
|
|
}
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
references = omit(references, reduce(references, function(array, reference, key) {
|
|
|
|
var element = reference.element,
|
|
|
|
property = reference.property;
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
if (key === descriptor.id) {
|
|
|
|
element[ property ] = businessObject;
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
array.push(descriptor.id);
|
|
|
|
}
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
return array;
|
|
|
|
}, []));
|
|
|
|
}
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
eventBus.on('copyPaste.pasteElements', function() {
|
|
|
|
references = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
eventBus.on('copyPaste.pasteElement', function(context) {
|
|
|
|
var cache = context.cache,
|
|
|
|
descriptor = context.descriptor,
|
|
|
|
oldBusinessObject = descriptor.oldBusinessObject,
|
2021-08-06 08:45:10 +00:00
|
|
|
oldDi = descriptor.oldDi,
|
|
|
|
newBusinessObject, newDi;
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// do NOT copy business object if external label
|
|
|
|
if (isLabel(descriptor)) {
|
|
|
|
descriptor.businessObject = getBusinessObject(cache[ descriptor.labelTarget ]);
|
2021-08-06 08:45:10 +00:00
|
|
|
descriptor.di = getDi(cache[ descriptor.labelTarget ]);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
return;
|
2016-04-20 15:31:42 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
newBusinessObject = bpmnFactory.create(oldBusinessObject.$type);
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
descriptor.businessObject = moddleCopy.copyElement(
|
|
|
|
oldBusinessObject,
|
|
|
|
newBusinessObject
|
|
|
|
);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2021-08-06 08:45:10 +00:00
|
|
|
newDi = bpmnFactory.create(oldDi.$type);
|
|
|
|
|
|
|
|
descriptor.di = moddleCopy.copyElement(
|
|
|
|
oldDi,
|
|
|
|
newDi
|
|
|
|
);
|
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
// resolve references e.g. default sequence flow
|
2019-09-20 14:12:59 +00:00
|
|
|
resolveReferences(descriptor, cache);
|
2016-05-20 13:04:20 +00:00
|
|
|
|
2019-08-07 18:32:47 +00:00
|
|
|
copyProperties(descriptor, newBusinessObject, [
|
|
|
|
'isExpanded',
|
|
|
|
'name'
|
|
|
|
]);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2019-08-07 13:17:28 +00:00
|
|
|
removeProperties(descriptor, 'oldBusinessObject');
|
2016-04-20 15:31:42 +00:00
|
|
|
});
|
2017-05-19 10:55:46 +00:00
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BpmnCopyPaste.$inject = [
|
|
|
|
'bpmnFactory',
|
|
|
|
'eventBus',
|
2019-08-07 13:17:28 +00:00
|
|
|
'moddleCopy'
|
|
|
|
];
|
|
|
|
|
|
|
|
// helpers //////////
|
|
|
|
|
|
|
|
function isLabel(element) {
|
|
|
|
return !!element.labelTarget;
|
2019-09-20 14:12:59 +00:00
|
|
|
}
|