Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable seamless connections between graphical editors #528

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ protected boolean handleButtonUp(final int which) {
protected boolean handleDrag() {
if (isInState(PAN_IN_PROGRESS) && (getCurrentViewer().getControl() instanceof FigureCanvas)) {
final FigureCanvas canvas = (FigureCanvas) getCurrentViewer().getControl();
canvas.scrollTo(viewLocation.x - getDragMoveDelta().width, viewLocation.y - getDragMoveDelta().height);
// canvas.scrollTo(viewLocation.x - getDragMoveDelta().width, viewLocation.y -
// getDragMoveDelta().height);
return true;
}
return super.handleDrag();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@
*******************************************************************************/
package org.eclipse.fordiac.ide.gef.tools;

import java.util.Objects;
import java.util.stream.Stream;

import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.fordiac.ide.gef.figures.HideableConnection;
import org.eclipse.fordiac.ide.gef.router.MoveableRouter;
import org.eclipse.fordiac.ide.model.commands.create.AbstractConnectionCreateCommand;
import org.eclipse.fordiac.ide.model.ui.editors.AdvancedScrollingGraphicalViewer;
import org.eclipse.fordiac.ide.ui.UIPlugin;
import org.eclipse.fordiac.ide.ui.preferences.ConnectionPreferenceValues;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.tools.ConnectionDragCreationTool;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

public class FordiacConnectionDragCreationTool extends ConnectionDragCreationTool {

Expand All @@ -51,11 +57,11 @@ public void deactivate() {
@Override
public void mouseDrag(final MouseEvent me, final EditPartViewer viewer) {
if (isActive() && viewer instanceof final AdvancedScrollingGraphicalViewer advViewer) {
advViewer.checkScrollPositionDuringDragBounded(me,
new Point(MoveableRouter.MIN_CONNECTION_FB_DISTANCE_SCREEN
+ HideableConnection.BEND_POINT_BEVEL_SIZE + ConnectionPreferenceValues.HANDLE_SIZE,
ConnectionPreferenceValues.HANDLE_SIZE));
CanvasHelper.bindToContentPane(me, advViewer, NEW_CONNECTION_CANVAS_BORDER);
// advViewer.checkScrollPositionDuringDragBounded(me,
// new Point(MoveableRouter.MIN_CONNECTION_FB_DISTANCE_SCREEN
// + HideableConnection.BEND_POINT_BEVEL_SIZE + ConnectionPreferenceValues.HANDLE_SIZE,
// ConnectionPreferenceValues.HANDLE_SIZE));
// CanvasHelper.bindToContentPane(me, advViewer, NEW_CONNECTION_CANVAS_BORDER);
}
super.mouseDrag(me, viewer);
}
Expand Down Expand Up @@ -99,4 +105,55 @@ private static void stopHover() {
UIPlugin.getDefault().getEMH().setHover(false);
}

@Override
protected boolean updateTargetUnderMouse() {
if (isTargetLocked()) {
return false;
}
final EditPartViewer currentViewer = getCurrentViewer();
final EditPartViewer actualViewer = findViewer(getLocation().getSWTPoint(), currentViewer);
if (actualViewer != currentViewer) {
final Point actualLocation = convertCoordinates(getLocation().getSWTPoint(), currentViewer, actualViewer);
EditPart editPart = actualViewer.findObjectAtExcluding(
new org.eclipse.draw2d.geometry.Point(actualLocation), getExclusionSet(),
getTargetingConditional());
if (editPart != null) {
editPart = editPart.getTargetEditPart(getTargetRequest());
}
final boolean changed = getTargetEditPart() != editPart;
setTargetEditPart(editPart);
return changed;
}
return super.updateTargetUnderMouse();
}

private static EditPartViewer findViewer(final Point point, final EditPartViewer viewer) {
if (viewer == null) {
return null;
}
if (viewer.getControl().getBounds().contains(point)) {
return viewer;
}
final Point absolute = viewer.getControl().toDisplay(point);
return Stream.of(PlatformUI.getWorkbench().getWorkbenchWindows())
.flatMap(window -> Stream.of(window.getPages())).flatMap(page -> Stream.of(page.getEditorReferences()))
.map(ref -> ref.getEditor(false)).filter(Objects::nonNull)
.<EditPartViewer>map(editor -> editor.getAdapter(GraphicalViewer.class)).filter(Objects::nonNull)
.filter(candidate -> containsAbsolutePoint(candidate, absolute)).findAny().orElse(viewer);
}

private static boolean containsAbsolutePoint(final EditPartViewer viewer, final Point point) {
final Control control = viewer.getControl();
if (control.getParent() != null) {
return control.getBounds().contains(control.getParent().toControl(point));
}
return control.getBounds().contains(point);
}

private static Point convertCoordinates(final Point point, final EditPartViewer from, final EditPartViewer to) {
if (from == to) {
return point;
}
return to.getControl().toControl(from.getControl().toDisplay(point.x, point.y));
}
}
Loading