Skip to content

Commit 8efa777

Browse files
committed
Add DnD Tests
1 parent b9d8b69 commit 8efa777

28 files changed

+1187
-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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>org.eclipse.ui.tests.dnd</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.pde.PluginNature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
</natures>
28+
</projectDescription>
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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
package org.eclipse.ui.tests.dnd;
15+
16+
import org.eclipse.swt.graphics.Point;
17+
import org.eclipse.swt.widgets.Shell;
18+
19+
public class DetachedDropTarget implements TestDropLocation {
20+
21+
@Override
22+
public String toString() {
23+
return "out of the window";
24+
}
25+
26+
@Override
27+
public Point getLocation() {
28+
return new Point(0,0);
29+
}
30+
31+
@Override
32+
public Shell[] getShells() {
33+
return new Shell[0];
34+
}
35+
}
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
/**
9+
* @since 3.0
10+
*/
11+
public class DragDropPerspectiveFactory implements IPerspectiveFactory {
12+
13+
// Id's needed by the 'Detached Window' Drag / Drop tests
14+
public static final String viewFolderId = "oorg.eclipse.ui.test.dnd.detached.MockFolder1";
15+
16+
public static final String dropViewId1 = "org.eclipse.ui.tests.api.MockViewPart";
17+
public static final String dropViewId2 = "org.eclipse.ui.tests.api.MockViewPart2";
18+
public static final String dropViewId3 = "org.eclipse.ui.tests.api.MockViewPart3";
19+
20+
@Override
21+
public void createInitialLayout(IPageLayout layout) {
22+
String folderId = "org.eclipse.ui.test.dnd.mystack";
23+
24+
IFolderLayout folder = layout.createFolder(folderId,
25+
IPageLayout.BOTTOM, 0.5f, IPageLayout.ID_EDITOR_AREA);
26+
folder.addView(IPageLayout.ID_OUTLINE);
27+
folder.addView(IPageLayout.ID_PROBLEM_VIEW);
28+
folder.addView(IPageLayout.ID_PROP_SHEET);
29+
30+
layout.addView(IPageLayout.ID_PROBLEM_VIEW, IPageLayout.LEFT, 0.5f,
31+
IPageLayout.ID_EDITOR_AREA);
32+
33+
// Extra stacks and views that will be shown and detached during the 'Detached Window' tests
34+
IPlaceholderFolderLayout folder2 = layout.createPlaceholderFolder(viewFolderId,
35+
IPageLayout.RIGHT, 0.5f, IPageLayout.ID_EDITOR_AREA);
36+
folder2.addPlaceholder(dropViewId1);
37+
folder2.addPlaceholder(dropViewId2);
38+
39+
layout.addPlaceholder(dropViewId3, IPageLayout.BOTTOM, 0.5f, viewFolderId);
40+
}
41+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
/**
15+
* @since 3.0
16+
*/
17+
public class DragOperations {
18+
19+
/**
20+
* Drags the given view OR editor to the given location (i.e. it only cares that we're given
21+
* a 'Part' and doesn't care whether it's a 'View' or an 'Editor'.
22+
* <p>
23+
* This method should eventually replace the original one once the Workbench has been updated
24+
* to handle Views and Editors without distincton.
25+
*/
26+
@SuppressWarnings("unused")
27+
public static void drag(IWorkbenchPart part, TestDropLocation target, boolean wholeFolder) {
28+
// DragUtil.forceDropLocation(target);
29+
30+
// PartSite site = (PartSite) part.getSite();
31+
// PartPane pane = site.getPane();
32+
// PartStack parent = ((PartStack) (pane.getContainer()));
33+
//
34+
// parent.paneDragStart(wholeFolder ? null : pane, Display.getDefault().getCursorLocation(), false);
35+
36+
Assert.fail("DND needs some updating");
37+
// DragUtil.forceDropLocation(null);
38+
}
39+
40+
/**
41+
* Returns the name of the given editor
42+
*/
43+
public static String getName(IEditorPart editor) {
44+
IWorkbenchPage page = editor.getSite().getPage();
45+
IWorkbenchPartReference ref = page.getReference(editor);
46+
return ref.getPartName();
47+
}
48+
49+
public static Rectangle getDisplayBounds() {
50+
return new Rectangle(0, 0, 0, 0);
51+
}
52+
53+
public static Point getLocation(int side) {
54+
return DragOperations.getPoint(getDisplayBounds(), side);
55+
}
56+
57+
public static Point getPointInEditorArea() {
58+
return new Point(0, 0);
59+
}
60+
61+
public static Point getPoint(Rectangle bounds, int side) {
62+
Point centerPoint = Geometry.centerPoint(bounds);
63+
64+
switch (side) {
65+
case SWT.TOP:
66+
return new Point(centerPoint.x, bounds.y + 1);
67+
case SWT.BOTTOM:
68+
return new Point(centerPoint.x, bounds.y + bounds.height - 1);
69+
case SWT.LEFT:
70+
return new Point(bounds.x + 1, centerPoint.y);
71+
case SWT.RIGHT:
72+
return new Point(bounds.x + bounds.width - 1, centerPoint.y);
73+
}
74+
75+
return centerPoint;
76+
}
77+
78+
public static String nameForConstant(int swtSideConstant) {
79+
switch (swtSideConstant) {
80+
case SWT.TOP:
81+
return "top";
82+
case SWT.BOTTOM:
83+
return "bottom";
84+
case SWT.LEFT:
85+
return "left";
86+
case SWT.RIGHT:
87+
return "right";
88+
}
89+
90+
return "center";
91+
}
92+
93+
public static String getName(IViewPart targetPart) {
94+
return targetPart.getTitle();
95+
}
96+
}

0 commit comments

Comments
 (0)