2015-01-19 11:13:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
|
|
var LabelUtil = require('../label-editing/LabelUtil'),
|
|
|
|
BaseReplace = require('diagram-js/lib/features/replace/Replace');
|
|
|
|
|
2015-02-26 15:19:34 +00:00
|
|
|
function BpmnReplace(modeling, eventBus, moddle) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
BaseReplace.call(this, modeling);
|
|
|
|
|
|
|
|
this._originalReplaceElement = BaseReplace.prototype.replaceElement;
|
|
|
|
|
|
|
|
this._modeling = modeling;
|
|
|
|
|
|
|
|
eventBus.on([
|
2015-03-03 14:52:40 +00:00
|
|
|
'commandStack.shape.replace.execute'
|
2015-01-19 11:13:39 +00:00
|
|
|
], function(event) {
|
|
|
|
|
|
|
|
var context = event.context,
|
|
|
|
oldShape = context.oldShape,
|
2015-02-05 15:00:05 +00:00
|
|
|
newShape = context.newShape,
|
2015-02-26 15:19:34 +00:00
|
|
|
newBusinessAtt = context.options ? context.options.newBusinessAtt || {} : {},
|
|
|
|
eventDefinitionType = context.options ? context.options.eventDefinition : null;
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-02-26 15:19:34 +00:00
|
|
|
// Attach eventDefinitions
|
|
|
|
if (eventDefinitionType) {
|
|
|
|
var eventDefinitions = newShape.businessObject.get('eventDefinitions'),
|
|
|
|
newEventDefinition = moddle.create(eventDefinitionType);
|
|
|
|
|
|
|
|
eventDefinitions.push(newEventDefinition);
|
|
|
|
}
|
|
|
|
|
|
|
|
// extend newBusinessAtt
|
2015-02-05 15:00:05 +00:00
|
|
|
_.assign(newShape.businessObject, newBusinessAtt);
|
2015-02-26 15:19:34 +00:00
|
|
|
|
|
|
|
// set label
|
2015-01-19 11:13:39 +00:00
|
|
|
modeling.updateLabel(newShape, LabelUtil.getLabel(oldShape));
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO(nre): update bpmn specific properties based on our meta-model
|
|
|
|
// i.e. we should not only keep the name, but also
|
|
|
|
// other properties that exist in BOTH the old and new shape
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = BpmnReplace;
|
|
|
|
|
2015-02-26 15:19:34 +00:00
|
|
|
BpmnReplace.$inject = [ 'modeling', 'eventBus', 'moddle' ];
|
|
|
|
|
|
|
|
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
BpmnReplace.prototype = Object.create(BaseReplace.prototype);
|
|
|
|
|
2015-02-26 15:19:34 +00:00
|
|
|
BpmnReplace.prototype.replaceElement = function(oldElement, newElementData, options) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
|
|
|
if (oldElement.waypoints) {
|
|
|
|
throw new Error('connections cannot be replaced (yet)');
|
|
|
|
}
|
|
|
|
|
|
|
|
// use old elements size for activities
|
|
|
|
// TODO(nre): may also specify do this during the replace suggestions
|
|
|
|
// already (i.e. replace suggestions = { type, label, newElementData }) (?)
|
|
|
|
if (oldElement.businessObject.$instanceOf('bpmn:Activity')) {
|
|
|
|
|
|
|
|
// TODO need also to respect min/max Size
|
|
|
|
newElementData.width = oldElement.width;
|
|
|
|
newElementData.height = oldElement.height;
|
|
|
|
}
|
|
|
|
|
2015-02-26 15:19:34 +00:00
|
|
|
return this._originalReplaceElement(oldElement, newElementData, options || {});
|
2015-01-19 11:13:39 +00:00
|
|
|
};
|