UnsetDefaultFlowBehavior.js 1.2 KB

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