2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2016-04-04 14:11:34 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
|
|
|
|
|
|
|
import {
|
|
|
|
getBusinessObject,
|
|
|
|
is
|
|
|
|
} from '../../../util/ModelUtil';
|
2016-04-04 14:11:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A behavior that unsets the Default property of
|
|
|
|
* sequence flow source on element delete, if the
|
|
|
|
* removed element is the Gateway or Task's default flow.
|
|
|
|
*
|
|
|
|
* @param {EventBus} eventBus
|
|
|
|
* @param {Modeling} modeling
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function DeleteSequenceFlowBehavior(eventBus, modeling) {
|
2016-04-04 14:11:34 +00:00
|
|
|
|
|
|
|
CommandInterceptor.call(this, eventBus);
|
|
|
|
|
|
|
|
|
|
|
|
this.preExecute('connection.delete', function(event) {
|
|
|
|
var context = event.context,
|
|
|
|
connection = context.connection,
|
|
|
|
source = connection.source;
|
|
|
|
|
|
|
|
if (isDefaultFlow(connection, source)) {
|
|
|
|
modeling.updateProperties(source, {
|
|
|
|
'default': null
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(DeleteSequenceFlowBehavior, CommandInterceptor);
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
DeleteSequenceFlowBehavior.$inject = [
|
|
|
|
'eventBus',
|
|
|
|
'modeling'
|
|
|
|
];
|
2016-04-04 14:11:34 +00:00
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// helpers //////////////////////
|
2016-04-04 14:11:34 +00:00
|
|
|
|
|
|
|
function isDefaultFlow(connection, source) {
|
|
|
|
|
|
|
|
if (!is(connection, 'bpmn:SequenceFlow')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var sourceBo = getBusinessObject(source),
|
|
|
|
sequenceFlow = getBusinessObject(connection);
|
|
|
|
|
|
|
|
return sourceBo.get('default') === sequenceFlow;
|
|
|
|
}
|