|
4 | 4 | import org.eclipse.swt.SWT;
|
5 | 5 | import org.eclipse.swt.graphics.Point;
|
6 | 6 | import org.eclipse.swt.graphics.Rectangle;
|
| 7 | +import org.eclipse.swt.widgets.Display; |
| 8 | +import org.eclipse.swt.widgets.Event; |
7 | 9 | import org.eclipse.ui.IEditorPart;
|
8 | 10 | import org.eclipse.ui.IViewPart;
|
9 | 11 | import org.eclipse.ui.IWorkbenchPage;
|
10 | 12 | import org.eclipse.ui.IWorkbenchPart;
|
11 | 13 | import org.eclipse.ui.IWorkbenchPartReference;
|
12 |
| -import org.junit.Assert; |
13 | 14 |
|
14 | 15 | public class DragOperations {
|
15 | 16 |
|
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 |
| - */ |
23 | 17 | 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); |
25 | 34 |
|
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); |
31 | 40 |
|
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 | + }); |
34 | 47 | }
|
35 | 48 |
|
36 | 49 | /**
|
|
0 commit comments