RemoveParticipantBehavior.js 1.1 KB

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