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 {
|
|
|
|
roundBounds
|
|
|
|
} from 'diagram-js/lib/layout/LayoutUtil';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
hasPrimaryModifier
|
|
|
|
} from 'diagram-js/lib/util/Mouse';
|
2015-10-22 18:28:08 +00:00
|
|
|
|
2015-10-09 23:40:52 +00:00
|
|
|
var SLIGHTLY_HIGHER_PRIORITY = 1001;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoke {@link Modeling#resizeLane} instead of
|
|
|
|
* {@link Modeling#resizeShape} when resizing a Lane
|
|
|
|
* or Participant shape.
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function ResizeLaneBehavior(eventBus, modeling) {
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2015-10-22 18:35:34 +00:00
|
|
|
eventBus.on('resize.start', SLIGHTLY_HIGHER_PRIORITY + 500, function(event) {
|
|
|
|
var context = event.context,
|
|
|
|
shape = context.shape;
|
|
|
|
|
|
|
|
if (is(shape, 'bpmn:Lane') || is(shape, 'bpmn:Participant')) {
|
|
|
|
|
|
|
|
// should we resize the opposite lane(s) in
|
|
|
|
// order to compensate for the resize operation?
|
|
|
|
context.balanced = !hasPrimaryModifier(event);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-09 23:40:52 +00:00
|
|
|
/**
|
|
|
|
* Intercept resize end and call resize lane function instead.
|
|
|
|
*/
|
|
|
|
eventBus.on('resize.end', SLIGHTLY_HIGHER_PRIORITY, function(event) {
|
|
|
|
var context = event.context,
|
|
|
|
shape = context.shape,
|
|
|
|
canExecute = context.canExecute,
|
2015-10-22 18:35:34 +00:00
|
|
|
newBounds = context.newBounds;
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
if (is(shape, 'bpmn:Lane') || is(shape, 'bpmn:Participant')) {
|
|
|
|
|
|
|
|
if (canExecute) {
|
|
|
|
// ensure we have actual pixel values for new bounds
|
|
|
|
// (important when zoom level was > 1 during move)
|
|
|
|
newBounds = roundBounds(newBounds);
|
|
|
|
|
|
|
|
// perform the actual resize
|
2015-10-22 18:35:34 +00:00
|
|
|
modeling.resizeLane(shape, newBounds, context.balanced);
|
2015-10-09 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// stop propagation
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
ResizeLaneBehavior.$inject = [
|
|
|
|
'eventBus',
|
|
|
|
'modeling'
|
|
|
|
];
|