2015-10-09 23:40:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var inherits = require('inherits');
|
|
|
|
|
|
|
|
var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor');
|
|
|
|
|
|
|
|
var is = require('../../../util/ModelUtil').is;
|
|
|
|
|
|
|
|
var getChildLanes = require('../util/LaneUtil').getChildLanes;
|
|
|
|
|
|
|
|
var eachElement = require('diagram-js/lib/util/Elements').eachElement;
|
|
|
|
|
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
var LOW_PRIORITY = 500;
|
|
|
|
|
|
|
|
|
2015-10-09 23:40:52 +00:00
|
|
|
/**
|
|
|
|
* BPMN specific delete lane behavior
|
|
|
|
*/
|
|
|
|
function DeleteLaneBehavior(eventBus, modeling, spaceTool) {
|
|
|
|
|
|
|
|
CommandInterceptor.call(this, eventBus);
|
|
|
|
|
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
function compensateLaneDelete(shape, oldParent) {
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
var siblings = getChildLanes(oldParent);
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
var topAffected = [];
|
|
|
|
var bottomAffected = [];
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
eachElement(siblings, function(element) {
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
if (element.y > shape.y) {
|
|
|
|
bottomAffected.push(element);
|
|
|
|
} else {
|
|
|
|
topAffected.push(element);
|
|
|
|
}
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
return element.children;
|
|
|
|
});
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
if (!siblings.length) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
var offset;
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
if (bottomAffected.length && topAffected.length) {
|
|
|
|
offset = shape.height / 2;
|
|
|
|
} else {
|
|
|
|
offset = shape.height;
|
|
|
|
}
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
var topAdjustments,
|
|
|
|
bottomAdjustments;
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
if (topAffected.length) {
|
|
|
|
topAdjustments = spaceTool.calculateAdjustments(
|
|
|
|
topAffected, 'y', offset, shape.y - 10);
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
spaceTool.makeSpace(
|
|
|
|
topAdjustments.movingShapes,
|
|
|
|
topAdjustments.resizingShapes,
|
|
|
|
{ x: 0, y: offset }, 's');
|
|
|
|
}
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
if (bottomAffected.length) {
|
|
|
|
bottomAdjustments = spaceTool.calculateAdjustments(
|
|
|
|
bottomAffected, 'y', -offset, shape.y + shape.height + 10);
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-15 21:50:15 +00:00
|
|
|
spaceTool.makeSpace(
|
|
|
|
bottomAdjustments.movingShapes,
|
|
|
|
bottomAdjustments.resizingShapes,
|
|
|
|
{ x: 0, y: -offset }, 'n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adjust sizes of other lanes after lane deletion
|
|
|
|
*/
|
|
|
|
this.postExecuted('shape.delete', LOW_PRIORITY, function(event) {
|
|
|
|
|
|
|
|
var context = event.context,
|
|
|
|
hints = context.hints,
|
|
|
|
shape = context.shape,
|
|
|
|
oldParent = context.oldParent;
|
|
|
|
|
|
|
|
// only compensate lane deletes
|
|
|
|
if (!is(shape, 'bpmn:Lane')) {
|
|
|
|
return;
|
2015-10-09 23:40:52 +00:00
|
|
|
}
|
2015-10-15 21:50:15 +00:00
|
|
|
|
|
|
|
// compensate root deletes only
|
|
|
|
if (hints && hints.nested) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
compensateLaneDelete(shape, oldParent);
|
|
|
|
});
|
2015-10-09 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DeleteLaneBehavior.$inject = [ 'eventBus', 'modeling', 'spaceTool' ];
|
|
|
|
|
|
|
|
inherits(DeleteLaneBehavior, CommandInterceptor);
|
|
|
|
|
|
|
|
module.exports = DeleteLaneBehavior;
|