PaletteProvider.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 createSubprocess(event) {
  60. var subProcess = elementFactory.createShape({
  61. type: 'bpmn:SubProcess',
  62. x: 0,
  63. y: 0,
  64. isExpanded: true
  65. });
  66. var startEvent = elementFactory.createShape({
  67. type: 'bpmn:StartEvent',
  68. x: 40,
  69. y: 82,
  70. parent: subProcess
  71. });
  72. create.start(event, [ subProcess, startEvent ], {
  73. hints: {
  74. autoSelect: [ startEvent ]
  75. }
  76. });
  77. }
  78. function createParticipant(event) {
  79. create.start(event, elementFactory.createParticipantShape());
  80. }
  81. assign(actions, {
  82. 'hand-tool': {
  83. group: 'tools',
  84. className: 'bpmn-icon-hand-tool',
  85. title: translate('Activate the hand tool'),
  86. action: {
  87. click: function(event) {
  88. handTool.activateHand(event);
  89. }
  90. }
  91. },
  92. 'lasso-tool': {
  93. group: 'tools',
  94. className: 'bpmn-icon-lasso-tool',
  95. title: translate('Activate the lasso tool'),
  96. action: {
  97. click: function(event) {
  98. lassoTool.activateSelection(event);
  99. }
  100. }
  101. },
  102. 'space-tool': {
  103. group: 'tools',
  104. className: 'bpmn-icon-space-tool',
  105. title: translate('Activate the create/remove space tool'),
  106. action: {
  107. click: function(event) {
  108. spaceTool.activateSelection(event);
  109. }
  110. }
  111. },
  112. 'global-connect-tool': {
  113. group: 'tools',
  114. className: 'bpmn-icon-connection-multi',
  115. title: translate('Activate the global connect tool'),
  116. action: {
  117. click: function(event) {
  118. globalConnect.toggle(event);
  119. }
  120. }
  121. },
  122. 'tool-separator': {
  123. group: 'tools',
  124. separator: true
  125. },
  126. 'create.start-event': createAction(
  127. 'bpmn:StartEvent', 'event', 'bpmn-icon-start-event-none',
  128. translate('Create StartEvent')
  129. ),
  130. 'create.intermediate-event': createAction(
  131. 'bpmn:IntermediateThrowEvent', 'event', 'bpmn-icon-intermediate-event-none',
  132. translate('Create Intermediate/Boundary Event')
  133. ),
  134. 'create.end-event': createAction(
  135. 'bpmn:EndEvent', 'event', 'bpmn-icon-end-event-none',
  136. translate('Create EndEvent')
  137. ),
  138. 'create.exclusive-gateway': createAction(
  139. 'bpmn:ExclusiveGateway', 'gateway', 'bpmn-icon-gateway-none',
  140. translate('Create Gateway')
  141. ),
  142. 'create.task': createAction(
  143. 'bpmn:Task', 'activity', 'bpmn-icon-task',
  144. translate('Create Task')
  145. ),
  146. 'create.data-object': createAction(
  147. 'bpmn:DataObjectReference', 'data-object', 'bpmn-icon-data-object',
  148. translate('Create DataObjectReference')
  149. ),
  150. 'create.data-store': createAction(
  151. 'bpmn:DataStoreReference', 'data-store', 'bpmn-icon-data-store',
  152. translate('Create DataStoreReference')
  153. ),
  154. 'create.subprocess-expanded': {
  155. group: 'activity',
  156. className: 'bpmn-icon-subprocess-expanded',
  157. title: translate('Create expanded SubProcess'),
  158. action: {
  159. dragstart: createSubprocess,
  160. click: createSubprocess
  161. }
  162. },
  163. 'create.participant-expanded': {
  164. group: 'collaboration',
  165. className: 'bpmn-icon-participant',
  166. title: translate('Create Pool/Participant'),
  167. action: {
  168. dragstart: createParticipant,
  169. click: createParticipant
  170. }
  171. },
  172. 'create.group': createAction(
  173. 'bpmn:Group', 'artifact', 'bpmn-icon-group',
  174. translate('Create Group')
  175. ),
  176. });
  177. return actions;
  178. };