2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2015-03-31 13:02:04 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
2015-03-31 13:02:04 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import { is } from '../../../util/ModelUtil';
|
2015-04-27 14:50:09 +00:00
|
|
|
|
|
|
|
|
2015-03-31 13:02:04 +00:00
|
|
|
/**
|
|
|
|
* BPMN specific remove behavior
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function RemoveParticipantBehavior(eventBus, modeling) {
|
2015-03-31 13:02:04 +00:00
|
|
|
|
|
|
|
CommandInterceptor.call(this, eventBus);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* morph collaboration diagram into process diagram
|
|
|
|
* after the last participant has been removed
|
|
|
|
*/
|
|
|
|
|
|
|
|
this.preExecute('shape.delete', function(context) {
|
|
|
|
|
|
|
|
var shape = context.shape,
|
|
|
|
parent = shape.parent;
|
|
|
|
|
|
|
|
// activate the behavior if the shape to be removed
|
|
|
|
// is a participant
|
2015-04-27 14:50:09 +00:00
|
|
|
if (is(shape, 'bpmn:Participant')) {
|
2015-03-31 13:02:04 +00:00
|
|
|
context.collaborationRoot = parent;
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
this.postExecute('shape.delete', function(context) {
|
|
|
|
|
|
|
|
var collaborationRoot = context.collaborationRoot;
|
|
|
|
|
2015-04-28 08:52:21 +00:00
|
|
|
if (collaborationRoot && !collaborationRoot.businessObject.participants.length) {
|
2015-03-31 13:02:04 +00:00
|
|
|
// replace empty collaboration with process diagram
|
|
|
|
modeling.makeProcess();
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-19 09:11:47 +00:00
|
|
|
RemoveParticipantBehavior.$inject = [ 'eventBus', 'modeling' ];
|
2015-03-31 13:02:04 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
inherits(RemoveParticipantBehavior, CommandInterceptor);
|