ModelingFeedback.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { is } from '../../util/ModelUtil';
  2. /**
  3. * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
  4. * @typedef {import('diagram-js/lib/features/tooltips/Tooltips').default} Tooltips
  5. * @typedef {import('diagram-js/lib/i18n/translate/translate').default} Translate
  6. */
  7. var COLLAB_ERR_MSG = 'flow elements must be children of pools/participants';
  8. /**
  9. * @param {EventBus} eventBus
  10. * @param {Tooltips} tooltips
  11. * @param {Translate} translate
  12. */
  13. export default function ModelingFeedback(eventBus, tooltips, translate) {
  14. function showError(position, message, timeout) {
  15. tooltips.add({
  16. position: {
  17. x: position.x + 5,
  18. y: position.y + 5
  19. },
  20. type: 'error',
  21. timeout: timeout || 2000,
  22. html: '<div>' + message + '</div>'
  23. });
  24. }
  25. eventBus.on([ 'shape.move.rejected', 'create.rejected' ], function(event) {
  26. var context = event.context,
  27. shape = context.shape,
  28. target = context.target;
  29. if (is(target, 'bpmn:Collaboration') && is(shape, 'bpmn:FlowNode')) {
  30. showError(event, translate(COLLAB_ERR_MSG));
  31. }
  32. });
  33. }
  34. ModelingFeedback.$inject = [
  35. 'eventBus',
  36. 'tooltips',
  37. 'translate'
  38. ];