BoundaryEventBehavior.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import inherits from 'inherits';
  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. * BPMN specific boundary event behavior
  10. */
  11. export default function BoundaryEventBehavior(eventBus, modeling) {
  12. CommandInterceptor.call(this, eventBus);
  13. function getBoundaryEvents(element) {
  14. return filter(element.attachers, function(attacher) {
  15. return is(attacher, 'bpmn:BoundaryEvent');
  16. });
  17. }
  18. // remove after connecting to event-based gateway
  19. this.postExecute('connection.create', function(event) {
  20. var source = event.context.source,
  21. target = event.context.target,
  22. boundaryEvents = getBoundaryEvents(target);
  23. if (
  24. is(source, 'bpmn:EventBasedGateway') &&
  25. is(target, 'bpmn:ReceiveTask') &&
  26. boundaryEvents.length > 0
  27. ) {
  28. modeling.removeElements(boundaryEvents);
  29. }
  30. });
  31. // remove after replacing connected gateway with event-based gateway
  32. this.postExecute('connection.reconnect', function(event) {
  33. var oldSource = event.context.oldSource,
  34. newSource = event.context.newSource;
  35. if (is(oldSource, 'bpmn:Gateway') &&
  36. is(newSource, 'bpmn:EventBasedGateway')) {
  37. forEach(newSource.outgoing, function(connection) {
  38. var target = connection.target,
  39. attachedboundaryEvents = getBoundaryEvents(target);
  40. if (is(target, 'bpmn:ReceiveTask') &&
  41. attachedboundaryEvents.length > 0) {
  42. modeling.removeElements(attachedboundaryEvents);
  43. }
  44. });
  45. }
  46. });
  47. }
  48. BoundaryEventBehavior.$inject = [
  49. 'eventBus',
  50. 'modeling'
  51. ];
  52. inherits(BoundaryEventBehavior, CommandInterceptor);