fix(modeling/behavior): only replace existing connections

This commit is contained in:
Nico Rehwaldt 2015-08-19 11:08:29 +02:00
parent bfa568dbca
commit 046f962244
1 changed files with 14 additions and 5 deletions

View File

@ -12,10 +12,18 @@ function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules) {
CommandInterceptor.call(this, eventBus); CommandInterceptor.call(this, eventBus);
function replaceConnection(connection) { function fixConnection(connection) {
var source = connection.source, var source = connection.source,
target = connection.target; target = connection.target,
parent = connection.parent;
// do not do anything if connection
// is already deleted (may happen due to other
// behaviors plugged-in before)
if (!parent) {
return;
}
var replacementType, var replacementType,
remove; remove;
@ -56,7 +64,8 @@ function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules) {
} }
// remove invalid connection // remove invalid connection,
// unless it has been removed already
if (remove) { if (remove) {
modeling.removeConnection(connection); modeling.removeConnection(connection);
} }
@ -76,7 +85,7 @@ function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules) {
var closure = context.closure, var closure = context.closure,
allConnections = closure.allConnections; allConnections = closure.allConnections;
forEach(allConnections, replaceConnection); forEach(allConnections, fixConnection);
}, true); }, true);
this.postExecuted([ this.postExecuted([
@ -86,7 +95,7 @@ function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules) {
var connection = event.context.connection; var connection = event.context.connection;
replaceConnection(connection); fixConnection(connection);
}); });
} }