RemoveParticipantBehavior.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import inherits from 'inherits-browser';
  2. import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
  3. import { is } from '../../../util/ModelUtil';
  4. /**
  5. * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
  6. * @typedef {import('../Modeling').default} Modeling
  7. */
  8. /**
  9. * BPMN specific remove behavior.
  10. *
  11. * @param {EventBus} eventBus
  12. * @param {Modeling} modeling
  13. */
  14. export default function RemoveParticipantBehavior(eventBus, modeling) {
  15. CommandInterceptor.call(this, eventBus);
  16. /**
  17. * morph collaboration diagram into process diagram
  18. * after the last participant has been removed
  19. */
  20. this.preExecute('shape.delete', function(context) {
  21. var shape = context.shape,
  22. parent = shape.parent;
  23. // activate the behavior if the shape to be removed
  24. // is a participant
  25. if (is(shape, 'bpmn:Participant')) {
  26. context.collaborationRoot = parent;
  27. }
  28. }, true);
  29. this.postExecute('shape.delete', function(context) {
  30. var collaborationRoot = context.collaborationRoot;
  31. if (collaborationRoot && !collaborationRoot.businessObject.participants.length) {
  32. // replace empty collaboration with process diagram
  33. modeling.makeProcess();
  34. }
  35. }, true);
  36. }
  37. RemoveParticipantBehavior.$inject = [ 'eventBus', 'modeling' ];
  38. inherits(RemoveParticipantBehavior, CommandInterceptor);