2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
getBusinessObject,
|
|
|
|
is
|
|
|
|
} from '../../util/ModelUtil';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import ModelCloneHelper from '../../util/model/ModelCloneHelper';
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
getProperties,
|
|
|
|
IGNORED_PROPERTIES
|
|
|
|
} from '../../util/model/ModelCloneUtils';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
filter,
|
|
|
|
forEach
|
|
|
|
} from 'min-dash';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
function setProperties(descriptor, data, properties) {
|
|
|
|
forEach(properties, function(property) {
|
2016-06-14 09:06:51 +00:00
|
|
|
if (data[property] !== undefined) {
|
2016-04-20 15:31:42 +00:00
|
|
|
descriptor[property] = data[property];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeProperties(element, properties) {
|
|
|
|
forEach(properties, function(prop) {
|
|
|
|
if (element[prop]) {
|
|
|
|
delete element[prop];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function BpmnCopyPaste(
|
2017-05-19 10:55:46 +00:00
|
|
|
bpmnFactory, eventBus, copyPaste,
|
|
|
|
clipboard, canvas, bpmnRules) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
var helper = new ModelCloneHelper(eventBus, bpmnFactory);
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
copyPaste.registerDescriptor(function(element, descriptor) {
|
2017-06-20 13:51:19 +00:00
|
|
|
var businessObject = descriptor.oldBusinessObject = getBusinessObject(element);
|
2017-01-19 15:16:56 +00:00
|
|
|
|
2017-06-20 13:51:19 +00:00
|
|
|
var colors = {};
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
descriptor.type = element.type;
|
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
setProperties(descriptor, businessObject.di, [ 'isExpanded' ]);
|
|
|
|
|
2017-02-03 10:03:50 +00:00
|
|
|
setProperties(colors, businessObject.di, [ 'fill', 'stroke' ]);
|
|
|
|
|
|
|
|
descriptor.colors = colors;
|
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
if (element.type === 'label') {
|
|
|
|
return descriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
setProperties(descriptor, businessObject, [
|
|
|
|
'processRef',
|
2017-01-19 15:16:56 +00:00
|
|
|
'triggeredByEvent'
|
2016-04-20 15:31:42 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
if (businessObject.default) {
|
|
|
|
descriptor.default = businessObject.default.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return descriptor;
|
|
|
|
});
|
|
|
|
|
|
|
|
eventBus.on('element.paste', function(context) {
|
|
|
|
var descriptor = context.descriptor,
|
|
|
|
createdElements = context.createdElements,
|
|
|
|
parent = descriptor.parent,
|
2016-05-20 10:40:15 +00:00
|
|
|
rootElement = canvas.getRootElement(),
|
2017-06-20 13:51:19 +00:00
|
|
|
oldBusinessObject = descriptor.oldBusinessObject,
|
|
|
|
newBusinessObject,
|
2016-05-20 10:40:15 +00:00
|
|
|
source,
|
|
|
|
target,
|
|
|
|
canConnect;
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2017-06-20 13:51:19 +00:00
|
|
|
newBusinessObject = bpmnFactory.create(oldBusinessObject.$type);
|
|
|
|
|
|
|
|
var properties = getProperties(oldBusinessObject.$descriptor);
|
|
|
|
|
|
|
|
properties = filter(properties, function(property) {
|
|
|
|
return IGNORED_PROPERTIES.indexOf(property.replace(/bpmn:/, '')) === -1;
|
|
|
|
});
|
|
|
|
|
|
|
|
descriptor.businessObject = helper.clone(oldBusinessObject, newBusinessObject, properties);
|
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
if (descriptor.type === 'label') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is(parent, 'bpmn:Process')) {
|
|
|
|
descriptor.parent = is(rootElement, 'bpmn:Collaboration') ? rootElement : parent;
|
2016-04-26 12:02:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 10:40:15 +00:00
|
|
|
if (descriptor.type === 'bpmn:DataOutputAssociation' ||
|
|
|
|
descriptor.type === 'bpmn:DataInputAssociation' ||
|
|
|
|
descriptor.type === 'bpmn:MessageFlow') {
|
|
|
|
descriptor.parent = rootElement;
|
2016-04-20 15:31:42 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 10:40:15 +00:00
|
|
|
if (is(parent, 'bpmn:Lane')) {
|
|
|
|
descriptor.parent = parent.parent;
|
2016-04-20 15:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure that the correct type of connection is created
|
|
|
|
if (descriptor.waypoints) {
|
|
|
|
source = createdElements[descriptor.source];
|
|
|
|
target = createdElements[descriptor.target];
|
|
|
|
|
|
|
|
if (source && target) {
|
|
|
|
source = source.element;
|
|
|
|
target = target.element;
|
|
|
|
}
|
|
|
|
|
|
|
|
canConnect = bpmnRules.canConnect(source, target);
|
|
|
|
|
|
|
|
if (canConnect) {
|
|
|
|
descriptor.type = canConnect.type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
// remove the id or else we cannot paste multiple times
|
2017-06-20 13:51:19 +00:00
|
|
|
delete newBusinessObject.id;
|
2017-01-19 15:16:56 +00:00
|
|
|
|
|
|
|
// assign an ID
|
2017-06-20 13:51:19 +00:00
|
|
|
bpmnFactory._ensureId(newBusinessObject);
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2016-05-20 13:04:20 +00:00
|
|
|
if (descriptor.type === 'bpmn:Participant' && descriptor.processRef) {
|
2017-06-20 13:51:19 +00:00
|
|
|
descriptor.processRef = newBusinessObject.processRef = bpmnFactory.create('bpmn:Process');
|
2016-05-20 13:04:20 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 13:51:19 +00:00
|
|
|
setProperties(newBusinessObject, descriptor, [
|
2016-06-14 09:06:51 +00:00
|
|
|
'isExpanded',
|
|
|
|
'triggeredByEvent'
|
2016-04-20 15:31:42 +00:00
|
|
|
]);
|
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
removeProperties(descriptor, [
|
2016-06-14 09:06:51 +00:00
|
|
|
'triggeredByEvent'
|
2016-06-07 06:46:45 +00:00
|
|
|
]);
|
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',
|
|
|
|
'copyPaste',
|
|
|
|
'clipboard',
|
|
|
|
'canvas',
|
|
|
|
'bpmnRules'
|
2018-04-02 19:01:53 +00:00
|
|
|
];
|