Skip to content

Commit

Permalink
crossing reconnect improvements
Browse files Browse the repository at this point in the history
Border crossing reconnect now also processes sources which leads to the cleanup of unused connections and more suitable connection endpoints.
  • Loading branch information
lindhuber authored and oberlehner committed Apr 22, 2024
1 parent 89f4472 commit 97c5e7c
Showing 1 changed file with 29 additions and 14 deletions.
Expand Up @@ -45,25 +45,25 @@ public BorderCrossingReconnectCommand(final IInterfaceElement source, final IInt
this.connection = connection;
this.isSourceReconnect = isSourceReconnect;

if (isSourceReconnect) {
initSourceReconnect();
} else {
initTargetReconnect();
}
init();
}

private void initSourceReconnect() {
private void init() {
final var sinks = new ArrayList<IInterfaceElement>();
final var sources = new ArrayList<IInterfaceElement>();
collectSinksRec(connection, this, sinks);
for (final var sink : sinks) {
add(CreateSubAppCrossingConnectionsCommand.createProcessBorderCrossingConnection(source, sink));
}
}
collectSourcesRec(connection, this, sources);
sources.add(source);

private void initTargetReconnect() {
add(new DeleteConnectionCommand(connection));
add(CreateSubAppCrossingConnectionsCommand.createProcessBorderCrossingConnection(connection.getSource(),
target));
if (isSourceReconnect) {
for (final var sink : sinks) {
add(CreateSubAppCrossingConnectionsCommand.createProcessBorderCrossingConnection(source, sink));
}
} else {
for (final var source : sources) {
add(CreateSubAppCrossingConnectionsCommand.createProcessBorderCrossingConnection(source, target));
}
}
}

private static void collectSinksRec(final Connection conn, final CompoundCommand cmd,
Expand All @@ -82,6 +82,21 @@ private static void collectSinksRec(final Connection conn, final CompoundCommand
}
}

private static void collectSourcesRec(final Connection conn, final CompoundCommand cmd,
final List<IInterfaceElement> sources) {
if (isEpxandedSubapp(conn.getSource())) {
final var source = conn.getSource();
if (source.getOutputConnections().size() == 1) {
for (final var outConn : source.getInputConnections()) {
collectSourcesRec(outConn, cmd, sources);
}
cmd.add(new DeleteInterfaceCommand(source));
}
} else {
sources.add(conn.getSource());
}
}

private static boolean isEpxandedSubapp(final IInterfaceElement ie) {
return ie.getFBNetworkElement() instanceof final SubApp subapp && subapp.isUnfolded();
}
Expand Down

0 comments on commit 97c5e7c

Please sign in to comment.