2016-04-20 15:31:42 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ModelUtil = require('../../util/ModelUtil'),
|
|
|
|
getBusinessObject = ModelUtil.getBusinessObject,
|
|
|
|
is = ModelUtil.is;
|
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
var ModelCloneHelper = require('../../util/model/ModelCloneHelper');
|
|
|
|
|
|
|
|
var ModelCloneUtils = require('../../util/model/ModelCloneUtils'),
|
|
|
|
getProperties = ModelCloneUtils.getProperties;
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2017-01-19 15:16:56 +00:00
|
|
|
var IGNORED_PROPERTIES = ModelCloneUtils.IGNORED_PROPERTIES;
|
|
|
|
|
|
|
|
var filter = require('lodash/collection/filter'),
|
|
|
|
forEach = require('lodash/collection/forEach');
|
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];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-19 10:55:46 +00:00
|
|
|
function BpmnCopyPaste(
|
|
|
|
bpmnFactory, eventBus, copyPaste,
|
|
|
|
clipboard, canvas, bpmnRules) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2017-01-23 13:12:43 +00:00
|
|
|
var helper = new ModelCloneHelper(eventBus);
|
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, [
|
2017-01-19 15:16:56 +00:00
|
|
|
'type',
|
2016-04-20 15:31:42 +00:00
|
|
|
'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'
|
|
|
|
];
|
|
|
|
|
2016-06-14 09:06:51 +00:00
|
|
|
module.exports = BpmnCopyPaste;
|