2016-04-20 15:31:42 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ModelUtil = require('../../util/ModelUtil'),
|
|
|
|
getBusinessObject = ModelUtil.getBusinessObject,
|
|
|
|
is = ModelUtil.is;
|
|
|
|
|
|
|
|
var map = require('lodash/collection/map'),
|
|
|
|
forEach = require('lodash/collection/forEach');
|
|
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function BpmnCopyPaste(bpmnFactory, eventBus, copyPaste, clipboard, moddle, canvas, bpmnRules) {
|
|
|
|
|
|
|
|
copyPaste.registerDescriptor(function(element, descriptor) {
|
|
|
|
var businessObject = getBusinessObject(element),
|
|
|
|
conditionExpression,
|
|
|
|
eventDefinitions;
|
|
|
|
|
|
|
|
descriptor.type = element.type;
|
|
|
|
|
|
|
|
if (element.type === 'label') {
|
|
|
|
return descriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
setProperties(descriptor, businessObject, [
|
|
|
|
'name',
|
|
|
|
'text',
|
|
|
|
'processRef',
|
|
|
|
'isInterrupting',
|
|
|
|
'isForCompensation',
|
2016-06-14 09:06:51 +00:00
|
|
|
'associationDirection',
|
|
|
|
'triggeredByEvent',
|
|
|
|
'cancelActivity'
|
2016-04-20 15:31:42 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
if (businessObject.default) {
|
|
|
|
descriptor.default = businessObject.default.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (businessObject.loopCharacteristics) {
|
|
|
|
|
|
|
|
descriptor.loopCharacteristics = {
|
|
|
|
type: businessObject.loopCharacteristics.$type,
|
|
|
|
isSequential: businessObject.loopCharacteristics.isSequential
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
setProperties(descriptor, businessObject.di, [ 'isExpanded' ]);
|
|
|
|
|
|
|
|
if (is(businessObject, 'bpmn:SequenceFlow')) {
|
|
|
|
conditionExpression = businessObject.get('conditionExpression');
|
|
|
|
|
|
|
|
if (conditionExpression) {
|
|
|
|
descriptor.conditionExpression = {
|
|
|
|
type: conditionExpression.$type,
|
|
|
|
body: conditionExpression.body
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
eventDefinitions = businessObject.get('eventDefinitions') || [];
|
|
|
|
|
|
|
|
if (eventDefinitions.length) {
|
|
|
|
descriptor.eventDefinitions = map(eventDefinitions, function(defs) {
|
|
|
|
return defs.$type;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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(),
|
|
|
|
businessObject,
|
|
|
|
newEventDefinition,
|
|
|
|
conditionExpression,
|
|
|
|
loopCharacteristics,
|
|
|
|
source,
|
|
|
|
target,
|
|
|
|
canConnect;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
descriptor.businessObject = businessObject = bpmnFactory.create(descriptor.type);
|
|
|
|
|
2016-05-20 13:04:20 +00:00
|
|
|
if (descriptor.type === 'bpmn:Participant' && descriptor.processRef) {
|
|
|
|
descriptor.processRef = businessObject.processRef = bpmnFactory.create('bpmn:Process');
|
|
|
|
}
|
|
|
|
|
2016-04-20 15:31:42 +00:00
|
|
|
setProperties(businessObject, descriptor, [
|
|
|
|
'name',
|
2016-06-14 09:06:51 +00:00
|
|
|
'text',
|
|
|
|
'isExpanded',
|
|
|
|
'isInterrupting',
|
|
|
|
'cancelActivity',
|
|
|
|
'triggeredByEvent'
|
2016-04-20 15:31:42 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
if (descriptor.loopCharacteristics) {
|
|
|
|
loopCharacteristics = descriptor.loopCharacteristics;
|
|
|
|
|
|
|
|
businessObject.loopCharacteristics = moddle.create(loopCharacteristics.type);
|
|
|
|
|
|
|
|
if (loopCharacteristics.isSequential) {
|
|
|
|
businessObject.loopCharacteristics.isSequential = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
businessObject.loopCharacteristics.$parent = businessObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (descriptor.conditionExpression) {
|
|
|
|
conditionExpression = descriptor.conditionExpression;
|
|
|
|
|
|
|
|
businessObject.conditionExpression = moddle.create(conditionExpression.type, { body: conditionExpression.body });
|
|
|
|
|
|
|
|
businessObject.conditionExpression.$parent = businessObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (descriptor.eventDefinitions) {
|
|
|
|
businessObject.eventDefinitions = map(descriptor.eventDefinitions, function(type) {
|
|
|
|
newEventDefinition = moddle.create(type);
|
|
|
|
|
|
|
|
newEventDefinition.$parent = businessObject;
|
|
|
|
|
|
|
|
return newEventDefinition;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
removeProperties(descriptor, [
|
|
|
|
'name',
|
|
|
|
'text',
|
|
|
|
'eventDefinitions',
|
|
|
|
'conditionExpression',
|
2016-06-14 09:06:51 +00:00
|
|
|
'loopCharacteristics',
|
|
|
|
'isInterrupting',
|
|
|
|
'cancelActivity',
|
|
|
|
'triggeredByEvent'
|
2016-06-07 06:46:45 +00:00
|
|
|
]);
|
2016-04-20 15:31:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BpmnCopyPaste.$inject = [
|
|
|
|
'bpmnFactory',
|
|
|
|
'eventBus',
|
|
|
|
'copyPaste',
|
|
|
|
'clipboard',
|
|
|
|
'moddle',
|
|
|
|
'canvas',
|
|
|
|
'bpmnRules'
|
|
|
|
];
|
|
|
|
|
2016-06-14 09:06:51 +00:00
|
|
|
module.exports = BpmnCopyPaste;
|