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