BoundaryEventBehavior.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import inherits from 'inherits-browser';
  2. import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
  3. import { is } from '../../../util/ModelUtil';
  4. import {
  5. filter,
  6. forEach
  7. } from 'min-dash';
  8. /**
  9. * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
  10. * @typedef {import('../Modeling').default} Modeling
  11. */
  12. /**
  13. * BPMN specific boundary event behavior.
  14. *
  15. * @param {EventBus} eventBus
  16. * @param {Modeling} modeling
  17. */
  18. export default function BoundaryEventBehavior(eventBus, modeling) {
  19. CommandInterceptor.call(this, eventBus);
  20. function getBoundaryEvents(element) {
  21. return filter(element.attachers, function(attacher) {
  22. return is(attacher, 'bpmn:BoundaryEvent');
  23. });
  24. }
  25. // remove after connecting to event-based gateway
  26. this.postExecute('connection.create', function(event) {
  27. var source = event.context.source,
  28. target = event.context.target,
  29. boundaryEvents = getBoundaryEvents(target);
  30. if (
  31. is(source, 'bpmn:EventBasedGateway') &&
  32. is(target, 'bpmn:ReceiveTask') &&
  33. boundaryEvents.length > 0
  34. ) {
  35. modeling.removeElements(boundaryEvents);
  36. }
  37. });
  38. // remove after replacing connected gateway with event-based gateway
  39. this.postExecute('connection.reconnect', function(event) {
  40. var oldSource = event.context.oldSource,
  41. newSource = event.context.newSource;
  42. if (is(oldSource, 'bpmn:Gateway') &&
  43. is(newSource, 'bpmn:EventBasedGateway')) {
  44. forEach(newSource.outgoing, function(connection) {
  45. var target = connection.target,
  46. attachedboundaryEvents = getBoundaryEvents(target);
  47. if (is(target, 'bpmn:ReceiveTask') &&
  48. attachedboundaryEvents.length > 0) {
  49. modeling.removeElements(attachedboundaryEvents);
  50. }
  51. });
  52. }
  53. });
  54. }
  55. BoundaryEventBehavior.$inject = [
  56. 'eventBus',
  57. 'modeling'
  58. ];
  59. inherits(BoundaryEventBehavior, CommandInterceptor);