Skip to content

Commit

Permalink
Added move and reconnect from application network
Browse files Browse the repository at this point in the history
Also fixed ClassCast error when reconnecting
  • Loading branch information
sebHollersbacher authored and oberlehner committed May 7, 2024
1 parent 9903a3e commit 28454b0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
1 change: 0 additions & 1 deletion plugins/org.eclipse.fordiac.ide.application/plugin.xml
Expand Up @@ -1204,7 +1204,6 @@
</and>
<test property="org.eclipse.fordiac.ide.application.properties.parentIsSubApp" />
</or>
<test property="org.eclipse.fordiac.ide.application.utilities.isSubapplication" />
</and>
</visibleWhen>
</command>
Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.fordiac.ide.model.libraryElement.FBNetwork;
import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement;
import org.eclipse.fordiac.ide.model.libraryElement.Group;
import org.eclipse.fordiac.ide.model.libraryElement.LibraryElementFactory;
import org.eclipse.fordiac.ide.model.libraryElement.Position;
import org.eclipse.fordiac.ide.model.libraryElement.SubApp;
import org.eclipse.gef.commands.Command;
Expand All @@ -50,7 +51,7 @@

public class MoveAndReconnectCommand extends Command implements ScopedCommand {

protected final SubApp sourceSubApp;
protected final FBNetwork sourceNetwork;
private Position destination;
private final FBNetwork destinationNetwork;
protected final List<FBNetworkElement> elements;
Expand All @@ -70,28 +71,29 @@ public MoveAndReconnectCommand(final Collection<FBNetworkElement> elements, fina
final FBNetwork destinationNetwork) {
this.elements = new ArrayList<>(elements);
setDestination(destination);
this.sourceSubApp = getSourceSubapp();
this.sourceNetwork = getSourceNetwork();
if (destinationNetwork == null) {
this.destinationNetwork = sourceSubApp != null ? sourceSubApp.getFbNetwork() : null;
if (sourceNetwork != null && sourceNetwork.eContainer() instanceof final SubApp subapp) {
this.destinationNetwork = subapp.getFbNetwork();
} else {
this.destinationNetwork = null;
}
} else {
this.destinationNetwork = destinationNetwork;
}
}

private SubApp getSourceSubapp() {
if (!elements.isEmpty() && (elements.get(0).getOuterFBNetworkElement() instanceof final SubApp fbel)) {
return fbel;
}
return null;
private FBNetwork getSourceNetwork() {
return elements.isEmpty() ? null : elements.get(0).getFbNetwork();
}

@Override
public boolean canExecute() {
return (null != sourceSubApp) && allElementsFromSameSubApp();
return (null != destinationNetwork) && allElementsFromSameNetwork();
}

private boolean allElementsFromSameSubApp() {
return elements.stream().allMatch(el -> sourceSubApp.equals(el.getOuterFBNetworkElement()));
private boolean allElementsFromSameNetwork() {
return elements.stream().allMatch(el -> sourceNetwork.equals(el.getFbNetwork()));
}

@Override
Expand Down Expand Up @@ -132,7 +134,7 @@ private void removeElementFromSubapp(final FBNetworkElement element) {
unmappingCmds.add(cmd);
}
}
sourceSubApp.getSubAppNetwork().getNetworkElements().remove(element);
sourceNetwork.getNetworkElements().remove(element);
}

protected void addElementsToDestination() {
Expand Down Expand Up @@ -179,7 +181,7 @@ protected void redoRemoveElementsFromSubapp() {
}

private void redoRemoveElementFromSubapp(final FBNetworkElement element) {
sourceSubApp.getSubAppNetwork().getNetworkElements().remove(element);
sourceNetwork.getNetworkElements().remove(element);
}

protected void redoAddElementsToDestination() {
Expand Down Expand Up @@ -210,13 +212,13 @@ protected void undoRemoveElementsFromSubapp() {

private void undoRemoveElementFromSubapp(final FBNetworkElement element) {
newPos.put(element, element.getPosition());
sourceSubApp.getSubAppNetwork().getNetworkElements().add(element);
sourceNetwork.getNetworkElements().add(element);
}

protected void undoAddElementsToDestination() {
setUniqueName.undo();
elements.forEach(this::undoAddElementToDestination);
connsMovedToParent.forEach(sourceSubApp.getFbNetwork()::addConnection);
connsMovedToParent.forEach(sourceNetwork::addConnection);
}

private void undoAddElementToDestination(final FBNetworkElement element) {
Expand All @@ -230,7 +232,11 @@ public List<FBNetworkElement> getElements() {

private void positionElements() {
if (null == destination) {
destination = sourceSubApp.getPosition();
if (destinationNetwork.eContainer() instanceof final SubApp subapp) {
destination = subapp.getPosition();
} else {
destination = LibraryElementFactory.eINSTANCE.createPosition();
}
}
FBNetworkHelper.moveFBNetworkToDestination(elements, destination);
}
Expand Down Expand Up @@ -264,8 +270,8 @@ protected final void setDestination(final Point destination) {

@Override
public Set<EObject> getAffectedObjects() {
if (sourceSubApp != null && destinationNetwork != null) {
return Set.of(sourceSubApp, destinationNetwork);
if (sourceNetwork != null && destinationNetwork != null) {
return Set.of(sourceNetwork, destinationNetwork);
}
return Set.of();
}
Expand Down
Expand Up @@ -13,16 +13,16 @@
package org.eclipse.fordiac.ide.fbtypeeditor.network.viewer;

import org.eclipse.fordiac.ide.application.editparts.ConnectionEditPart;
import org.eclipse.fordiac.ide.gef.policies.FeedbackConnectionEndpointEditPolicy;
import org.eclipse.fordiac.ide.application.policies.FBNConnectionEndpointPolicy;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.requests.ReconnectRequest;

public class ConnectionEditPartRO extends ConnectionEditPart {
@Override
protected void createEditPolicies() {
installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE, new FeedbackConnectionEndpointEditPolicy() {
installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE, new FBNConnectionEndpointPolicy() {
@Override
protected void showConnectionMoveFeedback(ReconnectRequest request) {
protected void showConnectionMoveFeedback(final ReconnectRequest request) {
// we do not want to allow moving viewer connections
}
});
Expand Down

0 comments on commit 28454b0

Please sign in to comment.