Skip to content

Commit

Permalink
Changed MoveAndReconnnect to use gef.Point instead of swt.Point
Browse files Browse the repository at this point in the history
  • Loading branch information
sebHollersbacher authored and azoitl committed May 16, 2024
1 parent eb24b4f commit 3b4bd5f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Map;
import java.util.Set;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.fordiac.ide.model.CoordinateConverter;
import org.eclipse.fordiac.ide.model.NameRepository;
Expand All @@ -47,7 +48,6 @@
import org.eclipse.fordiac.ide.model.libraryElement.SubApp;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.swt.graphics.Point;

public class MoveAndReconnectCommand extends Command implements ScopedCommand {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Status;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.fordiac.ide.application.commands.MoveAndReconnectCommand;
Expand All @@ -33,7 +34,6 @@
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Status;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.fordiac.ide.application.commands.MoveAndReconnectCommand;
import org.eclipse.fordiac.ide.model.libraryElement.Application;
Expand All @@ -40,7 +41,6 @@
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
Expand All @@ -60,8 +60,7 @@ public Object execute(final ExecutionEvent event) throws ExecutionException {
final int destX = bounds.x;
final int destY = bounds.y + bounds.height + 20;

final MoveAndReconnectCommand cmd = new MoveAndReconnectCommand(fbelements,
new Point(destX, destY));
final MoveAndReconnectCommand cmd = new MoveAndReconnectCommand(fbelements, new Point(destX, destY));
getCommandStack(editor).execute(cmd);

// select moved elements in editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ protected Command getAddCommand(final Request request) {
final Point destination = getTranslatedAndZoomedPoint((ChangeBoundsRequest) request);

if (!fbEls.isEmpty()) {
return new MoveAndReconnectCommand(fbEls,
new org.eclipse.swt.graphics.Point(destination.x, destination.y));
return new MoveAndReconnectCommand(fbEls, new Point(destination.x, destination.y));
}
return new AddElementsToSubAppCommand(dropSubApp, editParts);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ private Command handleDragToRootRequest(final ChangeBoundsRequest request) {
final Point destination = getTranslatedAndZoomedPoint(request);
final List<FBNetworkElement> fbEls = collectFromSubappDraggedFBs(editParts, getFBNetwork());
if (!fbEls.isEmpty()) {
return new MoveAndReconnectCommand(fbEls,
new org.eclipse.swt.graphics.Point(destination.x, destination.y));
return new MoveAndReconnectCommand(fbEls, destination, (FBNetwork) getHost().getModel());
}
return createRemoveFromGroup(editParts, request);
}
Expand All @@ -168,11 +167,11 @@ private Command createRemoveFromGroup(final List<? extends EditPart> editParts,
return null;
}

protected org.eclipse.draw2d.geometry.Point getTranslatedAndZoomedPoint(final ChangeBoundsRequest request) {
protected Point getTranslatedAndZoomedPoint(final ChangeBoundsRequest request) {
final FigureCanvas viewerControl = (FigureCanvas) getTargetEditPart(request).getViewer().getControl();
final org.eclipse.draw2d.geometry.Point location = viewerControl.getViewport().getViewLocation();
return new org.eclipse.draw2d.geometry.Point(request.getLocation().x + location.x,
request.getLocation().y + location.y).scale(1.0 / getZoomManager().getZoom());
final Point location = viewerControl.getViewport().getViewLocation();
return new Point(request.getLocation().x + location.x, request.getLocation().y + location.y)
.scale(1.0 / getZoomManager().getZoom());
}

private static List<FBNetworkElement> collectFromSubappDraggedFBs(final List<? extends EditPart> editParts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Collection;
import java.util.List;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.fordiac.ide.model.commands.create.AbstractConnectionCreateCommand;
import org.eclipse.fordiac.ide.model.commands.create.ConnectionCommandsTest;
import org.eclipse.fordiac.ide.model.commands.create.DataConnectionCreateCommand;
Expand All @@ -28,7 +29,6 @@
import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement;
import org.eclipse.fordiac.ide.model.libraryElement.InterfaceList;
import org.eclipse.fordiac.ide.model.libraryElement.SubApp;
import org.eclipse.swt.graphics.Point;
import org.junit.jupiter.params.provider.Arguments;

public class MoveElementsFromSubAppCommandTest extends FBNetworkTestBase {
Expand Down Expand Up @@ -62,8 +62,7 @@ private static void verifyInitialState(final State s, final State o, final TestF
private static State moveFB(final State s) {
final SubApp sub = (SubApp) s.getFbNetwork().getNetworkElements().get(0);
final FBNetworkElement elem = sub.getSubAppNetwork().getNetworkElements().get(0);
s.setCommand(
new MoveAndReconnectCommand(Arrays.asList(elem), new Point(0, 0)));
s.setCommand(new MoveAndReconnectCommand(Arrays.asList(elem), new Point(0, 0)));
return commandExecution(s);
}

Expand Down Expand Up @@ -147,8 +146,8 @@ protected static Collection<Arguments> data() {
new ExecutionDescription<>("move Functionblock from SubApp", //$NON-NLS-1$
MoveElementsFromSubAppCommandTest::moveFB, //
MoveElementsFromSubAppCommandTest::verifyMoveFB //
)) //
));
)) //
));

a.addAll(describeCommand("Start with two FBs in SubAppNetwork", //$NON-NLS-1$
MoveElementsFromSubAppCommandTest::initState, //
Expand All @@ -157,16 +156,16 @@ protected static Collection<Arguments> data() {
new ExecutionDescription<>("Create Data Connections", //$NON-NLS-1$
MoveElementsFromSubAppCommandTest::addDataConnection, //
MoveElementsFromSubAppCommandTest::verifyDataConnection //
), //
), //
new ExecutionDescription<>("Create Event Connections", //$NON-NLS-1$
MoveElementsFromSubAppCommandTest::addEventConnection, //
MoveElementsFromSubAppCommandTest::verifyEventConnection //
), //
), //
new ExecutionDescription<>("move Functionblock from SubApp", //$NON-NLS-1$
MoveElementsFromSubAppCommandTest::moveFB, //
MoveElementsFromSubAppCommandTest::verifyMoveFBwithConnections //
)) //
));
)) //
));

return a;
}
Expand Down

0 comments on commit 3b4bd5f

Please sign in to comment.