UnsetDefaultFlowBehavior.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import inherits from 'inherits-browser';
  2. import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
  3. import {
  4. getBusinessObject,
  5. is
  6. } from '../../../util/ModelUtil';
  7. /**
  8. * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
  9. * @typedef {import('../Modeling').default} Modeling
  10. */
  11. /**
  12. * A behavior that unsets the Default property of sequence flow source on
  13. * element delete, if the removed element is the Gateway or Task's default flow.
  14. *
  15. * @param {EventBus} eventBus
  16. * @param {Modeling} modeling
  17. */
  18. export default function DeleteSequenceFlowBehavior(eventBus, modeling) {
  19. CommandInterceptor.call(this, eventBus);
  20. this.preExecute('connection.delete', function(event) {
  21. var context = event.context,
  22. connection = context.connection,
  23. source = connection.source;
  24. if (isDefaultFlow(connection, source)) {
  25. modeling.updateProperties(source, {
  26. 'default': null
  27. });
  28. }
  29. });
  30. }
  31. inherits(DeleteSequenceFlowBehavior, CommandInterceptor);
  32. DeleteSequenceFlowBehavior.$inject = [
  33. 'eventBus',
  34. 'modeling'
  35. ];
  36. // helpers //////////////////////
  37. function isDefaultFlow(connection, source) {
  38. if (!is(connection, 'bpmn:SequenceFlow')) {
  39. return false;
  40. }
  41. var sourceBo = getBusinessObject(source),
  42. sequenceFlow = getBusinessObject(connection);
  43. return sourceBo.get('default') === sequenceFlow;
  44. }