Skip to content

Commit 7470cf0

Browse files
committed
Fix: Add DnD Tests, use IWorkbenchWindow/IWorkbenchPage, add copyright headers
1 parent 93e7d58 commit 7470cf0

27 files changed

+1140
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
9+
<classpathentry kind="src" path="src">
10+
<attributes>
11+
<attribute name="test" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="output" path="bin"/>
15+
</classpath>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
3+
org.eclipse.jdt.core.compiler.compliance=21
4+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
5+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
8+
org.eclipse.jdt.core.compiler.release=enabled
9+
org.eclipse.jdt.core.compiler.source=21
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: Dnd
4+
Bundle-SymbolicName: org.eclipse.ui.tests.dnd
5+
Bundle-Version: 1.0.0.qualifier
6+
Require-Bundle: org.eclipse.swt,
7+
org.eclipse.jface,
8+
org.junit;bundle-version="4.13.2",
9+
org.eclipse.ui;bundle-version="3.207.300",
10+
org.eclipse.ui.tests;bundle-version="3.15.2100",
11+
org.eclipse.ui.workbench.texteditor;bundle-version="3.19.300",
12+
org.eclipse.core.runtime;bundle-version="3.33.100",
13+
org.eclipse.core.resources;bundle-version="3.22.200",
14+
org.eclipse.ui.tests.harness;bundle-version="1.10.600",
15+
junit-jupiter-api;bundle-version="5.12.2",
16+
junit-platform-suite-api;bundle-version="1.12.2"
17+
Automatic-Module-Name: org.eclipse.ui.tests.dnd
18+
Bundle-RequiredExecutionEnvironment: JavaSE-21
19+
Import-Package: org.eclipse.ui.part
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source.. = src/
2+
output.. = bin/
3+
bin.includes = META-INF/,\
4+
.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2004, 2005 IBM Corporation 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+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
15+
package org.eclipse.ui.tests.dnd;
16+
17+
import org.eclipse.swt.graphics.Point;
18+
import org.eclipse.swt.widgets.Shell;
19+
20+
public class DetachedDropTarget implements TestDropLocation {
21+
22+
@Override
23+
public String toString() {
24+
return "out of the window";
25+
}
26+
27+
@Override
28+
public Point getLocation() {
29+
return new Point(0,0);
30+
}
31+
32+
@Override
33+
public Shell[] getShells() {
34+
return new Shell[0];
35+
}
36+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.eclipse.ui.tests.dnd;
2+
3+
import org.eclipse.ui.IViewPart;
4+
5+
public class DetachedWindowDragTest extends DragTest {
6+
7+
public DetachedWindowDragTest(TestDragSource dragSource,
8+
TestDropLocation dropTarget) {
9+
super(dragSource, dropTarget);
10+
}
11+
12+
@Override
13+
public void doSetUp() throws Exception {
14+
super.doSetUp();
15+
16+
page.showView(DragDropPerspectiveFactory.dropViewId2);
17+
page.showView(DragDropPerspectiveFactory.dropViewId1);
18+
page.showView(DragDropPerspectiveFactory.dropViewId3);
19+
20+
IViewPart viewPart = page.showView(DragDropPerspectiveFactory.dropViewId1);
21+
DragOperations.drag(viewPart, new DetachedDropTarget(), true);
22+
23+
viewPart = page.showView(DragDropPerspectiveFactory.dropViewId3);
24+
DragOperations.drag(viewPart, new DetachedDropTarget(), false);
25+
}
26+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.eclipse.ui.tests.dnd;
2+
3+
import org.eclipse.ui.IFolderLayout;
4+
import org.eclipse.ui.IPageLayout;
5+
import org.eclipse.ui.IPerspectiveFactory;
6+
import org.eclipse.ui.IPlaceholderFolderLayout;
7+
8+
public class DragDropPerspectiveFactory implements IPerspectiveFactory {
9+
10+
// Id's needed by the 'Detached Window' Drag / Drop tests
11+
public static final String viewFolderId = "oorg.eclipse.ui.test.dnd.detached.MockFolder1";
12+
13+
public static final String dropViewId1 = "org.eclipse.ui.tests.api.MockViewPart";
14+
public static final String dropViewId2 = "org.eclipse.ui.tests.api.MockViewPart2";
15+
public static final String dropViewId3 = "org.eclipse.ui.tests.api.MockViewPart3";
16+
17+
@Override
18+
public void createInitialLayout(IPageLayout layout) {
19+
String folderId = "org.eclipse.ui.test.dnd.mystack";
20+
21+
IFolderLayout folder = layout.createFolder(folderId,
22+
IPageLayout.BOTTOM, 0.5f, IPageLayout.ID_EDITOR_AREA);
23+
folder.addView(IPageLayout.ID_OUTLINE);
24+
folder.addView(IPageLayout.ID_PROBLEM_VIEW);
25+
folder.addView(IPageLayout.ID_PROP_SHEET);
26+
27+
layout.addView(IPageLayout.ID_PROBLEM_VIEW, IPageLayout.LEFT, 0.5f,
28+
IPageLayout.ID_EDITOR_AREA);
29+
30+
// Extra stacks and views that will be shown and detached during the 'Detached Window' tests
31+
IPlaceholderFolderLayout folder2 = layout.createPlaceholderFolder(viewFolderId,
32+
IPageLayout.RIGHT, 0.5f, IPageLayout.ID_EDITOR_AREA);
33+
folder2.addPlaceholder(dropViewId1);
34+
folder2.addPlaceholder(dropViewId2);
35+
36+
layout.addPlaceholder(dropViewId3, IPageLayout.BOTTOM, 0.5f, viewFolderId);
37+
}
38+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.eclipse.ui.tests.dnd;
2+
3+
import org.eclipse.jface.util.Geometry;
4+
import org.eclipse.swt.SWT;
5+
import org.eclipse.swt.graphics.Point;
6+
import org.eclipse.swt.graphics.Rectangle;
7+
import org.eclipse.ui.IEditorPart;
8+
import org.eclipse.ui.IViewPart;
9+
import org.eclipse.ui.IWorkbenchPage;
10+
import org.eclipse.ui.IWorkbenchPart;
11+
import org.eclipse.ui.IWorkbenchPartReference;
12+
import org.junit.Assert;
13+
14+
public class DragOperations {
15+
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+
@SuppressWarnings("unused")
24+
public static void drag(IWorkbenchPart part, TestDropLocation target, boolean wholeFolder) {
25+
// DragUtil.forceDropLocation(target);
26+
27+
// PartSite site = (PartSite) part.getSite();
28+
// PartPane pane = site.getPane();
29+
// PartStack parent = ((PartStack) (pane.getContainer()));
30+
//
31+
// parent.paneDragStart(wholeFolder ? null : pane, Display.getDefault().getCursorLocation(), false);
32+
33+
Assert.fail("DND needs some updating");
34+
// DragUtil.forceDropLocation(null);
35+
}
36+
37+
/**
38+
* Returns the name of the given editor
39+
*/
40+
public static String getName(IEditorPart editor) {
41+
IWorkbenchPage page = editor.getSite().getPage();
42+
IWorkbenchPartReference ref = page.getReference(editor);
43+
return ref.getPartName();
44+
}
45+
46+
public static Rectangle getDisplayBounds() {
47+
return new Rectangle(0, 0, 0, 0);
48+
}
49+
50+
public static Point getLocation(int side) {
51+
return DragOperations.getPoint(getDisplayBounds(), side);
52+
}
53+
54+
public static Point getPointInEditorArea() {
55+
return new Point(0, 0);
56+
}
57+
58+
public static Point getPoint(Rectangle bounds, int side) {
59+
Point centerPoint = Geometry.centerPoint(bounds);
60+
61+
switch (side) {
62+
case SWT.TOP:
63+
return new Point(centerPoint.x, bounds.y + 1);
64+
case SWT.BOTTOM:
65+
return new Point(centerPoint.x, bounds.y + bounds.height - 1);
66+
case SWT.LEFT:
67+
return new Point(bounds.x + 1, centerPoint.y);
68+
case SWT.RIGHT:
69+
return new Point(bounds.x + bounds.width - 1, centerPoint.y);
70+
}
71+
72+
return centerPoint;
73+
}
74+
75+
public static String nameForConstant(int swtSideConstant) {
76+
switch (swtSideConstant) {
77+
case SWT.TOP:
78+
return "top";
79+
case SWT.BOTTOM:
80+
return "bottom";
81+
case SWT.LEFT:
82+
return "left";
83+
case SWT.RIGHT:
84+
return "right";
85+
}
86+
87+
return "center";
88+
}
89+
90+
public static String getName(IViewPart targetPart) {
91+
return targetPart.getTitle();
92+
}
93+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Ali Muhsin KÖKSAL.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* Contributors:
9+
* Ali Muhsin KÖKSAL - initial API and implementation
10+
*******************************************************************************/
11+
12+
package org.eclipse.ui.tests.dnd;
13+
14+
import org.eclipse.core.resources.IFile;
15+
import org.eclipse.core.resources.IProject;
16+
import org.eclipse.swt.SWT;
17+
import org.eclipse.swt.widgets.Display;
18+
import org.eclipse.swt.widgets.Shell;
19+
import org.eclipse.ui.IEditorPart;
20+
import org.eclipse.ui.IWorkbenchPage;
21+
import org.eclipse.ui.IWorkbenchWindow;
22+
import org.eclipse.ui.PlatformUI;
23+
import org.eclipse.ui.internal.WorkbenchPage;
24+
import org.eclipse.ui.part.FileEditorInput;
25+
import org.eclipse.ui.tests.api.MockEditorPart;
26+
import org.eclipse.ui.tests.harness.util.FileUtil;
27+
import org.junit.jupiter.api.AfterEach;
28+
import org.junit.jupiter.api.DisplayName;
29+
import org.junit.jupiter.api.Test;
30+
31+
public class DragTest {
32+
33+
TestDragSource dragSource;
34+
TestDropLocation dropTarget;
35+
36+
static IProject project;
37+
static IFile file1, file2, file3;
38+
39+
IEditorPart editor1, editor2, editor3;
40+
41+
static IWorkbenchWindow window;
42+
static IWorkbenchPage page;
43+
44+
public DragTest(TestDragSource dragSource, TestDropLocation dropTarget) {
45+
this.dragSource = dragSource;
46+
this.dropTarget = dropTarget;
47+
}
48+
49+
@AfterEach
50+
public void doSetUp() throws Exception {
51+
if (window == null) {
52+
window = (IWorkbenchWindow) PlatformUI.getWorkbench();
53+
page = (IWorkbenchPage) window.getActivePage();
54+
55+
project = FileUtil.createProject("DragTest");
56+
file1 = FileUtil.createFile("DragTest1.txt", project);
57+
file2 = FileUtil.createFile("DragTest2.txt", project);
58+
file3 = FileUtil.createFile("DragTest3.txt", project);
59+
}
60+
61+
page.resetPerspective();
62+
page.closeAllEditors(false);
63+
64+
page.showView("org.eclipse.ui.views.ContentOutline");
65+
page.hideView(page.findView("org.eclipse.ui.internal.introview"));
66+
editor1 = page.openEditor(new FileEditorInput(file1), MockEditorPart.ID1);
67+
editor2 = page.openEditor(new FileEditorInput(file2), MockEditorPart.ID2);
68+
editor3 = page.openEditor(new FileEditorInput(file3), MockEditorPart.ID2);
69+
70+
window.getShell().setActive();
71+
DragOperations.drag(editor2, new EditorDropTarget(new ExistingWindowProvider(window), 0, SWT.CENTER), false);
72+
DragOperations.drag(editor3, new EditorAreaDropTarget(new ExistingWindowProvider(window), SWT.RIGHT), false);
73+
}
74+
75+
@Test
76+
@DisplayName("drag editor2 to right")
77+
public void stallTest() {
78+
String[] testNames = {};
79+
boolean testNameMatches = false;
80+
for (String testName : testNames) {
81+
if (testName.equals("drag editor2 to right")) {
82+
testNameMatches = true;
83+
break;
84+
}
85+
}
86+
87+
if (testNames.length == 0 || testNameMatches) {
88+
Display display = Display.getCurrent();
89+
Shell loopShell = new Shell(display, SWT.SHELL_TRIM);
90+
loopShell.setBounds(0, 0, 200, 100);
91+
loopShell.setText("Test Stall Shell");
92+
loopShell.setVisible(true);
93+
94+
while (loopShell != null && !loopShell.isDisposed()) {
95+
if (!display.readAndDispatch()) {
96+
display.sleep();
97+
}
98+
}
99+
}
100+
}
101+
102+
@Test
103+
public void performTest() throws Throwable {
104+
dragSource.setPage((WorkbenchPage) page);
105+
dragSource.drag(dropTarget);
106+
}
107+
}

0 commit comments

Comments
 (0)