PaletteProvider.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import {
  2. assign
  3. } from 'min-dash';
  4. /**
  5. * A palette provider for BPMN 2.0 elements.
  6. */
  7. export default function PaletteProvider(
  8. palette, create, elementFactory,
  9. spaceTool, lassoTool, handTool,
  10. globalConnect, translate) {
  11. this._palette = palette;
  12. this._create = create;
  13. this._elementFactory = elementFactory;
  14. this._spaceTool = spaceTool;
  15. this._lassoTool = lassoTool;
  16. this._handTool = handTool;
  17. this._globalConnect = globalConnect;
  18. this._translate = translate;
  19. palette.registerProvider(this);
  20. }
  21. PaletteProvider.$inject = [
  22. 'palette',
  23. 'create',
  24. 'elementFactory',
  25. 'spaceTool',
  26. 'lassoTool',
  27. 'handTool',
  28. 'globalConnect',
  29. 'translate'
  30. ];
  31. PaletteProvider.prototype.getPaletteEntries = function(element) {
  32. var actions = {},
  33. create = this._create,
  34. elementFactory = this._elementFactory,
  35. spaceTool = this._spaceTool,
  36. lassoTool = this._lassoTool,
  37. handTool = this._handTool,
  38. globalConnect = this._globalConnect,
  39. translate = this._translate;
  40. function createAction(type, group, className, title, options) {
  41. function createListener(event) {
  42. var shape = elementFactory.createShape(assign({ type: type }, options));
  43. if (options) {
  44. shape.businessObject.di.isExpanded = options.isExpanded;
  45. }
  46. create.start(event, shape);
  47. }
  48. var shortType = type.replace(/^bpmn:/, '');
  49. return {
  50. group: group,
  51. className: className,
  52. title: title || translate('Create {type}', { type: shortType }),
  53. action: {
  54. dragstart: createListener,
  55. click: createListener
  56. }
  57. };
  58. }
  59. function createParticipant(event, collapsed) {
  60. create.start(event, elementFactory.createParticipantShape(collapsed));
  61. }
  62. assign(actions, {
  63. 'hand-tool': {
  64. group: 'tools',
  65. className: 'bpmn-icon-hand-tool',
  66. title: translate('Activate the hand tool'),
  67. action: {
  68. click: function(event) {
  69. handTool.activateHand(event);
  70. }
  71. }
  72. },
  73. 'lasso-tool': {
  74. group: 'tools',
  75. className: 'bpmn-icon-lasso-tool',
  76. title: translate('Activate the lasso tool'),
  77. action: {
  78. click: function(event) {
  79. lassoTool.activateSelection(event);
  80. }
  81. }
  82. },
  83. 'space-tool': {
  84. group: 'tools',
  85. className: 'bpmn-icon-space-tool',
  86. title: translate('Activate the create/remove space tool'),
  87. action: {
  88. click: function(event) {
  89. spaceTool.activateSelection(event);
  90. }
  91. }
  92. },
  93. 'global-connect-tool': {
  94. group: 'tools',
  95. className: 'bpmn-icon-connection-multi',
  96. title: translate('Activate the global connect tool'),
  97. action: {
  98. click: function(event) {
  99. globalConnect.toggle(event);
  100. }
  101. }
  102. },
  103. 'tool-separator': {
  104. group: 'tools',
  105. separator: true
  106. },
  107. 'create.start-event': createAction(
  108. 'bpmn:StartEvent', 'event', 'bpmn-icon-start-event-none'
  109. ),
  110. 'create.intermediate-event': createAction(
  111. 'bpmn:IntermediateThrowEvent', 'event', 'bpmn-icon-intermediate-event-none',
  112. translate('Create Intermediate/Boundary Event')
  113. ),
  114. 'create.end-event': createAction(
  115. 'bpmn:EndEvent', 'event', 'bpmn-icon-end-event-none'
  116. ),
  117. 'create.exclusive-gateway': createAction(
  118. 'bpmn:ExclusiveGateway', 'gateway', 'bpmn-icon-gateway-none',
  119. translate('Create Gateway')
  120. ),
  121. 'create.task': createAction(
  122. 'bpmn:Task', 'activity', 'bpmn-icon-task'
  123. ),
  124. 'create.data-object': createAction(
  125. 'bpmn:DataObjectReference', 'data-object', 'bpmn-icon-data-object'
  126. ),
  127. 'create.data-store': createAction(
  128. 'bpmn:DataStoreReference', 'data-store', 'bpmn-icon-data-store'
  129. ),
  130. 'create.subprocess-expanded': createAction(
  131. 'bpmn:SubProcess', 'activity', 'bpmn-icon-subprocess-expanded',
  132. translate('Create expanded SubProcess'),
  133. { isExpanded: true }
  134. ),
  135. 'create.participant-expanded': {
  136. group: 'collaboration',
  137. className: 'bpmn-icon-participant',
  138. title: translate('Create Pool/Participant'),
  139. action: {
  140. dragstart: createParticipant,
  141. click: createParticipant
  142. }
  143. }
  144. });
  145. return actions;
  146. };