2015-01-19 11:13:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-07-23 11:59:47 +00:00
|
|
|
var forEach = require('lodash/collection/forEach'),
|
|
|
|
filter = require('lodash/collection/filter'),
|
|
|
|
pick = require('lodash/object/pick'),
|
|
|
|
assign = require('lodash/object/assign');
|
2015-03-11 15:17:19 +00:00
|
|
|
|
|
|
|
var REPLACE_OPTIONS = require ('./ReplaceOptions');
|
|
|
|
|
|
|
|
var startEventReplace = REPLACE_OPTIONS.START_EVENT,
|
|
|
|
intermediateEventReplace = REPLACE_OPTIONS.INTERMEDIATE_EVENT,
|
|
|
|
endEventReplace = REPLACE_OPTIONS.END_EVENT,
|
|
|
|
gatewayReplace = REPLACE_OPTIONS.GATEWAY,
|
2015-06-24 09:43:07 +00:00
|
|
|
taskReplace = REPLACE_OPTIONS.TASK,
|
2015-07-03 08:48:32 +00:00
|
|
|
subProcessExpandedReplace = REPLACE_OPTIONS.SUBPROCESS_EXPANDED,
|
2015-07-23 11:59:47 +00:00
|
|
|
transactionReplace = REPLACE_OPTIONS.TRANSACTION,
|
2015-08-04 15:52:43 +00:00
|
|
|
eventSubProcessReplace = REPLACE_OPTIONS.EVENT_SUB_PROCESS,
|
|
|
|
boundaryEventReplace = REPLACE_OPTIONS.BOUNDARY_EVENT,
|
2015-09-29 05:58:26 +00:00
|
|
|
eventSubProcessStartEventReplace = REPLACE_OPTIONS.EVENT_SUB_PROCESS_START_EVENT,
|
|
|
|
sequenceFlowReplace = REPLACE_OPTIONS.SEQUENCE_FLOW;
|
2015-03-11 15:17:19 +00:00
|
|
|
|
2015-06-12 13:46:28 +00:00
|
|
|
var is = require('../../util/ModelUtil').is,
|
2015-06-30 15:15:22 +00:00
|
|
|
getBusinessObject = require('../../util/ModelUtil').getBusinessObject,
|
2015-08-04 15:52:43 +00:00
|
|
|
isExpanded = require('../../util/DiUtil').isExpanded,
|
|
|
|
isEventSubProcess = require('../../util/DiUtil').isEventSubProcess;
|
|
|
|
|
2015-06-12 13:46:28 +00:00
|
|
|
|
2015-07-23 11:59:47 +00:00
|
|
|
var CUSTOM_PROPERTIES = [
|
|
|
|
'cancelActivity',
|
|
|
|
'instantiate',
|
2015-08-04 15:52:43 +00:00
|
|
|
'eventGatewayType',
|
|
|
|
'triggeredByEvent',
|
|
|
|
'isInterrupting'
|
2015-07-23 11:59:47 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
/**
|
|
|
|
* A replace menu provider that gives users the controls to choose
|
|
|
|
* and replace BPMN elements with each other.
|
|
|
|
*
|
|
|
|
* @param {BpmnFactory} bpmnFactory
|
|
|
|
* @param {Moddle} moddle
|
|
|
|
* @param {PopupMenu} popupMenu
|
|
|
|
* @param {Replace} replace
|
|
|
|
*/
|
2015-12-02 15:47:20 +00:00
|
|
|
function BpmnReplace(bpmnFactory, moddle, popupMenu, replace, selection, modeling, eventBus, rules) {
|
2015-06-30 15:15:22 +00:00
|
|
|
|
2015-07-03 08:48:32 +00:00
|
|
|
var self = this,
|
|
|
|
currentElement;
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares a new business object for the replacement element
|
|
|
|
* and triggers the replace operation.
|
|
|
|
*
|
|
|
|
* @param {djs.model.Base} element
|
|
|
|
* @param {Object} target
|
2015-08-20 15:52:49 +00:00
|
|
|
* @param {Object} [hints]
|
2015-03-11 15:17:19 +00:00
|
|
|
* @return {djs.model.Base} the newly created element
|
|
|
|
*/
|
2015-08-20 15:52:49 +00:00
|
|
|
function replaceElement(element, target, hints) {
|
|
|
|
|
|
|
|
hints = hints || {};
|
2015-03-11 15:17:19 +00:00
|
|
|
|
|
|
|
var type = target.type,
|
|
|
|
oldBusinessObject = element.businessObject,
|
|
|
|
businessObject = bpmnFactory.create(type);
|
|
|
|
|
|
|
|
var newElement = {
|
|
|
|
type: type,
|
|
|
|
businessObject: businessObject
|
|
|
|
};
|
|
|
|
|
|
|
|
// initialize custom BPMN extensions
|
|
|
|
if (target.eventDefinition) {
|
|
|
|
var eventDefinitions = businessObject.get('eventDefinitions'),
|
|
|
|
eventDefinition = moddle.create(target.eventDefinition);
|
|
|
|
|
2015-11-19 12:28:39 +00:00
|
|
|
eventDefinition.$parent = businessObject;
|
2015-03-11 15:17:19 +00:00
|
|
|
eventDefinitions.push(eventDefinition);
|
|
|
|
}
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-07-23 11:59:47 +00:00
|
|
|
// initialize special properties defined in target definition
|
|
|
|
assign(businessObject, pick(target, CUSTOM_PROPERTIES));
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
// copy size (for activities only)
|
2015-06-24 09:43:07 +00:00
|
|
|
if (is(oldBusinessObject, 'bpmn:Activity')) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
// TODO: need also to respect min/max Size
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
newElement.width = element.width;
|
|
|
|
newElement.height = element.height;
|
|
|
|
}
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
if (is(oldBusinessObject, 'bpmn:SubProcess')) {
|
|
|
|
newElement.isExpanded = isExpanded(oldBusinessObject);
|
|
|
|
}
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
businessObject.name = oldBusinessObject.name;
|
2015-08-04 15:52:43 +00:00
|
|
|
|
|
|
|
// retain loop characteristics if the target element is not an event sub process
|
|
|
|
if (!isEventSubProcess(businessObject)) {
|
|
|
|
businessObject.loopCharacteristics = oldBusinessObject.loopCharacteristics;
|
|
|
|
}
|
2015-06-23 15:24:13 +00:00
|
|
|
|
2015-10-06 08:50:47 +00:00
|
|
|
// retain default flow's reference between inclusive and exclusive gateways
|
|
|
|
if ((is(oldBusinessObject, 'bpmn:ExclusiveGateway') || is(oldBusinessObject, 'bpmn:InclusiveGateway')) &&
|
|
|
|
(is(businessObject, 'bpmn:ExclusiveGateway') || is(businessObject, 'bpmn:InclusiveGateway')))
|
|
|
|
{
|
|
|
|
businessObject.default = oldBusinessObject.default;
|
|
|
|
}
|
|
|
|
|
2015-03-11 15:31:42 +00:00
|
|
|
newElement = replace.replaceElement(element, newElement);
|
|
|
|
|
2015-08-20 15:52:49 +00:00
|
|
|
if (hints.select !== false) {
|
|
|
|
selection.select(newElement);
|
|
|
|
}
|
2015-03-11 15:31:42 +00:00
|
|
|
|
|
|
|
return newElement;
|
2015-03-11 15:17:19 +00:00
|
|
|
}
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-06-30 15:15:22 +00:00
|
|
|
|
2015-07-03 08:48:32 +00:00
|
|
|
function toggleLoopEntry(event, entry) {
|
|
|
|
var loopEntries = self.getLoopEntries(currentElement);
|
2015-06-30 15:15:22 +00:00
|
|
|
|
2015-07-03 08:48:32 +00:00
|
|
|
var loopCharacteristics;
|
2015-06-12 13:46:28 +00:00
|
|
|
|
|
|
|
if (entry.active) {
|
2015-06-30 15:15:22 +00:00
|
|
|
loopCharacteristics = undefined;
|
|
|
|
} else {
|
2015-07-03 08:48:32 +00:00
|
|
|
forEach(loopEntries, function(action) {
|
2015-06-30 15:15:22 +00:00
|
|
|
var options = action.options;
|
2015-06-12 13:46:28 +00:00
|
|
|
|
2015-06-30 15:15:22 +00:00
|
|
|
if (entry.id === action.id) {
|
|
|
|
loopCharacteristics = moddle.create(options.loopCharacteristics);
|
2015-06-12 13:46:28 +00:00
|
|
|
|
2015-06-30 15:15:22 +00:00
|
|
|
if (options.isSequential) {
|
|
|
|
loopCharacteristics.isSequential = options.isSequential;
|
|
|
|
}
|
2015-06-12 13:46:28 +00:00
|
|
|
}
|
2015-06-30 15:15:22 +00:00
|
|
|
});
|
|
|
|
}
|
2015-07-03 08:48:32 +00:00
|
|
|
modeling.updateProperties(currentElement, { loopCharacteristics: loopCharacteristics });
|
2015-06-12 13:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-03 08:48:32 +00:00
|
|
|
function getLoopEntries(element) {
|
|
|
|
|
|
|
|
currentElement = element;
|
2015-06-12 13:46:28 +00:00
|
|
|
|
|
|
|
var businessObject = getBusinessObject(element),
|
|
|
|
loopCharacteristics = businessObject.loopCharacteristics;
|
|
|
|
|
|
|
|
var isSequential,
|
|
|
|
isLoop,
|
|
|
|
isParallel;
|
|
|
|
|
|
|
|
if (loopCharacteristics) {
|
|
|
|
isSequential = loopCharacteristics.isSequential;
|
|
|
|
isLoop = loopCharacteristics.isSequential === undefined;
|
|
|
|
isParallel = loopCharacteristics.isSequential !== undefined && !loopCharacteristics.isSequential;
|
|
|
|
}
|
|
|
|
|
2015-07-03 08:48:32 +00:00
|
|
|
var loopEntries = [
|
2015-06-12 13:46:28 +00:00
|
|
|
{
|
|
|
|
id: 'toggle-parallel-mi',
|
2015-11-16 14:28:18 +00:00
|
|
|
className: 'bpmn-icon-parallel-mi-marker',
|
2015-09-30 08:50:17 +00:00
|
|
|
title: 'Parallel Multi Instance',
|
2015-06-12 13:46:28 +00:00
|
|
|
active: isParallel,
|
2015-07-03 08:48:32 +00:00
|
|
|
action: toggleLoopEntry,
|
2015-06-12 13:46:28 +00:00
|
|
|
options: {
|
|
|
|
loopCharacteristics: 'bpmn:MultiInstanceLoopCharacteristics',
|
|
|
|
isSequential: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'toggle-sequential-mi',
|
2015-11-16 14:28:18 +00:00
|
|
|
className: 'bpmn-icon-sequential-mi-marker',
|
2015-09-30 08:50:17 +00:00
|
|
|
title: 'Sequential Multi Instance',
|
2015-06-12 13:46:28 +00:00
|
|
|
active: isSequential,
|
2015-07-03 08:48:32 +00:00
|
|
|
action: toggleLoopEntry,
|
2015-06-12 13:46:28 +00:00
|
|
|
options: {
|
|
|
|
loopCharacteristics: 'bpmn:MultiInstanceLoopCharacteristics',
|
|
|
|
isSequential: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'toggle-loop',
|
2015-11-16 14:28:18 +00:00
|
|
|
className: 'bpmn-icon-loop-marker',
|
2015-09-30 08:50:17 +00:00
|
|
|
title: 'Loop',
|
2015-06-12 13:46:28 +00:00
|
|
|
active: isLoop,
|
2015-07-03 08:48:32 +00:00
|
|
|
action: toggleLoopEntry,
|
2015-06-12 13:46:28 +00:00
|
|
|
options: {
|
|
|
|
loopCharacteristics: 'bpmn:StandardLoopCharacteristics'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2015-07-03 08:48:32 +00:00
|
|
|
return loopEntries;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getAdHocEntry(element) {
|
|
|
|
var businessObject = getBusinessObject(element);
|
|
|
|
|
|
|
|
var isAdHoc = is(businessObject, 'bpmn:AdHocSubProcess');
|
|
|
|
|
|
|
|
var adHocEntry = {
|
|
|
|
id: 'toggle-adhoc',
|
2015-11-16 14:28:18 +00:00
|
|
|
className: 'bpmn-icon-ad-hoc-marker',
|
2015-09-30 08:50:17 +00:00
|
|
|
title: 'Ad-hoc',
|
2015-07-03 08:48:32 +00:00
|
|
|
active: isAdHoc,
|
|
|
|
action: function(event, entry) {
|
|
|
|
if (isAdHoc) {
|
|
|
|
return replaceElement(element, { type: 'bpmn:SubProcess' });
|
|
|
|
} else {
|
|
|
|
return replaceElement(element, { type: 'bpmn:AdHocSubProcess' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-06-12 13:46:28 +00:00
|
|
|
|
2015-07-03 08:48:32 +00:00
|
|
|
return adHocEntry;
|
2015-06-12 13:46:28 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 15:19:34 +00:00
|
|
|
|
2015-10-09 23:35:14 +00:00
|
|
|
this.getReplaceOptions = function(element) {
|
2015-02-26 15:19:34 +00:00
|
|
|
|
2015-12-02 15:47:20 +00:00
|
|
|
if (!rules.allowed('shape.replace', { element: element })) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
var menuEntries = [];
|
|
|
|
var businessObject = element.businessObject;
|
2015-02-26 15:19:34 +00:00
|
|
|
|
2015-08-04 15:52:43 +00:00
|
|
|
// start events outside event sub processes
|
|
|
|
if (is(businessObject, 'bpmn:StartEvent') && !isEventSubProcess(businessObject.$parent)) {
|
2015-03-11 15:17:19 +00:00
|
|
|
addEntries(startEventReplace, filterEvents);
|
|
|
|
} else
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-08-04 15:52:43 +00:00
|
|
|
// start events inside event sub processes
|
|
|
|
if (is(businessObject, 'bpmn:StartEvent') && isEventSubProcess(businessObject.$parent)) {
|
|
|
|
addEntries(eventSubProcessStartEventReplace, filterEvents);
|
|
|
|
} else
|
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
if (is(businessObject, 'bpmn:IntermediateCatchEvent') ||
|
|
|
|
is(businessObject, 'bpmn:IntermediateThrowEvent')) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
addEntries(intermediateEventReplace, filterEvents);
|
|
|
|
} else
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
if (is(businessObject, 'bpmn:EndEvent')) {
|
2015-02-26 15:19:34 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
addEntries(endEventReplace, filterEvents);
|
|
|
|
} else
|
2015-02-26 15:19:34 +00:00
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
if (is(businessObject, 'bpmn:Gateway')) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
addEntries(gatewayReplace, function(entry) {
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
return entry.target.type !== businessObject.$type;
|
|
|
|
});
|
|
|
|
} else
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
if (is(businessObject, 'bpmn:Transaction')) {
|
|
|
|
|
2015-08-04 15:52:43 +00:00
|
|
|
addEntries(transactionReplace);
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (isEventSubProcess(businessObject) && isExpanded(businessObject)) {
|
|
|
|
|
|
|
|
addEntries(eventSubProcessReplace);
|
2015-06-24 09:43:07 +00:00
|
|
|
} else
|
|
|
|
|
2015-07-03 08:48:32 +00:00
|
|
|
if (is(businessObject, 'bpmn:SubProcess') && isExpanded(businessObject)) {
|
2015-06-24 09:43:07 +00:00
|
|
|
|
2015-08-04 15:52:43 +00:00
|
|
|
addEntries(subProcessExpandedReplace);
|
2015-06-24 09:43:07 +00:00
|
|
|
} else
|
|
|
|
|
2015-07-03 08:48:32 +00:00
|
|
|
if (is(businessObject, 'bpmn:AdHocSubProcess') && !isExpanded(businessObject)) {
|
|
|
|
addEntries(taskReplace, function(entry) {
|
|
|
|
return entry.target.type !== 'bpmn:SubProcess';
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
|
2015-07-23 11:59:47 +00:00
|
|
|
if (is(businessObject, 'bpmn:BoundaryEvent')) {
|
|
|
|
addEntries(boundaryEventReplace, filterEvents);
|
|
|
|
} else
|
|
|
|
|
2015-09-29 05:58:26 +00:00
|
|
|
if (is(businessObject, 'bpmn:SequenceFlow')) {
|
|
|
|
addSequenceFlowEntries(sequenceFlowReplace);
|
|
|
|
} else
|
|
|
|
|
2015-06-24 09:43:07 +00:00
|
|
|
if (is(businessObject, 'bpmn:FlowNode')) {
|
2015-03-11 15:17:19 +00:00
|
|
|
addEntries(taskReplace, function(entry) {
|
|
|
|
return entry.target.type !== businessObject.$type;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-09-29 05:58:26 +00:00
|
|
|
function addSequenceFlowEntries(entries) {
|
|
|
|
forEach(entries, function(entry) {
|
|
|
|
|
2015-09-30 06:28:28 +00:00
|
|
|
switch (entry.actionName) {
|
|
|
|
case 'replace-with-default-flow':
|
|
|
|
if (businessObject.sourceRef.default !== businessObject &&
|
2015-11-10 11:32:43 +00:00
|
|
|
(is(businessObject.sourceRef, 'bpmn:ExclusiveGateway') ||
|
|
|
|
is(businessObject.sourceRef, 'bpmn:InclusiveGateway'))) {
|
2015-09-30 06:28:28 +00:00
|
|
|
|
|
|
|
menuEntries.push(addMenuEntry(entry, function() {
|
|
|
|
modeling.updateProperties(element.source, { default: businessObject });
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'replace-with-conditional-flow':
|
|
|
|
if (!businessObject.conditionExpression && is(businessObject.sourceRef, 'bpmn:Activity')) {
|
|
|
|
|
|
|
|
menuEntries.push(addMenuEntry(entry, function() {
|
|
|
|
var conditionExpression = moddle.create('bpmn:FormalExpression', { body: ''});
|
|
|
|
|
|
|
|
modeling.updateProperties(element, { conditionExpression: conditionExpression });
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// default flows
|
|
|
|
if (is(businessObject.sourceRef, 'bpmn:Activity') && businessObject.conditionExpression) {
|
|
|
|
return menuEntries.push(addMenuEntry(entry, function() {
|
|
|
|
modeling.updateProperties(element, { conditionExpression: undefined });
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
// conditional flows
|
|
|
|
if ((is(businessObject.sourceRef, 'bpmn:ExclusiveGateway') ||
|
|
|
|
is(businessObject.sourceRef, 'bpmn:InclusiveGateway')) &&
|
|
|
|
businessObject.sourceRef.default === businessObject) {
|
|
|
|
|
|
|
|
return menuEntries.push(addMenuEntry(entry, function() {
|
|
|
|
modeling.updateProperties(element.source, { default: undefined });
|
|
|
|
}));
|
|
|
|
}
|
2015-09-29 05:58:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-07-03 08:48:32 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
function filterEvents(entry) {
|
|
|
|
|
|
|
|
var target = entry.target;
|
|
|
|
|
2015-08-04 15:52:43 +00:00
|
|
|
var eventDefinition = businessObject.eventDefinitions && businessObject.eventDefinitions[0].$type;
|
|
|
|
|
|
|
|
var isEventDefinitionEqual = target.eventDefinition == eventDefinition,
|
|
|
|
isEventTypeEqual = businessObject.$type == target.type;
|
|
|
|
|
|
|
|
// filter for boundary events
|
|
|
|
if (is(businessObject, 'bpmn:BoundaryEvent')) {
|
2015-09-17 07:05:09 +00:00
|
|
|
if (target.eventDefinition == 'bpmn:CancelEventDefinition' &&
|
|
|
|
!is(businessObject.attachedToRef, 'bpmn:Transaction')) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-04 15:52:43 +00:00
|
|
|
var cancelActivity = target.cancelActivity !== false;
|
|
|
|
|
|
|
|
var isCancelActivityEqual = businessObject.cancelActivity == cancelActivity;
|
2015-08-03 15:15:13 +00:00
|
|
|
|
2015-08-04 15:52:43 +00:00
|
|
|
return !(isEventDefinitionEqual && isEventTypeEqual && isCancelActivityEqual);
|
2015-08-03 15:15:13 +00:00
|
|
|
}
|
2015-07-23 11:59:47 +00:00
|
|
|
|
2015-08-04 15:52:43 +00:00
|
|
|
// filter for start events inside event sub processes
|
|
|
|
if (is(businessObject, 'bpmn:StartEvent') && isEventSubProcess(businessObject.$parent)) {
|
|
|
|
var isInterrupting = target.isInterrupting !== false;
|
|
|
|
|
|
|
|
var isInterruptingEqual = businessObject.isInterrupting == isInterrupting;
|
|
|
|
|
|
|
|
return !(isEventDefinitionEqual && isEventDefinitionEqual && isInterruptingEqual);
|
|
|
|
}
|
2015-03-11 15:17:19 +00:00
|
|
|
|
2015-09-17 07:05:09 +00:00
|
|
|
if (is(businessObject, 'bpmn:EndEvent') && target.eventDefinition == 'bpmn:CancelEventDefinition' &&
|
|
|
|
!is(businessObject.$parent, 'bpmn:Transaction')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-04 15:52:43 +00:00
|
|
|
// filter for all other elements
|
|
|
|
return (!isEventDefinitionEqual && isEventTypeEqual) || !isEventTypeEqual;
|
2015-03-11 15:17:19 +00:00
|
|
|
}
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-07-03 08:48:32 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
function addEntries(entries, filterFun) {
|
|
|
|
// Filter selected type from the array
|
|
|
|
var filteredEntries = filter(entries, filterFun);
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
// Add entries to replace menu
|
|
|
|
forEach(filteredEntries, function(definition) {
|
|
|
|
var entry = addMenuEntry(definition);
|
|
|
|
menuEntries.push(entry);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-09-29 05:58:26 +00:00
|
|
|
function addMenuEntry(definition, action) {
|
2015-03-11 15:17:19 +00:00
|
|
|
|
2015-09-29 05:58:26 +00:00
|
|
|
var menuEntry = {
|
2015-03-11 15:17:19 +00:00
|
|
|
label: definition.label,
|
|
|
|
className: definition.className,
|
2015-06-11 13:21:21 +00:00
|
|
|
id: definition.actionName,
|
2015-09-29 05:58:26 +00:00
|
|
|
action: action
|
2015-03-11 15:17:19 +00:00
|
|
|
};
|
2015-09-29 05:58:26 +00:00
|
|
|
|
|
|
|
if (!menuEntry.action) {
|
|
|
|
menuEntry.action = function() {
|
|
|
|
return replaceElement(element, definition.target);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return menuEntry;
|
2015-03-11 15:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return menuEntries;
|
2015-10-09 23:35:14 +00:00
|
|
|
};
|
2015-01-19 11:13:39 +00:00
|
|
|
|
2015-06-30 15:15:22 +00:00
|
|
|
/**
|
2015-10-09 23:35:14 +00:00
|
|
|
* Open a replace chooser for an element on the specified position.
|
|
|
|
*
|
2015-06-30 15:15:22 +00:00
|
|
|
* @param {Object} position
|
|
|
|
* @param {Object} element
|
|
|
|
*/
|
2015-03-11 15:17:19 +00:00
|
|
|
this.openChooser = function(position, element) {
|
2015-06-12 13:46:28 +00:00
|
|
|
var entries = this.getReplaceOptions(element),
|
2015-07-03 08:48:32 +00:00
|
|
|
headerEntries = [];
|
2015-06-12 13:46:28 +00:00
|
|
|
|
2015-08-04 15:52:43 +00:00
|
|
|
if (is(element, 'bpmn:Activity') && !isEventSubProcess(element)) {
|
2015-07-03 08:48:32 +00:00
|
|
|
headerEntries = headerEntries.concat(this.getLoopEntries(element));
|
2015-06-12 13:46:28 +00:00
|
|
|
}
|
2015-03-11 15:17:19 +00:00
|
|
|
|
2015-08-04 15:52:43 +00:00
|
|
|
if (is(element, 'bpmn:SubProcess') &&
|
|
|
|
!is(element, 'bpmn:Transaction') &&
|
|
|
|
!isEventSubProcess(element)) {
|
2015-07-03 08:48:32 +00:00
|
|
|
headerEntries.push(this.getAdHocEntry(element));
|
|
|
|
}
|
|
|
|
|
|
|
|
popupMenu.open({
|
|
|
|
className: 'replace-menu',
|
|
|
|
element: element,
|
|
|
|
position: position,
|
|
|
|
headerEntries: headerEntries,
|
|
|
|
entries: entries
|
|
|
|
});
|
2015-03-11 15:17:19 +00:00
|
|
|
};
|
|
|
|
|
2015-07-03 08:48:32 +00:00
|
|
|
this.getLoopEntries = getLoopEntries;
|
|
|
|
|
|
|
|
this.getAdHocEntry = getAdHocEntry;
|
2015-06-12 13:46:28 +00:00
|
|
|
|
2015-03-11 15:17:19 +00:00
|
|
|
this.replaceElement = replaceElement;
|
|
|
|
}
|
|
|
|
|
2015-12-02 15:47:20 +00:00
|
|
|
BpmnReplace.$inject = [ 'bpmnFactory', 'moddle', 'popupMenu', 'replace', 'selection', 'modeling', 'eventBus', 'rules' ];
|
2015-03-11 15:17:19 +00:00
|
|
|
|
2015-06-12 13:46:28 +00:00
|
|
|
module.exports = BpmnReplace;
|