feature(rules): add modeling rules for event based gateways

closes #193
This commit is contained in:
jdotzki 2015-02-24 16:21:12 +01:00
parent 18c2b0552e
commit 66801df111
2 changed files with 49 additions and 6 deletions

View File

@ -251,7 +251,8 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
if (bpmnElement.$instanceOf('bpmn:FlowNode')) {
if (!bpmnElement.$instanceOf('bpmn:EndEvent')) {
if (!bpmnElement.$instanceOf('bpmn:EndEvent') &&
!bpmnElement.$instanceOf('bpmn:EventBasedGateway')) {
assign(actions, {
'append.end-event': appendAction('bpmn:EndEvent', 'icon-end-event'),
@ -269,6 +270,21 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
});
}
if (bpmnElement.$instanceOf('bpmn:EventBasedGateway')) {
// TODO Add Receiving Events
assign(actions, {
'append.receive-task': appendAction('bpmn:ReceiveTask', 'icon-receive'),
'connect': {
group: 'connect',
className: 'icon-connection',
action: {
click: startConnect,
dragstart: startConnect
}
}
});
}
assign(actions, {
'append.text-annotation': appendAction('bpmn:TextAnnotation', 'icon-text-annotation')
});

View File

@ -27,13 +27,40 @@ ModelingRules.prototype.init = function() {
return a === b;
}
function isEventConnectionValid(sourceBo, targetBo) {
return targetBo.$instanceOf('bpmn:StartEvent') ||
sourceBo.$instanceOf('bpmn:EndEvent');
function isEventConnectionInvalid(source, target) {
var sourceBo = source.businessObject,
targetBo = target.businessObject;
var startEventCheck = targetBo.$instanceOf('bpmn:StartEvent') ||
sourceBo.$instanceOf('bpmn:EndEvent');
var eventBasedGatewayCheck = false;
// Ensure target of event based gateway is one of:
// receive task, receiving message, timer, signal, condition event
if (sourceBo.$instanceOf('bpmn:EventBasedGateway')) {
eventBasedGatewayCheck = true;
if (targetBo.$instanceOf('bpmn:ReceiveTask')) {
eventBasedGatewayCheck = false;
} else if (targetBo.$instanceOf('bpmn:ReceiveMessageEvent')) { // ReceiveMessageEvent check name
// TODO waiting for https://github.com/bpmn-io/bpmn-js/issues/192
} else if (targetBo.$instanceOf('bpmn:ReceiveTimerEvent')) { // TimerEvent check name
// TODO waiting for https://github.com/bpmn-io/bpmn-js/issues/192
} else if (targetBo.$instanceOf('bpmn:ReceiveSignalEvent')) { // TimerEvent check name
// TODO waiting for https://github.com/bpmn-io/bpmn-js/issues/192
} else if (targetBo.$instanceOf('bpmn:ReceiveConditionEvent')) { // TimerEvent check name
// TODO waiting for https://github.com/bpmn-io/bpmn-js/issues/192
}
}
return startEventCheck || eventBasedGatewayCheck;
}
// rules
// rules
function canConnect(source, target, connection) {
if (nonExistantOrLabel(source) || nonExistantOrLabel(target)) {
@ -70,7 +97,7 @@ ModelingRules.prototype.init = function() {
// Do not allow incoming connections on StartEvents
// and outgoing connections on EndEvents
if (isEventConnectionValid(sourceBo, targetBo)) {
if (isEventConnectionInvalid(source, target)) {
return false;
}