paletteProvider.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import { assign } from 'min-dash'
  2. /**
  3. * A palette provider for BPMN 2.0 elements.
  4. */
  5. export default function PaletteProvider(
  6. palette,
  7. create,
  8. elementFactory,
  9. spaceTool,
  10. lassoTool,
  11. handTool,
  12. globalConnect,
  13. translate
  14. ) {
  15. this._palette = palette
  16. this._create = create
  17. this._elementFactory = elementFactory
  18. this._spaceTool = spaceTool
  19. this._lassoTool = lassoTool
  20. this._handTool = handTool
  21. this._globalConnect = globalConnect
  22. this._translate = translate
  23. palette.registerProvider(this)
  24. }
  25. PaletteProvider.$inject = [
  26. 'palette',
  27. 'create',
  28. 'elementFactory',
  29. 'spaceTool',
  30. 'lassoTool',
  31. 'handTool',
  32. 'globalConnect',
  33. 'translate'
  34. ]
  35. PaletteProvider.prototype.getPaletteEntries = function () {
  36. const actions = {},
  37. create = this._create,
  38. elementFactory = this._elementFactory,
  39. spaceTool = this._spaceTool,
  40. lassoTool = this._lassoTool,
  41. handTool = this._handTool,
  42. globalConnect = this._globalConnect,
  43. translate = this._translate
  44. function createAction(type, group, className, title, options) {
  45. function createListener(event) {
  46. const shape = elementFactory.createShape(assign({ type: type }, options))
  47. if (options) {
  48. shape.businessObject.di.isExpanded = options.isExpanded
  49. }
  50. create.start(event, shape)
  51. }
  52. const shortType = type.replace(/^bpmn:/, '')
  53. return {
  54. group: group,
  55. className: className,
  56. title: title || translate('Create {type}', { type: shortType }),
  57. action: {
  58. dragstart: createListener,
  59. click: createListener
  60. }
  61. }
  62. }
  63. function createSubprocess(event) {
  64. const subProcess = elementFactory.createShape({
  65. type: 'bpmn:SubProcess',
  66. x: 0,
  67. y: 0,
  68. isExpanded: true
  69. })
  70. const startEvent = elementFactory.createShape({
  71. type: 'bpmn:StartEvent',
  72. x: 40,
  73. y: 82,
  74. parent: subProcess
  75. })
  76. create.start(event, [subProcess, startEvent], {
  77. hints: {
  78. autoSelect: [startEvent]
  79. }
  80. })
  81. }
  82. function createParticipant(event) {
  83. create.start(event, elementFactory.createParticipantShape())
  84. }
  85. assign(actions, {
  86. 'hand-tool': {
  87. group: 'tools',
  88. className: 'bpmn-icon-hand-tool',
  89. title: translate('Activate the hand tool'),
  90. action: {
  91. click: function (event) {
  92. handTool.activateHand(event)
  93. }
  94. }
  95. },
  96. 'lasso-tool': {
  97. group: 'tools',
  98. className: 'bpmn-icon-lasso-tool',
  99. title: translate('Activate the lasso tool'),
  100. action: {
  101. click: function (event) {
  102. lassoTool.activateSelection(event)
  103. }
  104. }
  105. },
  106. 'space-tool': {
  107. group: 'tools',
  108. className: 'bpmn-icon-space-tool',
  109. title: translate('Activate the create/remove space tool'),
  110. action: {
  111. click: function (event) {
  112. spaceTool.activateSelection(event)
  113. }
  114. }
  115. },
  116. 'global-connect-tool': {
  117. group: 'tools',
  118. className: 'bpmn-icon-connection-multi',
  119. title: translate('Activate the global connect tool'),
  120. action: {
  121. click: function (event) {
  122. globalConnect.toggle(event)
  123. }
  124. }
  125. },
  126. 'tool-separator': {
  127. group: 'tools',
  128. separator: true
  129. },
  130. 'create.start-event': createAction(
  131. 'bpmn:StartEvent',
  132. 'event',
  133. 'bpmn-icon-start-event-none',
  134. translate('Create StartEvent')
  135. ),
  136. 'create.intermediate-event': createAction(
  137. 'bpmn:IntermediateThrowEvent',
  138. 'event',
  139. 'bpmn-icon-intermediate-event-none',
  140. translate('Create Intermediate/Boundary Event')
  141. ),
  142. 'create.end-event': createAction(
  143. 'bpmn:EndEvent',
  144. 'event',
  145. 'bpmn-icon-end-event-none',
  146. translate('Create EndEvent')
  147. ),
  148. 'create.exclusive-gateway': createAction(
  149. 'bpmn:ExclusiveGateway',
  150. 'gateway',
  151. 'bpmn-icon-gateway-none',
  152. translate('Create Gateway')
  153. ),
  154. 'create.user-task': createAction(
  155. 'bpmn:UserTask',
  156. 'activity',
  157. 'bpmn-icon-user-task',
  158. translate('Create User Task')
  159. ),
  160. 'create.data-object': createAction(
  161. 'bpmn:DataObjectReference',
  162. 'data-object',
  163. 'bpmn-icon-data-object',
  164. translate('Create DataObjectReference')
  165. ),
  166. 'create.data-store': createAction(
  167. 'bpmn:DataStoreReference',
  168. 'data-store',
  169. 'bpmn-icon-data-store',
  170. translate('Create DataStoreReference')
  171. ),
  172. 'create.subprocess-expanded': {
  173. group: 'activity',
  174. className: 'bpmn-icon-subprocess-expanded',
  175. title: translate('Create expanded SubProcess'),
  176. action: {
  177. dragstart: createSubprocess,
  178. click: createSubprocess
  179. }
  180. },
  181. 'create.participant-expanded': {
  182. group: 'collaboration',
  183. className: 'bpmn-icon-participant',
  184. title: translate('Create Pool/Participant'),
  185. action: {
  186. dragstart: createParticipant,
  187. click: createParticipant
  188. }
  189. },
  190. 'create.group': createAction(
  191. 'bpmn:Group',
  192. 'artifact',
  193. 'bpmn-icon-group',
  194. translate('Create Group')
  195. )
  196. })
  197. return actions
  198. }