Skip to content

Commit d62f0da

Browse files
committed
Migrate Drag-and-Drop tests to JUnit 5 and provide basic DragOperations implementation
1 parent e4f3b8f commit d62f0da

File tree

5 files changed

+167
-145
lines changed

5 files changed

+167
-145
lines changed

tests/org.eclipse.ui.tests.dnd/META-INF/MANIFEST.MF

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ Require-Bundle: org.eclipse.swt,
1616
junit-platform-suite-api;bundle-version="1.12.2"
1717
Automatic-Module-Name: org.eclipse.ui.tests.dnd
1818
Bundle-RequiredExecutionEnvironment: JavaSE-21
19-
Import-Package: org.eclipse.ui.part
19+
Import-Package: org.eclipse.e4.ui.model.application.ui.basic,
20+
org.eclipse.ui.part,
21+
org.junit.jupiter.params;version="[5.12.0,6.0.0)",
22+
org.junit.jupiter.params.provider;version="[5.12.0,6.0.0)",
23+
org.junit.platform.engine.support.descriptor;version="[1.12.0,2.0.0)"
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1+
###############################################################################
2+
# Copyright (c) 2025 Ali Muhsin KÖKSAL and others.
3+
#
4+
# This program and the accompanying materials
5+
# are made available under the terms of the Eclipse Public License 2.0
6+
# which accompanies this distribution, and is available at
7+
# https://www.eclipse.org/legal/epl-2.0/
8+
#
9+
# SPDX-License-Identifier: EPL-2.0
10+
###############################################################################
11+
112
source.. = src/
213
output.. = bin/
314
bin.includes = META-INF/,\
4-
.
15+
.,\
16+
test.xml
17+
18+
19+
# Maven properties, see https://github.com/eclipse/tycho/wiki/Tycho-Pomless
20+
pom.model.property.testClass = org.eclipse.ui.tests.dnd.DragTestSuite
21+
pom.model.property.defaultSigning-excludeInnerJars = true

tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragOperations.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,46 @@
44
import org.eclipse.swt.SWT;
55
import org.eclipse.swt.graphics.Point;
66
import org.eclipse.swt.graphics.Rectangle;
7+
import org.eclipse.swt.widgets.Display;
8+
import org.eclipse.swt.widgets.Event;
79
import org.eclipse.ui.IEditorPart;
810
import org.eclipse.ui.IViewPart;
911
import org.eclipse.ui.IWorkbenchPage;
1012
import org.eclipse.ui.IWorkbenchPart;
1113
import org.eclipse.ui.IWorkbenchPartReference;
12-
import org.junit.Assert;
1314

1415
public class DragOperations {
1516

16-
/**
17-
* Drags the given view OR editor to the given location (i.e. it only cares that we're given
18-
* a 'Part' and doesn't care whether it's a 'View' or an 'Editor'.
19-
* <p>
20-
* This method should eventually replace the original one once the Workbench has been updated
21-
* to handle Views and Editors without distincton.
22-
*/
2317
public static void drag(IWorkbenchPart part, TestDropLocation target, boolean wholeFolder) {
24-
// DragUtil.forceDropLocation(target);
18+
Display.getDefault().syncExec(() -> {
19+
Point startLocation = Display.getDefault().getCursorLocation();
20+
Point endLocation;
21+
22+
if (wholeFolder) {
23+
Rectangle bounds = part.getSite().getShell().getBounds();
24+
endLocation = new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
25+
} else {
26+
endLocation = target.getLocation();
27+
}
28+
29+
Event press = new Event();
30+
press.type = SWT.MouseDown;
31+
press.x = startLocation.x;
32+
press.y = startLocation.y;
33+
Display.getDefault().post(press);
2534

26-
// PartSite site = (PartSite) part.getSite();
27-
// PartPane pane = site.getPane();
28-
// PartStack parent = ((PartStack) (pane.getContainer()));
29-
//
30-
// parent.paneDragStart(wholeFolder ? null : pane, Display.getDefault().getCursorLocation(), false);
35+
Event move = new Event();
36+
move.type = SWT.MouseMove;
37+
move.x = endLocation.x;
38+
move.y = endLocation.y;
39+
Display.getDefault().post(move);
3140

32-
Assert.fail("DND needs some updating");
33-
// DragUtil.forceDropLocation(null);
41+
Event release = new Event();
42+
release.type = SWT.MouseUp;
43+
release.x = endLocation.x;
44+
release.y = endLocation.y;
45+
Display.getDefault().post(release);
46+
});
3447
}
3548

3649
/**

0 commit comments

Comments
 (0)