2014-06-27 15:52:34 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-02-05 15:00:05 +00:00
|
|
|
|
|
|
|
var assign = require('lodash/object/assign'),
|
|
|
|
forEach = require('lodash/collection/forEach');
|
|
|
|
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A provider for BPMN 2.0 elements context pad
|
|
|
|
*/
|
2015-02-05 15:00:05 +00:00
|
|
|
function ContextPadProvider(contextPad, modeling, elementFactory,
|
|
|
|
connect, create, popupMenu,
|
|
|
|
replace, canvas) {
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
contextPad.registerProvider(this);
|
|
|
|
|
2015-02-05 15:00:05 +00:00
|
|
|
this._contextPad = contextPad;
|
2014-12-07 12:08:50 +00:00
|
|
|
|
2014-07-23 16:53:33 +00:00
|
|
|
this._modeling = modeling;
|
2014-09-11 14:44:56 +00:00
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
this._elementFactory = elementFactory;
|
2014-09-11 14:44:56 +00:00
|
|
|
this._connect = connect;
|
2014-12-07 12:08:50 +00:00
|
|
|
this._create = create;
|
2015-02-05 15:00:05 +00:00
|
|
|
this._popupMenu = popupMenu;
|
|
|
|
this._replace = replace;
|
|
|
|
this._canvas = canvas;
|
2014-06-27 15:52:34 +00:00
|
|
|
}
|
|
|
|
|
2014-12-07 14:10:02 +00:00
|
|
|
ContextPadProvider.$inject = [
|
|
|
|
'contextPad',
|
|
|
|
'modeling',
|
|
|
|
'elementFactory',
|
|
|
|
'connect',
|
2015-02-05 15:00:05 +00:00
|
|
|
'create',
|
|
|
|
'popupMenu',
|
|
|
|
'replace',
|
|
|
|
'canvas'
|
2014-12-07 14:10:02 +00:00
|
|
|
];
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
ContextPadProvider.prototype.getContextPadEntries = function(element) {
|
|
|
|
|
2015-02-05 15:00:05 +00:00
|
|
|
var contextPad = this._contextPad,
|
|
|
|
modeling = this._modeling,
|
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
elementFactory = this._elementFactory,
|
|
|
|
connect = this._connect,
|
2015-02-05 15:00:05 +00:00
|
|
|
create = this._create,
|
|
|
|
popupMenu = this._popupMenu,
|
|
|
|
replace = this._replace,
|
|
|
|
canvas = this._canvas;
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
var actions = {};
|
|
|
|
|
|
|
|
if (element.type === 'label') {
|
|
|
|
return actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
var bpmnElement = element.businessObject;
|
|
|
|
|
2014-12-23 15:48:12 +00:00
|
|
|
function startConnect(event, element, autoActivate) {
|
|
|
|
connect.start(event, element, autoActivate);
|
2014-09-11 14:44:56 +00:00
|
|
|
}
|
|
|
|
|
2015-02-05 15:00:05 +00:00
|
|
|
function removeElement(e) {
|
|
|
|
if (element.waypoints) {
|
|
|
|
modeling.removeConnection(element);
|
|
|
|
} else {
|
|
|
|
modeling.removeShape(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function replaceElement(element, newType, newBusinessAtt) {
|
|
|
|
replace.replaceElement(element, {type: newType}, newBusinessAtt);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPosition(element) {
|
|
|
|
|
|
|
|
var Y_OFFSET = 20;
|
|
|
|
|
|
|
|
var pad = contextPad.getPad(element);
|
|
|
|
var rect = pad.html.getBoundingClientRect();
|
|
|
|
|
|
|
|
var zoom = 1 / canvas.zoom();
|
|
|
|
|
|
|
|
var pos = {
|
|
|
|
x: rect.left,
|
|
|
|
y: (rect.top - rect.height * zoom / 2) + rect.height + Y_OFFSET
|
|
|
|
};
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getReplacementMenuEntries(element) {
|
|
|
|
|
|
|
|
function addMenuEntry(label, newType, newBusinessAtt, actionName, className) {
|
|
|
|
|
|
|
|
function appendListener() {
|
|
|
|
replaceElement(element, newType, newBusinessAtt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
label: label,
|
|
|
|
className: className,
|
|
|
|
action: {
|
|
|
|
name: actionName,
|
|
|
|
handler: appendListener
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// var startEventReplace = [];
|
|
|
|
// var interEventReplace = [];
|
|
|
|
// var endEventReplace = [];
|
|
|
|
|
|
|
|
var gatewayReplace = [
|
|
|
|
{
|
|
|
|
label: 'Exclusive Gateway',
|
|
|
|
actionName: 'replace-with-exclusive-gateway',
|
|
|
|
className: 'icon-exclusive-gateway-variant-1',
|
|
|
|
targetType: 'bpmn:ExclusiveGateway'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Parallel Gateway',
|
|
|
|
actionName: 'replace-with-parallel-gateway',
|
|
|
|
className: 'icon-parallel-gateway',
|
|
|
|
targetType: 'bpmn:ParallelGateway'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Inclusive Gateway',
|
|
|
|
actionName: 'replace-with-inclusive-gateway',
|
|
|
|
className: 'icon-inclusive-gateway',
|
|
|
|
targetType: 'bpmn:InclusiveGateway'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Complex Gateway',
|
|
|
|
actionName: 'replace-with-complex-gateway',
|
|
|
|
className: 'icon-complex-gateway',
|
|
|
|
targetType: 'bpmn:ComplexGateway'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Event based Gateway',
|
|
|
|
actionName: 'replace-with-event-based-gateway',
|
|
|
|
className: 'icon-event-based-gateway',
|
|
|
|
targetType: 'bpmn:EventBasedGateway',
|
|
|
|
newBusinessAtt: {instantiate: false, eventGatewayType: 'Exclusive'}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Event based instantiating Gateway',
|
|
|
|
actionName: 'replace-with-exclusive-event-based-gateway',
|
|
|
|
className: 'icon-exclusive-event-based',
|
|
|
|
targetType: 'bpmn:EventBasedGateway',
|
|
|
|
newBusinessAtt: {instantiate: true, eventGatewayType: 'Exclusive'}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Parallel Event based instantiating Gateway',
|
|
|
|
actionName: 'replace-with-parallel-event-based-instantiate-gateway',
|
|
|
|
className: 'icon-parallel-event-based-instantiate-gateway',
|
|
|
|
targetType: 'bpmn:EventBasedGateway',
|
|
|
|
newBusinessAtt: {instantiate: true, eventGatewayType: 'Parallel'}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
var taskReplace = [
|
|
|
|
{
|
|
|
|
label: 'Send Task',
|
|
|
|
actionName: 'replace-with-send-task',
|
|
|
|
className: 'icon-send',
|
|
|
|
targetType: 'bpmn:SendTask'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Receive Task',
|
|
|
|
actionName: 'replace-with-receive-task',
|
|
|
|
className: 'icon-receive',
|
|
|
|
targetType: 'bpmn:ReceiveTask'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'User Task',
|
|
|
|
actionName: 'replace-with-user-task',
|
|
|
|
className: 'icon-user',
|
|
|
|
targetType: 'bpmn:UserTask'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Manual Task',
|
|
|
|
actionName: 'replace-with-manual-task',
|
|
|
|
className: 'icon-manual',
|
|
|
|
targetType: 'bpmn:ManualTask'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Business Rule Task',
|
|
|
|
actionName: 'replace-with-rule-task',
|
|
|
|
className: 'icon-business-rule',
|
|
|
|
targetType: 'bpmn:BusinessRuleTask'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Service Task',
|
|
|
|
actionName: 'replace-with-service-task',
|
|
|
|
className: 'icon-service',
|
|
|
|
targetType: 'bpmn:ServiceTask'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Script Task',
|
|
|
|
actionName: 'replace-with-script-task',
|
|
|
|
className: 'icon-script',
|
|
|
|
targetType: 'bpmn:ScriptTask'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
var menuEntries = [];
|
|
|
|
|
|
|
|
if (element.businessObject.$instanceOf('bpmn:Event')) {
|
|
|
|
|
|
|
|
console.warn('Replace for event is not implemented yet.');
|
|
|
|
} else if (element.businessObject.$instanceOf('bpmn:Gateway')) {
|
|
|
|
|
|
|
|
forEach(gatewayReplace, function(definition) {
|
|
|
|
|
|
|
|
var entry = addMenuEntry(definition.label, definition.targetType, definition.newBusinessAtt,
|
|
|
|
definition.actionName, definition.className);
|
|
|
|
menuEntries.push(entry);
|
|
|
|
});
|
|
|
|
} else if (element.businessObject.$instanceOf('bpmn:FlowNode')) {
|
|
|
|
|
|
|
|
forEach(taskReplace, function(definition) {
|
|
|
|
|
|
|
|
var entry = addMenuEntry(definition.label, definition.targetType, {},
|
|
|
|
definition.actionName, definition.className);
|
|
|
|
menuEntries.push(entry);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return menuEntries;
|
|
|
|
}
|
|
|
|
|
2014-12-23 15:48:12 +00:00
|
|
|
function appendAction(type, className) {
|
2014-07-18 13:29:41 +00:00
|
|
|
|
2014-12-23 15:48:12 +00:00
|
|
|
function appendListener(event, element) {
|
|
|
|
var shape = elementFactory.createShape({ type: type });
|
|
|
|
create.start(event, shape, element);
|
|
|
|
}
|
2014-06-27 15:52:34 +00:00
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
return {
|
|
|
|
group: 'model',
|
|
|
|
className: className,
|
|
|
|
action: {
|
2014-12-23 15:48:12 +00:00
|
|
|
dragstart: appendListener,
|
|
|
|
click: appendListener
|
2014-06-27 15:52:34 +00:00
|
|
|
}
|
2014-12-07 12:08:50 +00:00
|
|
|
};
|
|
|
|
}
|
2014-06-27 15:52:34 +00:00
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
if (bpmnElement.$instanceOf('bpmn:FlowNode')) {
|
|
|
|
|
|
|
|
if (!bpmnElement.$instanceOf('bpmn:EndEvent')) {
|
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
assign(actions, {
|
2014-12-07 12:08:50 +00:00
|
|
|
'append.end-event': appendAction('bpmn:EndEvent', 'icon-end-event'),
|
|
|
|
'append.gateway': appendAction('bpmn:ExclusiveGateway', 'icon-gateway'),
|
|
|
|
'append.append-task': appendAction('bpmn:Task', 'icon-task'),
|
|
|
|
'append.intermediate-event': appendAction('bpmn:IntermediateThrowEvent', 'icon-intermediate-event'),
|
|
|
|
'connect': {
|
|
|
|
group: 'connect',
|
|
|
|
className: 'icon-connection',
|
|
|
|
action: {
|
|
|
|
click: startConnect,
|
|
|
|
dragstart: startConnect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
assign(actions, {
|
2014-12-07 12:08:50 +00:00
|
|
|
'append.text-annotation': appendAction('bpmn:TextAnnotation', 'icon-text-annotation')
|
|
|
|
});
|
2014-06-27 15:52:34 +00:00
|
|
|
|
2015-02-05 15:00:05 +00:00
|
|
|
|
|
|
|
// Replace menu entry
|
|
|
|
assign(actions, {
|
|
|
|
'replace': {
|
|
|
|
group: 'edit',
|
|
|
|
className: 'icon-screw-wrench',
|
|
|
|
action: {
|
|
|
|
|
|
|
|
click: function(event, element) {
|
|
|
|
var pos = getPosition(element);
|
|
|
|
|
|
|
|
var entries = getReplacementMenuEntries(element);
|
|
|
|
|
|
|
|
popupMenu.open(
|
|
|
|
pos,
|
|
|
|
entries,
|
|
|
|
{ className: 'replace-menu' }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-12-23 15:48:12 +00:00
|
|
|
}
|
|
|
|
|
2015-02-05 15:00:05 +00:00
|
|
|
// Delete Element Entry
|
2015-02-02 13:46:21 +00:00
|
|
|
assign(actions, {
|
2014-12-07 12:08:50 +00:00
|
|
|
'delete': {
|
2014-09-11 14:44:56 +00:00
|
|
|
group: 'edit',
|
2014-11-05 13:05:31 +00:00
|
|
|
className: 'icon-trash',
|
2014-12-23 15:48:12 +00:00
|
|
|
action: {
|
|
|
|
click: removeElement,
|
|
|
|
dragstart: removeElement
|
2014-09-04 11:28:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-27 15:52:34 +00:00
|
|
|
return actions;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-29 14:03:08 +00:00
|
|
|
module.exports = ContextPadProvider;
|