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-12-02 11:12:04 +00:00
|
|
|
isArray = require('lodash/lang/isArray'),
|
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-12-10 11:48:40 +00:00
|
|
|
connect, create, popupMenu,
|
2015-12-02 11:12:04 +00:00
|
|
|
canvas, rules) {
|
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-12-10 11:48:40 +00:00
|
|
|
this._popupMenu = popupMenu;
|
2015-02-05 15:00:05 +00:00
|
|
|
this._canvas = canvas;
|
2015-12-02 11:12:04 +00:00
|
|
|
this._rules = rules;
|
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-12-10 11:48:40 +00:00
|
|
|
'popupMenu',
|
2015-12-02 11:12:04 +00:00
|
|
|
'canvas',
|
|
|
|
'rules'
|
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-12-10 11:48:40 +00:00
|
|
|
popupMenu = this._popupMenu,
|
2015-12-02 11:12:04 +00:00
|
|
|
canvas = this._canvas,
|
|
|
|
rules = this._rules;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-21 10:17:11 +00:00
|
|
|
/**
|
|
|
|
* Create an append action
|
|
|
|
*
|
|
|
|
* @param {String} type
|
|
|
|
* @param {String} className
|
|
|
|
* @param {String} [title]
|
|
|
|
* @param {Object} [options]
|
|
|
|
*
|
|
|
|
* @return {Object} descriptor
|
|
|
|
*/
|
|
|
|
function appendAction(type, className, title, options) {
|
|
|
|
|
|
|
|
if (typeof title !== 'string') {
|
|
|
|
options = title;
|
|
|
|
title = 'Append ' + type.replace(/^bpmn\:/, '');
|
|
|
|
}
|
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
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
return {
|
|
|
|
group: 'model',
|
|
|
|
className: className,
|
2016-01-21 10:17:11 +00:00
|
|
|
title: title,
|
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',
|
2015-11-16 14:28:18 +00:00
|
|
|
className: 'bpmn-icon-lane-insert-above',
|
2015-10-09 23:28:04 +00:00
|
|
|
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',
|
2015-11-16 14:28:18 +00:00
|
|
|
className: 'bpmn-icon-lane-divide-two',
|
2015-10-20 15:57:41 +00:00
|
|
|
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',
|
2015-11-16 14:28:18 +00:00
|
|
|
className: 'bpmn-icon-lane-divide-three',
|
2015-10-20 15:57:41 +00:00
|
|
|
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',
|
2015-11-16 14:28:18 +00:00
|
|
|
className: 'bpmn-icon-lane-insert-below',
|
2015-10-09 23:28:04 +00:00
|
|
|
title: 'Add Lane below',
|
|
|
|
action: {
|
|
|
|
click: function(event, element) {
|
|
|
|
modeling.addLane(element, 'bottom');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is(businessObject, 'bpmn:FlowNode')) {
|
|
|
|
|
|
|
|
if (is(businessObject, 'bpmn:EventBasedGateway')) {
|
2015-02-26 15:19:34 +00:00
|
|
|
|
2015-02-24 15:21:12 +00:00
|
|
|
assign(actions, {
|
2015-11-16 14:28:18 +00:00
|
|
|
'append.receive-task': appendAction('bpmn:ReceiveTask', 'bpmn-icon-receive-task'),
|
2015-03-06 08:27:18 +00:00
|
|
|
'append.message-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
|
2015-11-16 14:28:18 +00:00
|
|
|
'bpmn-icon-intermediate-event-catch-message',
|
2016-01-21 10:17:11 +00:00
|
|
|
{ eventDefinitionType: 'bpmn:MessageEventDefinition'}),
|
2015-03-06 08:27:18 +00:00
|
|
|
'append.timer-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
|
2015-11-16 14:28:18 +00:00
|
|
|
'bpmn-icon-intermediate-event-catch-timer',
|
2016-01-21 10:17:11 +00:00
|
|
|
{ eventDefinitionType: 'bpmn:TimerEventDefinition'}),
|
2015-03-06 08:27:18 +00:00
|
|
|
'append.condtion-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
|
2015-11-16 14:28:18 +00:00
|
|
|
'bpmn-icon-intermediate-event-catch-condition',
|
2016-01-21 10:17:11 +00:00
|
|
|
{ eventDefinitionType: 'bpmn:ConditionalEventDefinition'}),
|
2015-03-06 08:27:18 +00:00
|
|
|
'append.signal-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
|
2015-11-16 14:28:18 +00:00
|
|
|
'bpmn-icon-intermediate-event-catch-signal',
|
2016-01-21 10:17:11 +00:00
|
|
|
{ eventDefinitionType: 'bpmn:SignalEventDefinition'})
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (isEventType(businessObject, 'bpmn:BoundaryEvent', 'bpmn:CompensateEventDefinition')) {
|
|
|
|
|
|
|
|
assign(actions, {
|
|
|
|
'append.compensation-activity':
|
|
|
|
appendAction('bpmn:Task', 'bpmn-icon-task', 'Append compensation activity', {
|
|
|
|
isForCompensation: true
|
|
|
|
})
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (!is(businessObject, 'bpmn:EndEvent') &&
|
|
|
|
!businessObject.isForCompensation &&
|
|
|
|
!isEventType(businessObject, 'bpmn:IntermediateThrowEvent', 'bpmn:LinkEventDefinition') &&
|
|
|
|
!isEventSubProcess(businessObject)) {
|
|
|
|
|
|
|
|
assign(actions, {
|
|
|
|
'append.end-event': appendAction('bpmn:EndEvent', 'bpmn-icon-end-event-none'),
|
|
|
|
'append.gateway': appendAction('bpmn:ExclusiveGateway', 'bpmn-icon-gateway-xor'),
|
|
|
|
'append.append-task': appendAction('bpmn:Task', 'bpmn-icon-task'),
|
|
|
|
'append.intermediate-event': appendAction('bpmn:IntermediateThrowEvent',
|
|
|
|
'bpmn-icon-intermediate-event-none')
|
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-12-10 11:48:40 +00:00
|
|
|
var replaceMenu;
|
|
|
|
|
|
|
|
if (popupMenu._providers['bpmn-replace']) {
|
|
|
|
replaceMenu = popupMenu.create('bpmn-replace', element);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (replaceMenu && !replaceMenu.isEmpty()) {
|
2015-10-09 23:28:04 +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',
|
2015-11-16 14:28:18 +00:00
|
|
|
className: 'bpmn-icon-screw-wrench',
|
2015-07-03 08:48:32 +00:00
|
|
|
title: 'Change type',
|
|
|
|
action: {
|
|
|
|
click: function(event, element) {
|
2016-01-05 13:37:30 +00:00
|
|
|
replaceMenu.open(assign(getReplaceMenuPosition(element), {
|
|
|
|
cursor: { x: event.x, y: event.y }
|
|
|
|
}), 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
|
|
|
}
|
|
|
|
|
2016-01-21 10:17:11 +00:00
|
|
|
if (isAny(businessObject, [ 'bpmn:FlowNode', 'bpmn:InteractionNode' ]) ) {
|
2015-04-16 07:11:04 +00:00
|
|
|
|
|
|
|
assign(actions, {
|
2015-11-16 14:28:18 +00:00
|
|
|
'append.text-annotation': appendAction('bpmn:TextAnnotation', 'bpmn-icon-text-annotation'),
|
2015-04-16 07:11:04 +00:00
|
|
|
|
|
|
|
'connect': {
|
|
|
|
group: 'connect',
|
2015-11-16 14:28:18 +00:00
|
|
|
className: 'bpmn-icon-connection-multi',
|
2016-01-21 10:17:11 +00:00
|
|
|
title: 'Connect using ' +
|
|
|
|
(businessObject.isForCompensation ? '' : 'Sequence/MessageFlow or ') +
|
|
|
|
'Association',
|
2015-04-16 07:11:04 +00:00
|
|
|
action: {
|
|
|
|
click: startConnect,
|
|
|
|
dragstart: startConnect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-25 20:26:46 +00:00
|
|
|
if (isAny(businessObject, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ])) {
|
2015-10-06 10:33:21 +00:00
|
|
|
assign(actions, {
|
|
|
|
'connect': {
|
|
|
|
group: 'connect',
|
2015-11-16 14:28:18 +00:00
|
|
|
className: 'bpmn-icon-connection-multi',
|
2015-10-06 10:33:21 +00:00
|
|
|
title: 'Connect using DataInputAssociation',
|
|
|
|
action: {
|
|
|
|
click: startConnect,
|
|
|
|
dragstart: startConnect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-12-02 11:12:04 +00:00
|
|
|
// delete element entry, only show if allowed by rules
|
|
|
|
var deleteAllowed = rules.allowed('elements.delete', { elements: [ element ]});
|
|
|
|
|
|
|
|
if (isArray(deleteAllowed)) {
|
|
|
|
// was the element returned as a deletion candidate?
|
|
|
|
deleteAllowed = deleteAllowed[0] === element;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deleteAllowed) {
|
|
|
|
assign(actions, {
|
|
|
|
'delete': {
|
|
|
|
group: 'edit',
|
|
|
|
className: 'bpmn-icon-trash',
|
|
|
|
title: 'Remove',
|
|
|
|
action: {
|
|
|
|
click: removeElement,
|
|
|
|
dragstart: removeElement
|
|
|
|
}
|
2014-09-04 11:28:35 +00:00
|
|
|
}
|
2015-12-02 11:12:04 +00:00
|
|
|
});
|
|
|
|
}
|
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;
|
2016-01-05 13:37:30 +00:00
|
|
|
}
|