Skip to content

Commit

Permalink
Reconnect Connection Preserves Connection in XML File
Browse files Browse the repository at this point in the history
In order to reduce the amount of changed lines in the XML file this
change ensures that reconnect connection will use the same places as the
old one. In the best case this means only source or target entry and
bendpoints are changed and such the changes are within one XML file
line. This should reduce chances for conflicts when multiple people work
on one file via version control.
  • Loading branch information
azoitl committed Oct 17, 2024
1 parent 90c499c commit 0352198
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void execute() {
connectionCreateCmd.setDestination(getNewDestination());
connectionCreateCmd.setArrangementConstraints(con.getRoutingData());
connectionCreateCmd.setVisible(con.isVisible());
connectionCreateCmd.setElementIndex(parent.getConnectionIndex(con));
connectionCreateCmd.execute(); // perform adding the connection first to preserve any error markers
deleteConnectionCmd.execute();
copyAttributes(connectionCreateCmd.getConnection(), deleteConnectionCmd.getConnection());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public abstract class AbstractConnectionCreateCommand extends Command implements

private boolean visible = true;

private int elementIndex = -1;

protected AbstractConnectionCreateCommand(final FBNetwork parent) {
// initialize values
this.parent = parent;
Expand Down Expand Up @@ -125,7 +127,7 @@ public void execute() {
connection.setDestination(destination);
connection.setRoutingData(routingData);

parent.addConnection(connection);
parent.addConnectionWithIndex(connection, elementIndex);
// visible needs to be setup after the connection is added to correctly update
// ui
connection.setVisible(visible);
Expand Down Expand Up @@ -153,7 +155,7 @@ public void undo() {
public void redo() {
connection.setSource(source);
connection.setDestination(destination);
parent.addConnection(connection);
parent.addConnectionWithIndex(connection, elementIndex);

if (null != mirroredConnection) {
mirroredConnection.redo();
Expand Down Expand Up @@ -310,4 +312,8 @@ public Set<EObject> getAffectedObjects() {
return Stream.of(parent, connection, source, destination).filter(Objects::nonNull)
.collect(Collectors.toUnmodifiableSet());
}

public void setElementIndex(final int elementIndex) {
this.elementIndex = elementIndex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,8 @@ public Set<EObject> getAffectedObjects() {
return Stream.of(connectionParent, connection, source, destination).filter(Objects::nonNull)
.collect(Collectors.toUnmodifiableSet());
}

public int getElementIndex() {
return elementIndex;
}
}

0 comments on commit 0352198

Please sign in to comment.