2014-06-27 15:52:34 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-02-05 15:00:05 +00:00
|
|
|
|
2015-03-07 11:59:22 +00:00
|
|
|
var assign = require('lodash/object/assign'),
|
2015-06-24 09:43:07 +00:00
|
|
|
forEach = require('lodash/collection/forEach'),
|
2015-07-03 08:48:32 +00:00
|
|
|
is = require('../../util/ModelUtil').is;
|
2015-02-05 15:00:05 +00:00
|
|
|
|
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,
|
2015-03-11 15:17:19 +00:00
|
|
|
connect, create, bpmnReplace,
|
|
|
|
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-03-11 15:17:19 +00:00
|
|
|
this._bpmnReplace = bpmnReplace;
|
2015-02-05 15:00:05 +00:00
|
|
|
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',
|
2015-03-11 15:17:19 +00:00
|
|
|
'bpmnReplace',
|
2015-02-05 15:00:05 +00:00
|
|
|
'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,
|
2015-03-11 15:17:19 +00:00
|
|
|
bpmnReplace = this._bpmnReplace,
|
2015-02-05 15:00:05 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
function getReplaceMenuPosition(element) {
|
2015-02-05 15:00:05 +00:00
|
|
|
|
2015-03-04 14:27:13 +00:00
|
|
|
var Y_OFFSET = 5;
|
2015-02-05 15:00:05 +00:00
|
|
|
|
2015-03-04 14:27:13 +00:00
|
|
|
var diagramContainer = canvas.getContainer(),
|
|
|
|
pad = contextPad.getPad(element).html;
|
2015-02-05 15:00:05 +00:00
|
|
|
|
2015-03-04 14:27:13 +00:00
|
|
|
var diagramRect = diagramContainer.getBoundingClientRect(),
|
|
|
|
padRect = pad.getBoundingClientRect();
|
|
|
|
|
|
|
|
var top = padRect.top - diagramRect.top;
|
2015-05-08 12:26:05 +00:00
|
|
|
var left = padRect.left - diagramRect.left;
|
2015-02-05 15:00:05 +00:00
|
|
|
|
|
|
|
var pos = {
|
2015-05-08 12:26:05 +00:00
|
|
|
x: left,
|
2015-03-04 14:27:13 +00:00
|
|
|
y: top + padRect.height + Y_OFFSET
|
2015-02-05 15:00:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-06 08:27:18 +00:00
|
|
|
function appendAction(type, className, options) {
|
2014-07-18 13:29:41 +00:00
|
|
|
|
2014-12-23 15:48:12 +00:00
|
|
|
function appendListener(event, element) {
|
2015-03-06 08:27:18 +00:00
|
|
|
|
|
|
|
var shape = elementFactory.createShape(assign({ type: type }, options));
|
2014-12-23 15:48:12 +00:00
|
|
|
create.start(event, shape, element);
|
|
|
|
}
|
2014-06-27 15:52:34 +00:00
|
|
|
|
2015-05-11 15:36:01 +00:00
|
|
|
var shortType = type.replace(/^bpmn\:/, '');
|
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
return {
|
|
|
|
group: 'model',
|
|
|
|
className: className,
|
2015-05-11 15:36:01 +00:00
|
|
|
title: 'Append ' + shortType,
|
2014-12-07 12:08:50 +00:00
|
|
|
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
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
if (is(bpmnElement, 'bpmn:FlowNode')) {
|
2014-12-07 12:08:50 +00:00
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
if (!is(bpmnElement, 'bpmn:EndEvent') &&
|
|
|
|
!is(bpmnElement, 'bpmn:EventBasedGateway') &&
|
2015-03-07 11:59:22 +00:00
|
|
|
!isEventType(bpmnElement, 'bpmn:IntermediateThrowEvent', 'bpmn:LinkEventDefinition')) {
|
2014-12-07 12:08:50 +00:00
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
assign(actions, {
|
2015-03-10 15:07:58 +00:00
|
|
|
'append.end-event': appendAction('bpmn:EndEvent', 'icon-end-event-none'),
|
|
|
|
'append.gateway': appendAction('bpmn:ExclusiveGateway', 'icon-gateway-xor'),
|
2014-12-07 12:08:50 +00:00
|
|
|
'append.append-task': appendAction('bpmn:Task', 'icon-task'),
|
2015-03-05 17:04:57 +00:00
|
|
|
'append.intermediate-event': appendAction('bpmn:IntermediateThrowEvent',
|
2015-04-16 07:11:04 +00:00
|
|
|
'icon-intermediate-event-none')
|
2015-02-24 15:21:12 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
if (is(bpmnElement, 'bpmn:EventBasedGateway')) {
|
2015-02-26 15:19:34 +00:00
|
|
|
|
2015-02-24 15:21:12 +00:00
|
|
|
assign(actions, {
|
2015-03-04 14:50:06 +00:00
|
|
|
'append.receive-task': appendAction('bpmn:ReceiveTask', 'icon-receive-task'),
|
2015-03-06 08:27:18 +00:00
|
|
|
'append.message-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
|
2015-03-10 15:07:58 +00:00
|
|
|
'icon-intermediate-event-catch-message',
|
2015-03-06 08:27:18 +00:00
|
|
|
{ _eventDefinitionType: 'bpmn:MessageEventDefinition'}),
|
|
|
|
'append.timer-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
|
2015-03-10 15:07:58 +00:00
|
|
|
'icon-intermediate-event-catch-timer',
|
2015-03-06 08:27:18 +00:00
|
|
|
{ _eventDefinitionType: 'bpmn:TimerEventDefinition'}),
|
|
|
|
'append.condtion-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
|
2015-03-10 15:07:58 +00:00
|
|
|
'icon-intermediate-event-catch-condition',
|
2015-03-06 08:27:18 +00:00
|
|
|
{ _eventDefinitionType: 'bpmn:ConditionalEventDefinition'}),
|
|
|
|
'append.signal-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
|
2015-03-10 15:07:58 +00:00
|
|
|
'icon-intermediate-event-catch-signal',
|
2015-05-11 15:36:01 +00:00
|
|
|
{ _eventDefinitionType: 'bpmn:SignalEventDefinition'})
|
2014-12-07 12:08:50 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-02-05 15:00:05 +00:00
|
|
|
|
|
|
|
// Replace menu entry
|
2015-07-03 08:48:32 +00:00
|
|
|
assign(actions, {
|
|
|
|
'replace': {
|
|
|
|
group: 'edit',
|
|
|
|
className: 'icon-screw-wrench',
|
|
|
|
title: 'Change type',
|
|
|
|
action: {
|
|
|
|
click: function(event, element) {
|
|
|
|
bpmnReplace.openChooser(getReplaceMenuPosition(element), element);
|
2015-02-05 15:00:05 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-03 08:48:32 +00:00
|
|
|
}
|
|
|
|
});
|
2014-12-23 15:48:12 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
if (is(bpmnElement, 'bpmn:FlowNode') ||
|
|
|
|
is(bpmnElement, 'bpmn:InteractionNode')) {
|
2015-04-16 07:11:04 +00:00
|
|
|
|
|
|
|
assign(actions, {
|
|
|
|
'append.text-annotation': appendAction('bpmn:TextAnnotation', 'icon-text-annotation'),
|
|
|
|
|
|
|
|
'connect': {
|
|
|
|
group: 'connect',
|
2015-05-12 13:25:35 +00:00
|
|
|
className: 'icon-connection-multi',
|
2015-05-11 15:36:01 +00:00
|
|
|
title: 'Connect using Sequence/MessageFlow',
|
2015-04-16 07:11:04 +00:00
|
|
|
action: {
|
|
|
|
click: startConnect,
|
|
|
|
dragstart: startConnect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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',
|
2015-05-11 15:36:01 +00:00
|
|
|
title: 'Remove',
|
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;
|
|
|
|
};
|
|
|
|
|
2015-03-07 11:59:22 +00:00
|
|
|
function isEventType(eventBo, type, definition) {
|
|
|
|
|
|
|
|
var isType = eventBo.$instanceOf(type);
|
|
|
|
var isDefinition = false;
|
|
|
|
|
|
|
|
var definitions = eventBo.eventDefinitions || [];
|
|
|
|
forEach(definitions, function(def) {
|
|
|
|
if (def.$type === definition) {
|
|
|
|
isDefinition = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return isType && isDefinition;
|
|
|
|
}
|
|
|
|
|
2014-06-27 15:52:34 +00:00
|
|
|
|
2014-08-29 14:03:08 +00:00
|
|
|
module.exports = ContextPadProvider;
|