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-08-04 15:52:43 +00:00
|
|
|
is = require('../../util/ModelUtil').is,
|
2015-10-09 23:28:04 +00:00
|
|
|
isAny = require('../modeling/util/ModelingUtil').isAny,
|
|
|
|
getChildLanes = require('../modeling/util/LaneUtil').getChildLanes,
|
2015-08-04 15:52:43 +00:00
|
|
|
isEventSubProcess = require('../../util/DiUtil').isEventSubProcess;
|
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
|
|
|
|
2015-10-09 23:28:04 +00:00
|
|
|
module.exports = ContextPadProvider;
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-10-09 23:28:04 +00:00
|
|
|
var businessObject = element.businessObject;
|
2014-06-27 15:52:34 +00:00
|
|
|
|
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) {
|
2015-10-15 21:48:14 +00:00
|
|
|
modeling.removeElements([ element ]);
|
2015-02-05 15:00:05 +00:00
|
|
|
}
|
|
|
|
|
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-10-20 14:29:13 +00:00
|
|
|
function splitLaneHandler(count) {
|
|
|
|
|
|
|
|
return function(event, element) {
|
|
|
|
// actual split
|
|
|
|
modeling.splitLane(element, count);
|
|
|
|
|
|
|
|
// refresh context pad after split to
|
|
|
|
// get rid of split icons
|
|
|
|
contextPad.open(element, true);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-10-09 23:28:04 +00:00
|
|
|
if (isAny(businessObject, [ 'bpmn:Lane', 'bpmn:Participant' ])) {
|
2014-12-07 12:08:50 +00:00
|
|
|
|
2015-10-09 23:28:04 +00:00
|
|
|
var childLanes = getChildLanes(element);
|
|
|
|
|
|
|
|
assign(actions, {
|
|
|
|
'lane-insert-above': {
|
|
|
|
group: 'lane-insert-above',
|
|
|
|
className: 'icon-lane-insert-above',
|
|
|
|
title: 'Add Lane above',
|
|
|
|
action: {
|
|
|
|
click: function(event, element) {
|
|
|
|
modeling.addLane(element, 'top');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (childLanes.length < 2) {
|
2015-10-20 15:57:41 +00:00
|
|
|
|
|
|
|
if (element.height >= 120) {
|
|
|
|
assign(actions, {
|
|
|
|
'lane-divide-two': {
|
|
|
|
group: 'lane-divide',
|
|
|
|
className: 'icon-lane-divide-two',
|
|
|
|
title: 'Divide into two Lanes',
|
|
|
|
action: {
|
|
|
|
click: splitLaneHandler(2)
|
|
|
|
}
|
2015-10-09 23:28:04 +00:00
|
|
|
}
|
2015-10-20 15:57:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element.height >= 180) {
|
|
|
|
assign(actions, {
|
|
|
|
'lane-divide-three': {
|
|
|
|
group: 'lane-divide',
|
|
|
|
className: 'icon-lane-divide-three',
|
|
|
|
title: 'Divide into three Lanes',
|
|
|
|
action: {
|
|
|
|
click: splitLaneHandler(3)
|
|
|
|
}
|
2015-10-09 23:28:04 +00:00
|
|
|
}
|
2015-10-20 15:57:41 +00:00
|
|
|
});
|
|
|
|
}
|
2015-10-09 23:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assign(actions, {
|
|
|
|
'lane-insert-below': {
|
|
|
|
group: 'lane-insert-below',
|
|
|
|
className: 'icon-lane-insert-below',
|
|
|
|
title: 'Add Lane below',
|
|
|
|
action: {
|
|
|
|
click: function(event, element) {
|
|
|
|
modeling.addLane(element, 'bottom');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is(businessObject, 'bpmn:FlowNode')) {
|
|
|
|
|
|
|
|
if (!is(businessObject, 'bpmn:EndEvent') &&
|
|
|
|
!is(businessObject, 'bpmn:EventBasedGateway') &&
|
|
|
|
!isEventType(businessObject, 'bpmn:IntermediateThrowEvent', 'bpmn:LinkEventDefinition') &&
|
|
|
|
!isEventSubProcess(businessObject)) {
|
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-10-09 23:28:04 +00:00
|
|
|
if (is(businessObject, '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-09-29 05:58:26 +00:00
|
|
|
}
|
2014-12-07 12:08:50 +00:00
|
|
|
|
2015-10-09 23:28:04 +00:00
|
|
|
var replaceOptions = bpmnReplace.getReplaceOptions(element);
|
|
|
|
|
|
|
|
if (replaceOptions.length) {
|
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-10-09 23:28:04 +00:00
|
|
|
if (isAny(businessObject, [ 'bpmn:FlowNode', '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-10-09 23:28:04 +00:00
|
|
|
if (is(businessObject, 'bpmn:DataObjectReference')) {
|
2015-10-06 10:33:21 +00:00
|
|
|
assign(actions, {
|
|
|
|
'connect': {
|
|
|
|
group: 'connect',
|
|
|
|
className: 'icon-connection-multi',
|
|
|
|
title: 'Connect using DataInputAssociation',
|
|
|
|
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;
|
2015-10-09 23:28:04 +00:00
|
|
|
}
|