2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import { is } from '../../../util/ModelUtil';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
getChildLanes
|
|
|
|
} from '../util/LaneUtil';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
eachElement
|
|
|
|
} from 'diagram-js/lib/util/Elements';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function DeleteLaneBehavior(eventBus, modeling, spaceTool) {
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
DeleteLaneBehavior.$inject = [
|
|
|
|
'eventBus',
|
|
|
|
'modeling',
|
|
|
|
'spaceTool'
|
|
|
|
];
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
inherits(DeleteLaneBehavior, CommandInterceptor);
|