2019-05-16 14:55:38 +00:00
|
|
|
import inherits from 'inherits';
|
|
|
|
|
|
|
|
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
|
|
|
|
|
|
|
import { is } from '../../../util/ModelUtil';
|
|
|
|
import { isExpanded } from '../../../util/DiUtil.js';
|
|
|
|
|
|
|
|
/**
|
2019-08-06 16:57:30 +00:00
|
|
|
* Add start event replacing element with expanded sub process.
|
|
|
|
*
|
|
|
|
* @param {Injector} injector
|
|
|
|
* @param {Modeling} modeling
|
2019-05-16 14:55:38 +00:00
|
|
|
*/
|
2019-08-06 16:57:30 +00:00
|
|
|
export default function SubProcessStartEventBehavior(injector, modeling) {
|
|
|
|
injector.invoke(CommandInterceptor, this);
|
2019-05-16 14:55:38 +00:00
|
|
|
|
|
|
|
this.postExecuted('shape.replace', function(event) {
|
|
|
|
var oldShape = event.context.oldShape,
|
2019-08-06 16:57:30 +00:00
|
|
|
newShape = event.context.newShape;
|
2019-05-16 14:55:38 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
!is(newShape, 'bpmn:SubProcess') ||
|
|
|
|
!is(oldShape, 'bpmn:Task') ||
|
|
|
|
!isExpanded(newShape)
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
var position = getStartEventPosition(newShape);
|
2019-05-16 14:55:38 +00:00
|
|
|
|
|
|
|
modeling.createShape({ type: 'bpmn:StartEvent' }, position, newShape);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
SubProcessStartEventBehavior.$inject = [
|
2019-08-06 16:57:30 +00:00
|
|
|
'injector',
|
2019-05-16 14:55:38 +00:00
|
|
|
'modeling'
|
|
|
|
];
|
|
|
|
|
|
|
|
inherits(SubProcessStartEventBehavior, CommandInterceptor);
|
|
|
|
|
|
|
|
// helpers //////////
|
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
function getStartEventPosition(shape) {
|
2019-05-16 14:55:38 +00:00
|
|
|
return {
|
|
|
|
x: shape.x + shape.width / 6,
|
|
|
|
y: shape.y + shape.height / 2
|
|
|
|
};
|
|
|
|
}
|