From 5b97d0a099bca6d326b2c1b1fd0c3447c0d364a1 Mon Sep 17 00:00:00 2001 From: aloowood Date: Tue, 2 Sep 2025 08:59:59 +0300 Subject: [PATCH 1/2] Migrate Drag-and-Drop tests to JUnit 5 and provide basic DragOperations implementation --- tests/org.eclipse.ui.tests.dnd/.classpath | 15 ++ tests/org.eclipse.ui.tests.dnd/.project | 28 +++ .../org.eclipse.core.resources.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 9 + .../META-INF/MANIFEST.MF | 23 ++ .../org.eclipse.ui.tests.dnd/build.properties | 21 ++ .../ui/tests/dnd/DetachedDropTarget.java | 36 ++++ .../ui/tests/dnd/DetachedWindowDragTest.java | 26 +++ .../tests/dnd/DragDropPerspectiveFactory.java | 38 ++++ .../eclipse/ui/tests/dnd/DragOperations.java | 105 ++++++++++ .../org/eclipse/ui/tests/dnd/DragTest.java | 106 ++++++++++ .../eclipse/ui/tests/dnd/DragTestSuite.java | 197 ++++++++++++++++++ .../ui/tests/dnd/EditorAreaDropTarget.java | 23 ++ .../ui/tests/dnd/EditorDragSource.java | 36 ++++ .../ui/tests/dnd/EditorDropTarget.java | 37 ++++ .../ui/tests/dnd/EditorTabDropTarget.java | 37 ++++ .../ui/tests/dnd/EditorTitleDropTarget.java | 37 ++++ .../ui/tests/dnd/ExistingWindowProvider.java | 18 ++ .../tests/dnd/IWorkbenchWindowProvider.java | 7 + .../tests/dnd/StandaloneViewPerspective.java | 29 +++ .../eclipse/ui/tests/dnd/TestDragSource.java | 33 +++ .../ui/tests/dnd/TestDropLocation.java | 28 +++ .../eclipse/ui/tests/dnd/ViewDragSource.java | 71 +++++++ .../eclipse/ui/tests/dnd/ViewDropTarget.java | 43 ++++ .../ui/tests/dnd/ViewTabDropTarget.java | 52 +++++ .../ui/tests/dnd/ViewTitleDropTarget.java | 52 +++++ .../ui/tests/dnd/WindowDropTarget.java | 30 +++ .../tests/dnd/WorkbenchWindowDropTarget.java | 39 ++++ tests/org.eclipse.ui.tests.dnd/test.xml | 9 + 29 files changed, 1187 insertions(+) create mode 100644 tests/org.eclipse.ui.tests.dnd/.classpath create mode 100644 tests/org.eclipse.ui.tests.dnd/.project create mode 100644 tests/org.eclipse.ui.tests.dnd/.settings/org.eclipse.core.resources.prefs create mode 100644 tests/org.eclipse.ui.tests.dnd/.settings/org.eclipse.jdt.core.prefs create mode 100644 tests/org.eclipse.ui.tests.dnd/META-INF/MANIFEST.MF create mode 100644 tests/org.eclipse.ui.tests.dnd/build.properties create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedDropTarget.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragDropPerspectiveFactory.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragOperations.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTestSuite.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorAreaDropTarget.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDragSource.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDropTarget.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTabDropTarget.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTitleDropTarget.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ExistingWindowProvider.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/IWorkbenchWindowProvider.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/StandaloneViewPerspective.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDragSource.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDropLocation.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDragSource.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDropTarget.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTabDropTarget.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTitleDropTarget.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WindowDropTarget.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WorkbenchWindowDropTarget.java create mode 100644 tests/org.eclipse.ui.tests.dnd/test.xml diff --git a/tests/org.eclipse.ui.tests.dnd/.classpath b/tests/org.eclipse.ui.tests.dnd/.classpath new file mode 100644 index 00000000000..c9bfedfe9ca --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/.classpath @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/tests/org.eclipse.ui.tests.dnd/.project b/tests/org.eclipse.ui.tests.dnd/.project new file mode 100644 index 00000000000..31f44b9890e --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/.project @@ -0,0 +1,28 @@ + + + org.eclipse.ui.tests.dnd + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/tests/org.eclipse.ui.tests.dnd/.settings/org.eclipse.core.resources.prefs b/tests/org.eclipse.ui.tests.dnd/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..99f26c0203a --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/tests/org.eclipse.ui.tests.dnd/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.ui.tests.dnd/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..23fa13b1705 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=21 diff --git a/tests/org.eclipse.ui.tests.dnd/META-INF/MANIFEST.MF b/tests/org.eclipse.ui.tests.dnd/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..f1a4f166663 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Dnd +Bundle-SymbolicName: org.eclipse.ui.tests.dnd +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.eclipse.swt, + org.eclipse.jface, + org.junit;bundle-version="4.13.2", + org.eclipse.ui;bundle-version="3.207.300", + org.eclipse.ui.tests;bundle-version="3.15.2100", + org.eclipse.ui.workbench.texteditor;bundle-version="3.19.300", + org.eclipse.core.runtime;bundle-version="3.33.100", + org.eclipse.core.resources;bundle-version="3.22.200", + org.eclipse.ui.tests.harness;bundle-version="1.10.600", + junit-jupiter-api;bundle-version="5.12.2", + junit-platform-suite-api;bundle-version="1.12.2" +Automatic-Module-Name: org.eclipse.ui.tests.dnd +Bundle-RequiredExecutionEnvironment: JavaSE-21 +Import-Package: org.eclipse.e4.ui.model.application.ui.basic, + org.eclipse.ui.part, + org.junit.jupiter.params;version="[5.12.0,6.0.0)", + org.junit.jupiter.params.provider;version="[5.12.0,6.0.0)", + org.junit.platform.engine.support.descriptor;version="[1.12.0,2.0.0)" diff --git a/tests/org.eclipse.ui.tests.dnd/build.properties b/tests/org.eclipse.ui.tests.dnd/build.properties new file mode 100644 index 00000000000..d71de1f188d --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/build.properties @@ -0,0 +1,21 @@ +############################################################################### +# Copyright (c) 2025 Ali Muhsin KÖKSAL and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +############################################################################### + +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + test.xml + + +# Maven properties, see https://github.com/eclipse/tycho/wiki/Tycho-Pomless +pom.model.property.testClass = org.eclipse.ui.tests.dnd.DragTestSuite +pom.model.property.defaultSigning-excludeInnerJars = true diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedDropTarget.java new file mode 100644 index 00000000000..7c4e85b1236 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedDropTarget.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2004, 2005 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Shell; + +public class DetachedDropTarget implements TestDropLocation { + + @Override + public String toString() { + return "out of the window"; + } + + @Override + public Point getLocation() { + return new Point(0,0); + } + + @Override + public Shell[] getShells() { + return new Shell[0]; + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java new file mode 100644 index 00000000000..5938d5d3290 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java @@ -0,0 +1,26 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.ui.IViewPart; + +public class DetachedWindowDragTest extends DragTest { + + public DetachedWindowDragTest(TestDragSource dragSource, + TestDropLocation dropTarget) { + super(dragSource, dropTarget); + } + + @Override + public void doSetUp() throws Exception { + super.doSetUp(); + + page.showView(DragDropPerspectiveFactory.dropViewId2); + page.showView(DragDropPerspectiveFactory.dropViewId1); + page.showView(DragDropPerspectiveFactory.dropViewId3); + + IViewPart viewPart = page.showView(DragDropPerspectiveFactory.dropViewId1); + DragOperations.drag(viewPart, new DetachedDropTarget(), true); + + viewPart = page.showView(DragDropPerspectiveFactory.dropViewId3); + DragOperations.drag(viewPart, new DetachedDropTarget(), false); + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragDropPerspectiveFactory.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragDropPerspectiveFactory.java new file mode 100644 index 00000000000..9228a6d020b --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragDropPerspectiveFactory.java @@ -0,0 +1,38 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.ui.IFolderLayout; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPerspectiveFactory; +import org.eclipse.ui.IPlaceholderFolderLayout; + +public class DragDropPerspectiveFactory implements IPerspectiveFactory { + + // Id's needed by the 'Detached Window' Drag / Drop tests + public static final String viewFolderId = "oorg.eclipse.ui.test.dnd.detached.MockFolder1"; + + public static final String dropViewId1 = "org.eclipse.ui.tests.api.MockViewPart"; + public static final String dropViewId2 = "org.eclipse.ui.tests.api.MockViewPart2"; + public static final String dropViewId3 = "org.eclipse.ui.tests.api.MockViewPart3"; + + @Override + public void createInitialLayout(IPageLayout layout) { + String folderId = "org.eclipse.ui.test.dnd.mystack"; + + IFolderLayout folder = layout.createFolder(folderId, + IPageLayout.BOTTOM, 0.5f, IPageLayout.ID_EDITOR_AREA); + folder.addView(IPageLayout.ID_OUTLINE); + folder.addView(IPageLayout.ID_PROBLEM_VIEW); + folder.addView(IPageLayout.ID_PROP_SHEET); + + layout.addView(IPageLayout.ID_PROBLEM_VIEW, IPageLayout.LEFT, 0.5f, + IPageLayout.ID_EDITOR_AREA); + + // Extra stacks and views that will be shown and detached during the 'Detached Window' tests + IPlaceholderFolderLayout folder2 = layout.createPlaceholderFolder(viewFolderId, + IPageLayout.RIGHT, 0.5f, IPageLayout.ID_EDITOR_AREA); + folder2.addPlaceholder(dropViewId1); + folder2.addPlaceholder(dropViewId2); + + layout.addPlaceholder(dropViewId3, IPageLayout.BOTTOM, 0.5f, viewFolderId); + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragOperations.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragOperations.java new file mode 100644 index 00000000000..43c6ce2bed7 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragOperations.java @@ -0,0 +1,105 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.jface.util.Geometry; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartReference; + +public class DragOperations { + + public static void drag(IWorkbenchPart part, TestDropLocation target, boolean wholeFolder) { + Display.getDefault().syncExec(() -> { + Point startLocation = Display.getDefault().getCursorLocation(); + Point endLocation; + + if (wholeFolder) { + Rectangle bounds = part.getSite().getShell().getBounds(); + endLocation = new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2); + } else { + endLocation = target.getLocation(); + } + + Event press = new Event(); + press.type = SWT.MouseDown; + press.x = startLocation.x; + press.y = startLocation.y; + Display.getDefault().post(press); + + Event move = new Event(); + move.type = SWT.MouseMove; + move.x = endLocation.x; + move.y = endLocation.y; + Display.getDefault().post(move); + + Event release = new Event(); + release.type = SWT.MouseUp; + release.x = endLocation.x; + release.y = endLocation.y; + Display.getDefault().post(release); + }); + } + + /** + * Returns the name of the given editor + */ + public static String getName(IEditorPart editor) { + IWorkbenchPage page = editor.getSite().getPage(); + IWorkbenchPartReference ref = page.getReference(editor); + return ref.getPartName(); + } + + public static Rectangle getDisplayBounds() { + return new Rectangle(0, 0, 0, 0); + } + + public static Point getLocation(int side) { + return DragOperations.getPoint(getDisplayBounds(), side); + } + + public static Point getPointInEditorArea() { + return new Point(0, 0); + } + + public static Point getPoint(Rectangle bounds, int side) { + Point centerPoint = Geometry.centerPoint(bounds); + + switch (side) { + case SWT.TOP: + return new Point(centerPoint.x, bounds.y + 1); + case SWT.BOTTOM: + return new Point(centerPoint.x, bounds.y + bounds.height - 1); + case SWT.LEFT: + return new Point(bounds.x + 1, centerPoint.y); + case SWT.RIGHT: + return new Point(bounds.x + bounds.width - 1, centerPoint.y); + } + + return centerPoint; + } + + public static String nameForConstant(int swtSideConstant) { + switch (swtSideConstant) { + case SWT.TOP: + return "top"; + case SWT.BOTTOM: + return "bottom"; + case SWT.LEFT: + return "left"; + case SWT.RIGHT: + return "right"; + } + + return "center"; + } + + public static String getName(IViewPart targetPart) { + return targetPart.getTitle(); + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java new file mode 100644 index 00000000000..4bdd03c13c5 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2025 Ali Muhsin KÖKSAL. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: + * Ali Muhsin KÖKSAL - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui.tests.dnd; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.ui.tests.api.MockEditorPart; +import org.eclipse.ui.tests.harness.util.FileUtil; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class DragTest { + + TestDragSource dragSource; + TestDropLocation dropTarget; + + static IProject project; + static IFile file1, file2, file3; + + IEditorPart editor1, editor2, editor3; + + static IWorkbenchWindow window; + static IWorkbenchPage page; + + public DragTest(TestDragSource dragSource, TestDropLocation dropTarget) { + this.dragSource = dragSource; + this.dropTarget = dropTarget; + } + + @AfterEach + public void doSetUp() throws Exception { + if (window == null) { + window = (IWorkbenchWindow) PlatformUI.getWorkbench(); + page = (IWorkbenchPage) window.getActivePage(); + + project = FileUtil.createProject("DragTest"); + file1 = FileUtil.createFile("DragTest1.txt", project); + file2 = FileUtil.createFile("DragTest2.txt", project); + file3 = FileUtil.createFile("DragTest3.txt", project); + } + + page.resetPerspective(); + page.closeAllEditors(false); + + page.showView("org.eclipse.ui.views.ContentOutline"); + page.hideView(page.findView("org.eclipse.ui.internal.introview")); + editor1 = page.openEditor(new FileEditorInput(file1), MockEditorPart.ID1); + editor2 = page.openEditor(new FileEditorInput(file2), MockEditorPart.ID2); + editor3 = page.openEditor(new FileEditorInput(file3), MockEditorPart.ID2); + + window.getShell().setActive(); + DragOperations.drag(editor2, new EditorDropTarget(new ExistingWindowProvider(window), 0, SWT.CENTER), false); + DragOperations.drag(editor3, new EditorAreaDropTarget(new ExistingWindowProvider(window), SWT.RIGHT), false); + } + + @Test + @DisplayName("drag editor2 to right") + public void stallTest() { + String[] testNames = {}; + boolean testNameMatches = false; + for (String testName : testNames) { + if (testName.equals("drag editor2 to right")) { + testNameMatches = true; + break; + } + } + + if (testNames.length == 0 || testNameMatches) { + Display display = Display.getCurrent(); + Shell loopShell = new Shell(display, SWT.SHELL_TRIM); + loopShell.setBounds(0, 0, 200, 100); + loopShell.setText("Test Stall Shell"); + loopShell.setVisible(true); + + while (loopShell != null && !loopShell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + } + + @Test + public void performTest() throws Throwable { + dragSource.setPage(page); + dragSource.drag(dropTarget); + } +} diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTestSuite.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTestSuite.java new file mode 100644 index 00000000000..4768fd53917 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTestSuite.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * Copyright (c) 2025 Ali Muhsin KÖKSAL. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * Contributors: + * Ali Muhsin KÖKSAL - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui.tests.dnd; + +import java.util.stream.Stream; +import org.junit.jupiter.params.provider.Arguments; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IPageLayout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class DragTestSuite { + + private static final boolean isDetachingSupported; + + static { + Shell shell = new Shell(); + Composite c = new Composite(shell, SWT.NONE); + isDetachingSupported = c.isReparentable(); + shell.dispose(); + } + + public DragTestSuite() {} + + @ParameterizedTest + @MethodSource("dragSourceDropTargetProvider") + void dragTest(TestDragSource dragSource, TestDropLocation dropTarget) { + new DragTest(dragSource, dropTarget); + } + + static Stream dragSourceDropTargetProvider() { + List args = new ArrayList<>(); + + String resNav = IPageLayout.ID_PROJECT_EXPLORER; + String probView = IPageLayout.ID_PROBLEM_VIEW; + + TestDragSource[] viewDragSources = new TestDragSource[] { new ViewDragSource(resNav, false), + new ViewDragSource(resNav, true), new ViewDragSource(probView, false), + new ViewDragSource(probView, true) }; + + TestDragSource[] editorDragSources = new TestDragSource[] { new EditorDragSource(0, false), + new EditorDragSource(0, true), new EditorDragSource(2, false), new EditorDragSource(2, true) }; + + for (TestDragSource source : viewDragSources) { + for (TestDropLocation target : getViewDropTargets(source)) { + if (target != null) { + args.add(Arguments.of(source, target)); + } + } + for (TestDropLocation target : getCommonDropTargets(source)) { + args.add(Arguments.of(source, target)); + } + } + + for (TestDragSource source : editorDragSources) { + for (TestDropLocation target : getEditorDropTargets(source)) { + args.add(Arguments.of(source, target)); + } + for (TestDropLocation target : getCommonDropTargets(source)) { + args.add(Arguments.of(source, target)); + } + } + + TestDragSource[] maximizedViewDragSources = new TestDragSource[] { new ViewDragSource(resNav, false, true), + new ViewDragSource(resNav, true, true), new ViewDragSource(probView, false, true), + new ViewDragSource(probView, true, true) }; + + for (TestDragSource source : maximizedViewDragSources) { + for (TestDropLocation target : getMaximizedViewDropTargets(source)) { + args.add(Arguments.of(source, target)); + } + } + + if (isDetachingSupported) { + for (TestDragSource source : viewDragSources) { + for (TestDropLocation target : getDetachedWindowDropTargets(source)) { + args.add(Arguments.of(source, target)); + } + } + for (TestDragSource source : editorDragSources) { + for (TestDropLocation target : getDetachedWindowDropTargets(source)) { + args.add(Arguments.of(source, target)); + } + } + } + + return args.stream(); + } + + /** + * Returns drop targets that will only be tested for maximized views. (we only + * need to ensure that the view will become un-maximized -- the regular view + * test cases will excercise the remainder of the view dragging code). We need + * to drag each kind of maximized view to something that couldn't be seen while + * the view is maximized -- like the editor area). + * + * @since 3.1 + */ + private static TestDropLocation[] getMaximizedViewDropTargets(IWorkbenchWindowProvider originatingWindow) { + return new TestDropLocation[] { new EditorAreaDropTarget(originatingWindow, SWT.RIGHT) }; + } + + private static TestDropLocation[] getCommonDropTargets(IWorkbenchWindowProvider dragSource) { + return new TestDropLocation[] { + // Test dragging to the edges of the workbench window + new WindowDropTarget(dragSource, SWT.TOP), new WindowDropTarget(dragSource, SWT.BOTTOM), + new WindowDropTarget(dragSource, SWT.LEFT), new WindowDropTarget(dragSource, SWT.RIGHT) }; + } + + /** + * Return all drop targets that only apply to views, given the window being + * dragged from. + * + * @since 3.1 + */ + private static TestDropLocation[] getViewDropTargets(IWorkbenchWindowProvider dragSource) { + + String resNav = IPageLayout.ID_PROJECT_EXPLORER; + String probView = IPageLayout.ID_PROBLEM_VIEW; + + return new TestDropLocation[] { + // Editor area + new EditorAreaDropTarget(dragSource, SWT.LEFT), new EditorAreaDropTarget(dragSource, SWT.RIGHT), + new EditorAreaDropTarget(dragSource, SWT.TOP), new EditorAreaDropTarget(dragSource, SWT.BOTTOM), + + // Resource navigator (a view that isn't in a stack) + new ViewDropTarget(dragSource, resNav, SWT.LEFT), new ViewDropTarget(dragSource, resNav, SWT.RIGHT), + new ViewDropTarget(dragSource, resNav, SWT.BOTTOM), new ViewDropTarget(dragSource, resNav, SWT.CENTER), + new ViewDropTarget(dragSource, resNav, SWT.TOP), + + // Problems view (a view that is in a stack) + // Omit the top from this test, since the meaning of dropping on the top border + // of + // a stack may change in the near future + new ViewDropTarget(dragSource, probView, SWT.LEFT), new ViewDropTarget(dragSource, probView, SWT.RIGHT), + new ViewDropTarget(dragSource, probView, SWT.BOTTOM), + new ViewDropTarget(dragSource, probView, SWT.CENTER), new ViewDropTarget(dragSource, probView, SWT.TOP), + + // Fast view bar + null, // new FastViewBarDropTarget(dragSource), + + // View tabs + new ViewTabDropTarget(dragSource, resNav), new ViewTabDropTarget(dragSource, probView), + new ViewTitleDropTarget(dragSource, probView), }; + } + + /** + * Return all drop targets that apply to detached windows, given the window + * being dragged from. + * + * @since 3.1 + */ + private static TestDropLocation[] getDetachedWindowDropTargets(IWorkbenchWindowProvider dragSource) { + return new TestDropLocation[] { + // Editor area + new ViewDropTarget(dragSource, DragDropPerspectiveFactory.dropViewId1, SWT.CENTER), + new ViewDropTarget(dragSource, DragDropPerspectiveFactory.dropViewId3, SWT.CENTER), + new ViewTabDropTarget(dragSource, DragDropPerspectiveFactory.dropViewId1), new DetachedDropTarget() }; + } + + private static TestDropLocation[] getEditorDropTargets(IWorkbenchWindowProvider originatingWindow) { + String resNav = IPageLayout.ID_PROJECT_EXPLORER; + // Drop targets that will only be tested for editors + return new TestDropLocation[] { + // A view + new ViewDropTarget(originatingWindow, resNav, SWT.CENTER), + + // A stand-alone editor + new EditorDropTarget(originatingWindow, 2, SWT.LEFT), + new EditorDropTarget(originatingWindow, 2, SWT.RIGHT), + new EditorDropTarget(originatingWindow, 2, SWT.TOP), + new EditorDropTarget(originatingWindow, 2, SWT.BOTTOM), + new EditorDropTarget(originatingWindow, 2, SWT.CENTER), + + // Editors (a stack of editors) + new EditorDropTarget(originatingWindow, 0, SWT.LEFT), + new EditorDropTarget(originatingWindow, 0, SWT.RIGHT), + new EditorDropTarget(originatingWindow, 0, SWT.BOTTOM), + new EditorDropTarget(originatingWindow, 0, SWT.CENTER), new EditorTabDropTarget(originatingWindow, 0), + new EditorTitleDropTarget(originatingWindow, 0), }; + } + +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorAreaDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorAreaDropTarget.java new file mode 100644 index 00000000000..7a8708ef6b9 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorAreaDropTarget.java @@ -0,0 +1,23 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.graphics.Point; + +public class EditorAreaDropTarget extends WorkbenchWindowDropTarget { + int side; + + public EditorAreaDropTarget(IWorkbenchWindowProvider provider, int side) { + super(provider); + this.side = side; + } + + @Override + public String toString() { + return DragOperations.nameForConstant(side) + " of editor area"; + } + + @Override + public Point getLocation() { + return DragOperations.getPointInEditorArea(); + } + +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDragSource.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDragSource.java new file mode 100644 index 00000000000..1f77794337c --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDragSource.java @@ -0,0 +1,36 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.ui.IEditorPart; + +public class EditorDragSource extends TestDragSource { + + int editorIdx; + + boolean wholeFolder; + + public EditorDragSource(int editorIdx, boolean wholeFolder) { + super(); + this.editorIdx = editorIdx; + this.wholeFolder = wholeFolder; + } + + IEditorPart getPart() { + return getPage().getEditorReferences()[editorIdx].getEditor(true); + } + + @Override + public String toString() { + String title = "editor " + editorIdx; + + if (wholeFolder) { + return title + " folder"; + } + return title; + } + + @Override + public void drag(TestDropLocation target) { + DragOperations.drag(getPart(), target, wholeFolder); + } + +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDropTarget.java new file mode 100644 index 00000000000..f2f2a472d88 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDropTarget.java @@ -0,0 +1,37 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; + +public class EditorDropTarget extends WorkbenchWindowDropTarget { + + int editorIdx; + + int side; + + public EditorDropTarget(IWorkbenchWindowProvider provider, int editorIdx, int side) { + super(provider); + this.editorIdx = editorIdx; + this.side = side; + } + + IEditorPart getPart() { + return getPage().getEditorReferences()[editorIdx].getEditor(true); + } + + @Override + public String toString() { + return DragOperations.nameForConstant(side) + " of editor " + editorIdx; + } + + @Override + public Point getLocation() { + return DragOperations.getLocation(side); + } + + @Override + public Shell getShell() { + return getPart().getSite().getShell(); + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTabDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTabDropTarget.java new file mode 100644 index 00000000000..d2cd00b1fda --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTabDropTarget.java @@ -0,0 +1,37 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; + +public class EditorTabDropTarget extends WorkbenchWindowDropTarget { + + int editorIdx; + + public EditorTabDropTarget(IWorkbenchWindowProvider provider, int editorIdx) { + super(provider); + this.editorIdx = editorIdx; + } + + IEditorPart getPart() { + return getPage().getEditorReferences()[editorIdx].getEditor(true); + } + + @Override + public String toString() { + return "editor " + editorIdx + " tab area"; + } + + @Override + public Shell getShell() { + return getPart().getSite().getShell(); + } + + @Override + public Point getLocation() { + Rectangle bounds = DragOperations.getDisplayBounds(); + + return new Point(bounds.x + 8, bounds.y + 8); + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTitleDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTitleDropTarget.java new file mode 100644 index 00000000000..52d65237cf8 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTitleDropTarget.java @@ -0,0 +1,37 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; + +public class EditorTitleDropTarget extends WorkbenchWindowDropTarget { + + int editorIdx; + + public EditorTitleDropTarget(IWorkbenchWindowProvider provider, int editorIdx) { + super(provider); + this.editorIdx = editorIdx; + } + + IEditorPart getPart() { + return getPage().getEditorReferences()[editorIdx].getEditor(true); + } + + @Override + public String toString() { + return "editor " + editorIdx + " title area"; + } + + @Override + public Shell getShell() { + return getPart().getSite().getShell(); + } + + @Override + public Point getLocation() { + Rectangle bounds = DragOperations.getDisplayBounds(); + + return new Point( (bounds.x + bounds.width) - 4, bounds.y + 4); + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ExistingWindowProvider.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ExistingWindowProvider.java new file mode 100644 index 00000000000..738e6fb1827 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ExistingWindowProvider.java @@ -0,0 +1,18 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.ui.IWorkbenchWindow; + +public class ExistingWindowProvider implements IWorkbenchWindowProvider { + + private final IWorkbenchWindow window; + + public ExistingWindowProvider(IWorkbenchWindow window) { + this.window = window; + } + + @Override + public IWorkbenchWindow getWorkbenchWindow() { + return window; + } + +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/IWorkbenchWindowProvider.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/IWorkbenchWindowProvider.java new file mode 100644 index 00000000000..cab0f890a1b --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/IWorkbenchWindowProvider.java @@ -0,0 +1,7 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.ui.IWorkbenchWindow; + +public interface IWorkbenchWindowProvider { + public IWorkbenchWindow getWorkbenchWindow(); +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/StandaloneViewPerspective.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/StandaloneViewPerspective.java new file mode 100644 index 00000000000..1dca53da9d4 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/StandaloneViewPerspective.java @@ -0,0 +1,29 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPerspectiveFactory; + +public class StandaloneViewPerspective implements IPerspectiveFactory { + + public static final String OUTLINE_ID = IPageLayout.ID_OUTLINE; + + public static final String RESOURCE_ID = IPageLayout.ID_PROJECT_EXPLORER; + + public static final String TASK_ID = IPageLayout.ID_TASK_LIST; + + public static final String PERSP_ID = "org.eclipse.ui.tests.dnd.StandaloneViewPerspective"; + + public StandaloneViewPerspective() { + // do nothing + } + + @Override + public void createInitialLayout(IPageLayout layout) { + layout.setEditorAreaVisible(true); + + layout.addStandaloneView(RESOURCE_ID, true, IPageLayout.LEFT, 0.25f, IPageLayout.ID_EDITOR_AREA); + layout.addStandaloneView(OUTLINE_ID, true, IPageLayout.RIGHT, 0.25f, IPageLayout.ID_EDITOR_AREA); + layout.getViewLayout(OUTLINE_ID).setCloseable(false); + layout.addStandaloneView(TASK_ID, true, IPageLayout.BOTTOM, 0.25f, IPageLayout.ID_EDITOR_AREA); + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDragSource.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDragSource.java new file mode 100644 index 00000000000..37cf5f36d93 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDragSource.java @@ -0,0 +1,33 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +public abstract class TestDragSource implements IWorkbenchWindowProvider { + private IWorkbenchPage page; + + @Override + public abstract String toString(); + + public abstract void drag(TestDropLocation target); + + public void setPage(IWorkbenchPage page) { + this.page = page; + } + + @Override + public IWorkbenchWindow getWorkbenchWindow() { + return getPage().getWorkbenchWindow(); + } + + public IWorkbenchPage getPage() { + if (page == null) { + page = PlatformUI + .getWorkbench().getActiveWorkbenchWindow().getActivePage(); + } + return page; + } + + +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDropLocation.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDropLocation.java new file mode 100644 index 00000000000..10884d36f94 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDropLocation.java @@ -0,0 +1,28 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Shell; + +/** + * This is an interface intended for use in test suites. Objects can implement + * this interface to force any dragged object to be dropped at a particular + * location. + * + */ +public interface TestDropLocation { + + /** + * Location where the object should be dropped, in display coordinates + * + * @return a location in display coordinates + */ + Point getLocation(); + + /** + * The drop code will pretend that only the given shells are open, + * and that they have the specified Z-order. + * + * @return the shells to check for drop targets, from bottom to top. + */ + Shell[] getShells(); +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDragSource.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDragSource.java new file mode 100644 index 00000000000..e047c95c580 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDragSource.java @@ -0,0 +1,71 @@ +package org.eclipse.ui.tests.dnd; + + +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.views.IViewDescriptor; +import org.junit.Assert; + +public class ViewDragSource extends TestDragSource { + + String targetPart; + + boolean wholeFolder; + + boolean maximized = false; + + public ViewDragSource(String part, boolean dragWholeFolder) { + this(part, dragWholeFolder, false); + } + + public ViewDragSource(String part, boolean dragWholeFolder, + boolean maximized) { + this.maximized = maximized; + this.targetPart = part; + + wholeFolder = dragWholeFolder; + } + + public IViewPart getPart() { + return getPage().findView(targetPart); + } + + @Override + public String toString() { + IViewDescriptor desc = PlatformUI.getWorkbench().getViewRegistry() + .find(targetPart); + String title = desc.getLabel(); + + if (wholeFolder) { + title = title + " folder"; + } + + if (maximized) { + title = "maximized " + title; + } + + return title; + } + + @Override + public void drag(TestDropLocation target) { + IViewPart part = getPart(); + + IWorkbenchPage page = getPage(); + if (maximized) { + page.toggleZoom(page.getReference(part)); + } + +// DragUtil.forceDropLocation(target); +// ViewStack parent = ((ViewStack) (pane.getContainer())); +// +// PartPane presentablePart = wholeFolder ? null : pane; +// parent.paneDragStart(presentablePart, Display.getDefault() +// .getCursorLocation(), false); + Assert.fail("DND needs updated"); + +// DragUtil.forceDropLocation(null); + } + +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDropTarget.java new file mode 100644 index 00000000000..42947b718c7 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDropTarget.java @@ -0,0 +1,43 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.views.IViewDescriptor; + +public class ViewDropTarget extends WorkbenchWindowDropTarget { + + String targetPart; + + int side; + + public ViewDropTarget(IWorkbenchWindowProvider provider, String part, int side) { + super(provider); + targetPart = part; + this.side = side; + } + + IViewPart getPart() { + return getPage().findView(targetPart); + } + + @Override + public String toString() { + IViewDescriptor desc = PlatformUI.getWorkbench().getViewRegistry() + .find(targetPart); + String title = desc.getLabel(); + + return DragOperations.nameForConstant(side) + " of " + title; + } + + @Override + public Point getLocation() { + return DragOperations.getLocation(side); + } + + @Override + public Shell getShell() { + return getPart().getSite().getShell(); + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTabDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTabDropTarget.java new file mode 100644 index 00000000000..0ed1a2671f0 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTabDropTarget.java @@ -0,0 +1,52 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.views.IViewDescriptor; + +/** + * Note: this drop location is hardcoded to assume a presentation that has + * a tab drop location at the upper left corner, 8 pixels away from the + * edge in both dimensions. This drop location should be omitted from the + * tests in situations where this does not apply (this is not a problem + * right now since the current tests only use the tabs-on-top drop + * location). + * + */ +public class ViewTabDropTarget extends WorkbenchWindowDropTarget { + + String targetPart; + + public ViewTabDropTarget(IWorkbenchWindowProvider provider, String part) { + super(provider); + targetPart = part; + } + + IViewPart getPart() { + return getPage().findView(targetPart); + } + + @Override + public String toString() { + IViewDescriptor desc = PlatformUI.getWorkbench().getViewRegistry() + .find(targetPart); + String title = desc.getLabel(); + + return title + " view tab area"; + } + + @Override + public Point getLocation() { + Rectangle bounds = DragOperations.getDisplayBounds(); + + return new Point(bounds.x + 8, bounds.y + 8); + } + + @Override + public Shell getShell() { + return getPart().getSite().getShell(); + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTitleDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTitleDropTarget.java new file mode 100644 index 00000000000..8cc07476794 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTitleDropTarget.java @@ -0,0 +1,52 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.views.IViewDescriptor; + +/** + * Note: this drop location is hardcoded to assume a presentation that has + * a tab drop location at the upper left corner, 8 pixels away from the + * edge in both dimensions. This drop location should be omitted from the + * tests in situations where this does not apply (this is not a problem + * right now since the current tests only use the tabs-on-top drop + * location). + * + */ +public class ViewTitleDropTarget extends WorkbenchWindowDropTarget { + + String targetPart; + + public ViewTitleDropTarget(IWorkbenchWindowProvider provider, String part) { + super(provider); + targetPart = part; + } + + IViewPart getPart() { + return getPage().findView(targetPart); + } + + @Override + public String toString() { + IViewDescriptor desc = PlatformUI.getWorkbench().getViewRegistry() + .find(targetPart); + String title = desc.getLabel(); + + return title + " view title area"; + } + + @Override + public Point getLocation() { + Rectangle bounds = DragOperations.getDisplayBounds(); + + return new Point( (bounds.x + bounds.width) - 8, bounds.y + 8); + } + + @Override + public Shell getShell() { + return getPart().getSite().getShell(); + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WindowDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WindowDropTarget.java new file mode 100644 index 00000000000..255e4ea0a28 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WindowDropTarget.java @@ -0,0 +1,30 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.jface.util.Geometry; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Shell; + +public class WindowDropTarget extends WorkbenchWindowDropTarget { + + private final int side; + + public WindowDropTarget(IWorkbenchWindowProvider provider, int side) { + super(provider); + this.side = side; + } + + @Override + public String toString() { + return DragOperations.nameForConstant(side) + " of window"; + } + + @Override + public Point getLocation() { + Shell shell = getShell(); + Rectangle clientArea = shell.getClientArea(); + + return DragOperations.getPoint(Geometry.toDisplay(shell, clientArea), + side); + } +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WorkbenchWindowDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WorkbenchWindowDropTarget.java new file mode 100644 index 00000000000..6ef5d72df0f --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WorkbenchWindowDropTarget.java @@ -0,0 +1,39 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; + +public abstract class WorkbenchWindowDropTarget implements TestDropLocation { + + private final IWorkbenchWindowProvider window; + + @Override + public abstract String toString(); + + @Override + public abstract Point getLocation(); + + public WorkbenchWindowDropTarget(IWorkbenchWindowProvider window) { + this.window = window; + } + + public IWorkbenchWindow getWindow() { + return window.getWorkbenchWindow(); + } + + public Shell getShell() { + return getWindow().getShell(); + } + + public IWorkbenchPage getPage() { + return (IWorkbenchPage)getWindow().getActivePage(); + } + + @Override + public Shell[] getShells() { + return new Shell[] {getShell()}; + } + +} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/test.xml b/tests/org.eclipse.ui.tests.dnd/test.xml new file mode 100644 index 00000000000..cacfb19017c --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/test.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file From 654da492e9857ea954be90ba4aea7fbc8871754a Mon Sep 17 00:00:00 2001 From: aloowood Date: Tue, 23 Sep 2025 12:41:06 +0300 Subject: [PATCH 2/2] Add clean DnD Test --- .../org.eclipse.core.resources.prefs | 2 + features/.project | 11 + tests/org.eclipse.ui.tests.dnd/.classpath | 6 +- tests/org.eclipse.ui.tests.dnd/.project | 6 + .../META-INF/MANIFEST.MF | 19 +- .../org.eclipse.ui.tests.dnd/build.properties | 19 +- .../ui/tests/dnd/DataTypeValidator.java | 35 ++++ .../ui/tests/dnd/DetachedDropTarget.java | 36 ---- .../ui/tests/dnd/DetachedWindowDragTest.java | 26 --- .../eclipse/ui/tests/dnd/DnDEventFactory.java | 47 +++++ .../eclipse/ui/tests/dnd/DnDTestHelper.java | 91 ++++++++ .../org/eclipse/ui/tests/dnd/DnDTests.java | 123 +++++++++++ .../tests/dnd/DragDropPerspectiveFactory.java | 38 ---- .../eclipse/ui/tests/dnd/DragOperations.java | 105 ---------- .../org/eclipse/ui/tests/dnd/DragTest.java | 106 ---------- .../eclipse/ui/tests/dnd/DragTestSuite.java | 197 ------------------ .../ui/tests/dnd/EditorAreaDropTarget.java | 23 -- .../ui/tests/dnd/EditorDragSource.java | 36 ---- .../ui/tests/dnd/EditorDropTarget.java | 37 ---- .../ui/tests/dnd/EditorTabDropTarget.java | 37 ---- .../ui/tests/dnd/EditorTitleDropTarget.java | 37 ---- .../ui/tests/dnd/ExistingWindowProvider.java | 18 -- .../tests/dnd/IWorkbenchWindowProvider.java | 7 - .../tests/dnd/StandaloneViewPerspective.java | 29 --- .../eclipse/ui/tests/dnd/TestDragSource.java | 33 --- .../ui/tests/dnd/TestDropLocation.java | 28 --- .../eclipse/ui/tests/dnd/ViewDragSource.java | 71 ------- .../eclipse/ui/tests/dnd/ViewDropTarget.java | 43 ---- .../ui/tests/dnd/ViewTabDropTarget.java | 52 ----- .../ui/tests/dnd/ViewTitleDropTarget.java | 52 ----- .../ui/tests/dnd/WindowDropTarget.java | 30 --- .../tests/dnd/WorkbenchWindowDropTarget.java | 39 ---- tests/org.eclipse.ui.tests.dnd/test.xml | 9 - 33 files changed, 320 insertions(+), 1128 deletions(-) create mode 100644 examples/.settings/org.eclipse.core.resources.prefs create mode 100644 features/.project create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DataTypeValidator.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedDropTarget.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDEventFactory.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDTestHelper.java create mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDTests.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragDropPerspectiveFactory.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragOperations.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTestSuite.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorAreaDropTarget.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDragSource.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDropTarget.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTabDropTarget.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTitleDropTarget.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ExistingWindowProvider.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/IWorkbenchWindowProvider.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/StandaloneViewPerspective.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDragSource.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDropLocation.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDragSource.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDropTarget.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTabDropTarget.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTitleDropTarget.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WindowDropTarget.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WorkbenchWindowDropTarget.java delete mode 100644 tests/org.eclipse.ui.tests.dnd/test.xml diff --git a/examples/.settings/org.eclipse.core.resources.prefs b/examples/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..99f26c0203a --- /dev/null +++ b/examples/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/features/.project b/features/.project new file mode 100644 index 00000000000..cf8899cb3fa --- /dev/null +++ b/features/.project @@ -0,0 +1,11 @@ + + + features + + + + + + + + diff --git a/tests/org.eclipse.ui.tests.dnd/.classpath b/tests/org.eclipse.ui.tests.dnd/.classpath index c9bfedfe9ca..1aa9eca95a0 100644 --- a/tests/org.eclipse.ui.tests.dnd/.classpath +++ b/tests/org.eclipse.ui.tests.dnd/.classpath @@ -1,10 +1,6 @@ - - - - - + diff --git a/tests/org.eclipse.ui.tests.dnd/.project b/tests/org.eclipse.ui.tests.dnd/.project index 31f44b9890e..fcb678152cc 100644 --- a/tests/org.eclipse.ui.tests.dnd/.project +++ b/tests/org.eclipse.ui.tests.dnd/.project @@ -20,9 +20,15 @@ + + org.eclipse.pde.api.tools.apiAnalysisBuilder + + + org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature + org.eclipse.pde.api.tools.apiAnalysisNature diff --git a/tests/org.eclipse.ui.tests.dnd/META-INF/MANIFEST.MF b/tests/org.eclipse.ui.tests.dnd/META-INF/MANIFEST.MF index f1a4f166663..8c04bd05335 100644 --- a/tests/org.eclipse.ui.tests.dnd/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.ui.tests.dnd/META-INF/MANIFEST.MF @@ -3,21 +3,8 @@ Bundle-ManifestVersion: 2 Bundle-Name: Dnd Bundle-SymbolicName: org.eclipse.ui.tests.dnd Bundle-Version: 1.0.0.qualifier -Require-Bundle: org.eclipse.swt, - org.eclipse.jface, - org.junit;bundle-version="4.13.2", - org.eclipse.ui;bundle-version="3.207.300", - org.eclipse.ui.tests;bundle-version="3.15.2100", - org.eclipse.ui.workbench.texteditor;bundle-version="3.19.300", - org.eclipse.core.runtime;bundle-version="3.33.100", - org.eclipse.core.resources;bundle-version="3.22.200", - org.eclipse.ui.tests.harness;bundle-version="1.10.600", - junit-jupiter-api;bundle-version="5.12.2", - junit-platform-suite-api;bundle-version="1.12.2" +Require-Bundle: junit-jupiter-api;bundle-version="5.13.4", + org.eclipse.jface;bundle-version="3.38.0", + org.eclipse.e4.ui.workbench.addons.swt;bundle-version="1.5.800" Automatic-Module-Name: org.eclipse.ui.tests.dnd Bundle-RequiredExecutionEnvironment: JavaSE-21 -Import-Package: org.eclipse.e4.ui.model.application.ui.basic, - org.eclipse.ui.part, - org.junit.jupiter.params;version="[5.12.0,6.0.0)", - org.junit.jupiter.params.provider;version="[5.12.0,6.0.0)", - org.junit.platform.engine.support.descriptor;version="[1.12.0,2.0.0)" diff --git a/tests/org.eclipse.ui.tests.dnd/build.properties b/tests/org.eclipse.ui.tests.dnd/build.properties index d71de1f188d..34d2e4d2dad 100644 --- a/tests/org.eclipse.ui.tests.dnd/build.properties +++ b/tests/org.eclipse.ui.tests.dnd/build.properties @@ -1,21 +1,4 @@ -############################################################################### -# Copyright (c) 2025 Ali Muhsin KÖKSAL and others. -# -# This program and the accompanying materials -# are made available under the terms of the Eclipse Public License 2.0 -# which accompanies this distribution, and is available at -# https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -############################################################################### - source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - .,\ - test.xml - - -# Maven properties, see https://github.com/eclipse/tycho/wiki/Tycho-Pomless -pom.model.property.testClass = org.eclipse.ui.tests.dnd.DragTestSuite -pom.model.property.defaultSigning-excludeInnerJars = true + . diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DataTypeValidator.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DataTypeValidator.java new file mode 100644 index 00000000000..a6a463c2b3d --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DataTypeValidator.java @@ -0,0 +1,35 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.swt.widgets.Widget; + +public class DataTypeValidator { + + public boolean isValidDrop(Widget target, Object data) { + if (target == null || data == null) { + System.out.println("Invalid drop: target or data is null"); + return false; + } + + if (target instanceof List) { + boolean valid = data instanceof String; + if (!valid) System.out.println("Invalid drop: List can only accept String data"); + return valid; + } else if (target instanceof Tree) { + boolean valid = data instanceof String || data instanceof TreeItem; + if (!valid) System.out.println("Invalid drop: Tree can only accept String or TreeItem data"); + return valid; + } else if (target instanceof Table) { + boolean valid = data instanceof TableItem; + if (!valid) System.out.println("Invalid drop: Table can only accept TableItem data"); + return valid; + } + + System.out.println("Invalid drop: Unsupported widget type " + target.getClass().getSimpleName()); + return false; + } +} diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedDropTarget.java deleted file mode 100644 index 7c4e85b1236..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedDropTarget.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.ui.tests.dnd; - -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Shell; - -public class DetachedDropTarget implements TestDropLocation { - - @Override - public String toString() { - return "out of the window"; - } - - @Override - public Point getLocation() { - return new Point(0,0); - } - - @Override - public Shell[] getShells() { - return new Shell[0]; - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java deleted file mode 100644 index 5938d5d3290..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.ui.IViewPart; - -public class DetachedWindowDragTest extends DragTest { - - public DetachedWindowDragTest(TestDragSource dragSource, - TestDropLocation dropTarget) { - super(dragSource, dropTarget); - } - - @Override - public void doSetUp() throws Exception { - super.doSetUp(); - - page.showView(DragDropPerspectiveFactory.dropViewId2); - page.showView(DragDropPerspectiveFactory.dropViewId1); - page.showView(DragDropPerspectiveFactory.dropViewId3); - - IViewPart viewPart = page.showView(DragDropPerspectiveFactory.dropViewId1); - DragOperations.drag(viewPart, new DetachedDropTarget(), true); - - viewPart = page.showView(DragDropPerspectiveFactory.dropViewId3); - DragOperations.drag(viewPart, new DetachedDropTarget(), false); - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDEventFactory.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDEventFactory.java new file mode 100644 index 00000000000..18facbf8a99 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDEventFactory.java @@ -0,0 +1,47 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.widgets.Widget; +import java.util.Arrays; + +public class DnDEventFactory { + + public DragSourceEvent createDragStartEvent(Widget source, Object... items) { + if (source == null) { + throw new IllegalArgumentException("Source widget cannot be null"); + } + + DragSourceEvent event = new DragSourceEvent(null); + event.widget = source; + event.data = items != null ? items : new Object[0]; + event.detail = 0; + + System.out.println("DragStartEvent created for source: " + source + + " with items: " + Arrays.toString((Object[]) event.data)); + + return event; + } + + public DragSourceEvent createDragSetDataEvent(Widget source, Object data, int operation) { + if (source == null) throw new IllegalArgumentException("Source widget cannot be null"); + DragSourceEvent event = new DragSourceEvent(null); + event.widget = source; + event.data = data; + event.detail = operation; + + System.out.println("DragSetDataEvent created for source: " + source + + ", data: " + data + ", operation: " + operation); + return event; + } + + public DragSourceEvent createDragFinishedEvent(Widget source, int operation) { + if (source == null) throw new IllegalArgumentException("Source widget cannot be null"); + DragSourceEvent event = new DragSourceEvent(null); + event.widget = source; + event.detail = operation; + + System.out.println("DragFinishedEvent created for source: " + source + + ", operation: " + operation); + return event; + } +} diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDTestHelper.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDTestHelper.java new file mode 100644 index 00000000000..0d10a242a6b --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDTestHelper.java @@ -0,0 +1,91 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.swt.widgets.Event; + +public class DnDTestHelper { + + public void selectItems(Widget widget, Object... items) { + if (items == null || items.length == 0) return; + + if (widget instanceof Tree tree) { + for (Object item : items) { + if (item instanceof org.eclipse.swt.widgets.TreeItem) { + tree.setSelection((org.eclipse.swt.widgets.TreeItem) item); + } else { + System.out.println("Invalid item type for Tree: " + item); + } + } + } else if (widget instanceof Table table) { + for (Object item : items) { + if (item instanceof TableItem) { + table.setSelection((TableItem) item); + } else { + System.out.println("Invalid item type for Table: " + item); + } + } + } else if (widget instanceof List list) { + for (Object item : items) { + if (item instanceof String) { + int index = list.indexOf((String) item); + if (index >= 0) { + list.select(index); + } else { + System.out.println("Item not found in List: " + item); + } + } else { + System.out.println("Invalid item type for List: " + item); + } + } + } + } + + public void simulateDrag(Widget source, Widget target, int dragType, Object... items) { + if (source == null || target == null || items == null || items.length == 0) { + System.out.println("Invalid drag parameters. Aborting simulation."); + return; + } + + Display.getDefault().syncExec(() -> { + System.out.println("=== Starting drag from " + source + " to " + target + " ==="); + + // --- Drag Detect --- + Event dragDetect = new Event(); + dragDetect.widget = source; + source.notifyListeners(SWT.DragDetect, dragDetect); + + // --- Drag Set Data --- + Event setData = new Event(); + setData.widget = source; + setData.data = items; + source.notifyListeners(DND.DragSetData, setData); + + // --- Drag Finished --- + Event dragEnd = new Event(); + dragEnd.widget = source; + dragEnd.detail = dragType; + source.notifyListeners(DND.DragEnd, dragEnd); + + // --- Drop --- + Event dropEvent = new Event(); + dropEvent.widget = target; + dropEvent.data = items; + target.notifyListeners(DND.Drop, dropEvent); + + System.out.println("=== Drag simulation finished to " + target + " ==="); + }); + } + + public void runEventLoop() { + Display display = Display.getDefault(); + while (display.readAndDispatch()) { + } + } +} diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDTests.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDTests.java new file mode 100644 index 00000000000..f9d3cd8f723 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DnDTests.java @@ -0,0 +1,123 @@ +package org.eclipse.ui.tests.dnd; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.function.BiConsumer; + +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class DnDTests { + + static Display display; + static Shell shell; + + @BeforeAll + public static void setupDisplay() { + display = Display.getDefault(); + shell = new Shell(display); + } + + @AfterAll + public static void disposeDisplay() { + if (shell != null && !shell.isDisposed()) + shell.dispose(); + } + + @Test + public void testSingleItemDragAndDrop() { + display.syncExec(() -> { + List source = new List(shell, SWT.BORDER); + List target = new List(shell, SWT.BORDER); + source.add("Item 1"); + + DnDTestHelper helper = new DnDTestHelper(); + helper.selectItems(source, "Item 1"); + helper.simulateDrag(source, target, DND.DROP_COPY, "Item 1"); + + assertEquals(1, source.getSelectionCount()); + assertEquals("Item 1", source.getSelection()[0]); + }); + } + + @Test + public void testMultiItemDragAcrossWidgets() { + display.syncExec(() -> { + List listSource = new List(shell, SWT.BORDER); + Table tableSource = new Table(shell, SWT.BORDER); + Tree treeSource = new Tree(shell, SWT.BORDER); + + List listTarget = new List(shell, SWT.BORDER); + Table tableTarget = new Table(shell, SWT.BORDER); + Tree treeTarget = new Tree(shell, SWT.BORDER); + + listSource.add("L1"); + listSource.add("L2"); + + TableItem t1 = new TableItem(tableSource, SWT.NONE); + t1.setText("T1"); + TableItem t2 = new TableItem(tableSource, SWT.NONE); + t2.setText("T2"); + + TreeItem tr1 = new TreeItem(treeSource, SWT.NONE); + tr1.setText("TR1"); + TreeItem tr2 = new TreeItem(treeSource, SWT.NONE); + tr2.setText("TR2"); + + DnDTestHelper helper = new DnDTestHelper(); + + BiConsumer assertTargetContent = (target, expectedItems) -> { + if(target instanceof List l) { + assertEquals(expectedItems.length, l.getItemCount()); + + } + }; + + + }); + } + + @Test + public void testDropWithInvalidData() { + } + + @Test + public void testDropOnDisposedWidget() { + } + + @Test + public void testDropOnInvisibleWidget() { + } + + @Test + public void testDragOperations() { + } + + @Test + public void testCustomDataTransfer() { + } + + @Test + public void testEventOrder() { + } + + @Test + public void testSelectionClearedAfterDrag() { + } + + @Test + public void testDragWithEmptySelection() { + } + +} diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragDropPerspectiveFactory.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragDropPerspectiveFactory.java deleted file mode 100644 index 9228a6d020b..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragDropPerspectiveFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.ui.IFolderLayout; -import org.eclipse.ui.IPageLayout; -import org.eclipse.ui.IPerspectiveFactory; -import org.eclipse.ui.IPlaceholderFolderLayout; - -public class DragDropPerspectiveFactory implements IPerspectiveFactory { - - // Id's needed by the 'Detached Window' Drag / Drop tests - public static final String viewFolderId = "oorg.eclipse.ui.test.dnd.detached.MockFolder1"; - - public static final String dropViewId1 = "org.eclipse.ui.tests.api.MockViewPart"; - public static final String dropViewId2 = "org.eclipse.ui.tests.api.MockViewPart2"; - public static final String dropViewId3 = "org.eclipse.ui.tests.api.MockViewPart3"; - - @Override - public void createInitialLayout(IPageLayout layout) { - String folderId = "org.eclipse.ui.test.dnd.mystack"; - - IFolderLayout folder = layout.createFolder(folderId, - IPageLayout.BOTTOM, 0.5f, IPageLayout.ID_EDITOR_AREA); - folder.addView(IPageLayout.ID_OUTLINE); - folder.addView(IPageLayout.ID_PROBLEM_VIEW); - folder.addView(IPageLayout.ID_PROP_SHEET); - - layout.addView(IPageLayout.ID_PROBLEM_VIEW, IPageLayout.LEFT, 0.5f, - IPageLayout.ID_EDITOR_AREA); - - // Extra stacks and views that will be shown and detached during the 'Detached Window' tests - IPlaceholderFolderLayout folder2 = layout.createPlaceholderFolder(viewFolderId, - IPageLayout.RIGHT, 0.5f, IPageLayout.ID_EDITOR_AREA); - folder2.addPlaceholder(dropViewId1); - folder2.addPlaceholder(dropViewId2); - - layout.addPlaceholder(dropViewId3, IPageLayout.BOTTOM, 0.5f, viewFolderId); - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragOperations.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragOperations.java deleted file mode 100644 index 43c6ce2bed7..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragOperations.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.jface.util.Geometry; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchPartReference; - -public class DragOperations { - - public static void drag(IWorkbenchPart part, TestDropLocation target, boolean wholeFolder) { - Display.getDefault().syncExec(() -> { - Point startLocation = Display.getDefault().getCursorLocation(); - Point endLocation; - - if (wholeFolder) { - Rectangle bounds = part.getSite().getShell().getBounds(); - endLocation = new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2); - } else { - endLocation = target.getLocation(); - } - - Event press = new Event(); - press.type = SWT.MouseDown; - press.x = startLocation.x; - press.y = startLocation.y; - Display.getDefault().post(press); - - Event move = new Event(); - move.type = SWT.MouseMove; - move.x = endLocation.x; - move.y = endLocation.y; - Display.getDefault().post(move); - - Event release = new Event(); - release.type = SWT.MouseUp; - release.x = endLocation.x; - release.y = endLocation.y; - Display.getDefault().post(release); - }); - } - - /** - * Returns the name of the given editor - */ - public static String getName(IEditorPart editor) { - IWorkbenchPage page = editor.getSite().getPage(); - IWorkbenchPartReference ref = page.getReference(editor); - return ref.getPartName(); - } - - public static Rectangle getDisplayBounds() { - return new Rectangle(0, 0, 0, 0); - } - - public static Point getLocation(int side) { - return DragOperations.getPoint(getDisplayBounds(), side); - } - - public static Point getPointInEditorArea() { - return new Point(0, 0); - } - - public static Point getPoint(Rectangle bounds, int side) { - Point centerPoint = Geometry.centerPoint(bounds); - - switch (side) { - case SWT.TOP: - return new Point(centerPoint.x, bounds.y + 1); - case SWT.BOTTOM: - return new Point(centerPoint.x, bounds.y + bounds.height - 1); - case SWT.LEFT: - return new Point(bounds.x + 1, centerPoint.y); - case SWT.RIGHT: - return new Point(bounds.x + bounds.width - 1, centerPoint.y); - } - - return centerPoint; - } - - public static String nameForConstant(int swtSideConstant) { - switch (swtSideConstant) { - case SWT.TOP: - return "top"; - case SWT.BOTTOM: - return "bottom"; - case SWT.LEFT: - return "left"; - case SWT.RIGHT: - return "right"; - } - - return "center"; - } - - public static String getName(IViewPart targetPart) { - return targetPart.getTitle(); - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java deleted file mode 100644 index 4bdd03c13c5..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2025 Ali Muhsin KÖKSAL. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: - * Ali Muhsin KÖKSAL - initial API and implementation - *******************************************************************************/ - -package org.eclipse.ui.tests.dnd; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.ui.tests.api.MockEditorPart; -import org.eclipse.ui.tests.harness.util.FileUtil; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -public class DragTest { - - TestDragSource dragSource; - TestDropLocation dropTarget; - - static IProject project; - static IFile file1, file2, file3; - - IEditorPart editor1, editor2, editor3; - - static IWorkbenchWindow window; - static IWorkbenchPage page; - - public DragTest(TestDragSource dragSource, TestDropLocation dropTarget) { - this.dragSource = dragSource; - this.dropTarget = dropTarget; - } - - @AfterEach - public void doSetUp() throws Exception { - if (window == null) { - window = (IWorkbenchWindow) PlatformUI.getWorkbench(); - page = (IWorkbenchPage) window.getActivePage(); - - project = FileUtil.createProject("DragTest"); - file1 = FileUtil.createFile("DragTest1.txt", project); - file2 = FileUtil.createFile("DragTest2.txt", project); - file3 = FileUtil.createFile("DragTest3.txt", project); - } - - page.resetPerspective(); - page.closeAllEditors(false); - - page.showView("org.eclipse.ui.views.ContentOutline"); - page.hideView(page.findView("org.eclipse.ui.internal.introview")); - editor1 = page.openEditor(new FileEditorInput(file1), MockEditorPart.ID1); - editor2 = page.openEditor(new FileEditorInput(file2), MockEditorPart.ID2); - editor3 = page.openEditor(new FileEditorInput(file3), MockEditorPart.ID2); - - window.getShell().setActive(); - DragOperations.drag(editor2, new EditorDropTarget(new ExistingWindowProvider(window), 0, SWT.CENTER), false); - DragOperations.drag(editor3, new EditorAreaDropTarget(new ExistingWindowProvider(window), SWT.RIGHT), false); - } - - @Test - @DisplayName("drag editor2 to right") - public void stallTest() { - String[] testNames = {}; - boolean testNameMatches = false; - for (String testName : testNames) { - if (testName.equals("drag editor2 to right")) { - testNameMatches = true; - break; - } - } - - if (testNames.length == 0 || testNameMatches) { - Display display = Display.getCurrent(); - Shell loopShell = new Shell(display, SWT.SHELL_TRIM); - loopShell.setBounds(0, 0, 200, 100); - loopShell.setText("Test Stall Shell"); - loopShell.setVisible(true); - - while (loopShell != null && !loopShell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } - } - - @Test - public void performTest() throws Throwable { - dragSource.setPage(page); - dragSource.drag(dropTarget); - } -} diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTestSuite.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTestSuite.java deleted file mode 100644 index 4768fd53917..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTestSuite.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2025 Ali Muhsin KÖKSAL. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * Contributors: - * Ali Muhsin KÖKSAL - initial API and implementation - *******************************************************************************/ - -package org.eclipse.ui.tests.dnd; - -import java.util.stream.Stream; -import org.junit.jupiter.params.provider.Arguments; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IPageLayout; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -public class DragTestSuite { - - private static final boolean isDetachingSupported; - - static { - Shell shell = new Shell(); - Composite c = new Composite(shell, SWT.NONE); - isDetachingSupported = c.isReparentable(); - shell.dispose(); - } - - public DragTestSuite() {} - - @ParameterizedTest - @MethodSource("dragSourceDropTargetProvider") - void dragTest(TestDragSource dragSource, TestDropLocation dropTarget) { - new DragTest(dragSource, dropTarget); - } - - static Stream dragSourceDropTargetProvider() { - List args = new ArrayList<>(); - - String resNav = IPageLayout.ID_PROJECT_EXPLORER; - String probView = IPageLayout.ID_PROBLEM_VIEW; - - TestDragSource[] viewDragSources = new TestDragSource[] { new ViewDragSource(resNav, false), - new ViewDragSource(resNav, true), new ViewDragSource(probView, false), - new ViewDragSource(probView, true) }; - - TestDragSource[] editorDragSources = new TestDragSource[] { new EditorDragSource(0, false), - new EditorDragSource(0, true), new EditorDragSource(2, false), new EditorDragSource(2, true) }; - - for (TestDragSource source : viewDragSources) { - for (TestDropLocation target : getViewDropTargets(source)) { - if (target != null) { - args.add(Arguments.of(source, target)); - } - } - for (TestDropLocation target : getCommonDropTargets(source)) { - args.add(Arguments.of(source, target)); - } - } - - for (TestDragSource source : editorDragSources) { - for (TestDropLocation target : getEditorDropTargets(source)) { - args.add(Arguments.of(source, target)); - } - for (TestDropLocation target : getCommonDropTargets(source)) { - args.add(Arguments.of(source, target)); - } - } - - TestDragSource[] maximizedViewDragSources = new TestDragSource[] { new ViewDragSource(resNav, false, true), - new ViewDragSource(resNav, true, true), new ViewDragSource(probView, false, true), - new ViewDragSource(probView, true, true) }; - - for (TestDragSource source : maximizedViewDragSources) { - for (TestDropLocation target : getMaximizedViewDropTargets(source)) { - args.add(Arguments.of(source, target)); - } - } - - if (isDetachingSupported) { - for (TestDragSource source : viewDragSources) { - for (TestDropLocation target : getDetachedWindowDropTargets(source)) { - args.add(Arguments.of(source, target)); - } - } - for (TestDragSource source : editorDragSources) { - for (TestDropLocation target : getDetachedWindowDropTargets(source)) { - args.add(Arguments.of(source, target)); - } - } - } - - return args.stream(); - } - - /** - * Returns drop targets that will only be tested for maximized views. (we only - * need to ensure that the view will become un-maximized -- the regular view - * test cases will excercise the remainder of the view dragging code). We need - * to drag each kind of maximized view to something that couldn't be seen while - * the view is maximized -- like the editor area). - * - * @since 3.1 - */ - private static TestDropLocation[] getMaximizedViewDropTargets(IWorkbenchWindowProvider originatingWindow) { - return new TestDropLocation[] { new EditorAreaDropTarget(originatingWindow, SWT.RIGHT) }; - } - - private static TestDropLocation[] getCommonDropTargets(IWorkbenchWindowProvider dragSource) { - return new TestDropLocation[] { - // Test dragging to the edges of the workbench window - new WindowDropTarget(dragSource, SWT.TOP), new WindowDropTarget(dragSource, SWT.BOTTOM), - new WindowDropTarget(dragSource, SWT.LEFT), new WindowDropTarget(dragSource, SWT.RIGHT) }; - } - - /** - * Return all drop targets that only apply to views, given the window being - * dragged from. - * - * @since 3.1 - */ - private static TestDropLocation[] getViewDropTargets(IWorkbenchWindowProvider dragSource) { - - String resNav = IPageLayout.ID_PROJECT_EXPLORER; - String probView = IPageLayout.ID_PROBLEM_VIEW; - - return new TestDropLocation[] { - // Editor area - new EditorAreaDropTarget(dragSource, SWT.LEFT), new EditorAreaDropTarget(dragSource, SWT.RIGHT), - new EditorAreaDropTarget(dragSource, SWT.TOP), new EditorAreaDropTarget(dragSource, SWT.BOTTOM), - - // Resource navigator (a view that isn't in a stack) - new ViewDropTarget(dragSource, resNav, SWT.LEFT), new ViewDropTarget(dragSource, resNav, SWT.RIGHT), - new ViewDropTarget(dragSource, resNav, SWT.BOTTOM), new ViewDropTarget(dragSource, resNav, SWT.CENTER), - new ViewDropTarget(dragSource, resNav, SWT.TOP), - - // Problems view (a view that is in a stack) - // Omit the top from this test, since the meaning of dropping on the top border - // of - // a stack may change in the near future - new ViewDropTarget(dragSource, probView, SWT.LEFT), new ViewDropTarget(dragSource, probView, SWT.RIGHT), - new ViewDropTarget(dragSource, probView, SWT.BOTTOM), - new ViewDropTarget(dragSource, probView, SWT.CENTER), new ViewDropTarget(dragSource, probView, SWT.TOP), - - // Fast view bar - null, // new FastViewBarDropTarget(dragSource), - - // View tabs - new ViewTabDropTarget(dragSource, resNav), new ViewTabDropTarget(dragSource, probView), - new ViewTitleDropTarget(dragSource, probView), }; - } - - /** - * Return all drop targets that apply to detached windows, given the window - * being dragged from. - * - * @since 3.1 - */ - private static TestDropLocation[] getDetachedWindowDropTargets(IWorkbenchWindowProvider dragSource) { - return new TestDropLocation[] { - // Editor area - new ViewDropTarget(dragSource, DragDropPerspectiveFactory.dropViewId1, SWT.CENTER), - new ViewDropTarget(dragSource, DragDropPerspectiveFactory.dropViewId3, SWT.CENTER), - new ViewTabDropTarget(dragSource, DragDropPerspectiveFactory.dropViewId1), new DetachedDropTarget() }; - } - - private static TestDropLocation[] getEditorDropTargets(IWorkbenchWindowProvider originatingWindow) { - String resNav = IPageLayout.ID_PROJECT_EXPLORER; - // Drop targets that will only be tested for editors - return new TestDropLocation[] { - // A view - new ViewDropTarget(originatingWindow, resNav, SWT.CENTER), - - // A stand-alone editor - new EditorDropTarget(originatingWindow, 2, SWT.LEFT), - new EditorDropTarget(originatingWindow, 2, SWT.RIGHT), - new EditorDropTarget(originatingWindow, 2, SWT.TOP), - new EditorDropTarget(originatingWindow, 2, SWT.BOTTOM), - new EditorDropTarget(originatingWindow, 2, SWT.CENTER), - - // Editors (a stack of editors) - new EditorDropTarget(originatingWindow, 0, SWT.LEFT), - new EditorDropTarget(originatingWindow, 0, SWT.RIGHT), - new EditorDropTarget(originatingWindow, 0, SWT.BOTTOM), - new EditorDropTarget(originatingWindow, 0, SWT.CENTER), new EditorTabDropTarget(originatingWindow, 0), - new EditorTitleDropTarget(originatingWindow, 0), }; - } - -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorAreaDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorAreaDropTarget.java deleted file mode 100644 index 7a8708ef6b9..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorAreaDropTarget.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.swt.graphics.Point; - -public class EditorAreaDropTarget extends WorkbenchWindowDropTarget { - int side; - - public EditorAreaDropTarget(IWorkbenchWindowProvider provider, int side) { - super(provider); - this.side = side; - } - - @Override - public String toString() { - return DragOperations.nameForConstant(side) + " of editor area"; - } - - @Override - public Point getLocation() { - return DragOperations.getPointInEditorArea(); - } - -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDragSource.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDragSource.java deleted file mode 100644 index 1f77794337c..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDragSource.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.ui.IEditorPart; - -public class EditorDragSource extends TestDragSource { - - int editorIdx; - - boolean wholeFolder; - - public EditorDragSource(int editorIdx, boolean wholeFolder) { - super(); - this.editorIdx = editorIdx; - this.wholeFolder = wholeFolder; - } - - IEditorPart getPart() { - return getPage().getEditorReferences()[editorIdx].getEditor(true); - } - - @Override - public String toString() { - String title = "editor " + editorIdx; - - if (wholeFolder) { - return title + " folder"; - } - return title; - } - - @Override - public void drag(TestDropLocation target) { - DragOperations.drag(getPart(), target, wholeFolder); - } - -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDropTarget.java deleted file mode 100644 index f2f2a472d88..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorDropTarget.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; - -public class EditorDropTarget extends WorkbenchWindowDropTarget { - - int editorIdx; - - int side; - - public EditorDropTarget(IWorkbenchWindowProvider provider, int editorIdx, int side) { - super(provider); - this.editorIdx = editorIdx; - this.side = side; - } - - IEditorPart getPart() { - return getPage().getEditorReferences()[editorIdx].getEditor(true); - } - - @Override - public String toString() { - return DragOperations.nameForConstant(side) + " of editor " + editorIdx; - } - - @Override - public Point getLocation() { - return DragOperations.getLocation(side); - } - - @Override - public Shell getShell() { - return getPart().getSite().getShell(); - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTabDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTabDropTarget.java deleted file mode 100644 index d2cd00b1fda..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTabDropTarget.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; - -public class EditorTabDropTarget extends WorkbenchWindowDropTarget { - - int editorIdx; - - public EditorTabDropTarget(IWorkbenchWindowProvider provider, int editorIdx) { - super(provider); - this.editorIdx = editorIdx; - } - - IEditorPart getPart() { - return getPage().getEditorReferences()[editorIdx].getEditor(true); - } - - @Override - public String toString() { - return "editor " + editorIdx + " tab area"; - } - - @Override - public Shell getShell() { - return getPart().getSite().getShell(); - } - - @Override - public Point getLocation() { - Rectangle bounds = DragOperations.getDisplayBounds(); - - return new Point(bounds.x + 8, bounds.y + 8); - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTitleDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTitleDropTarget.java deleted file mode 100644 index 52d65237cf8..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/EditorTitleDropTarget.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; - -public class EditorTitleDropTarget extends WorkbenchWindowDropTarget { - - int editorIdx; - - public EditorTitleDropTarget(IWorkbenchWindowProvider provider, int editorIdx) { - super(provider); - this.editorIdx = editorIdx; - } - - IEditorPart getPart() { - return getPage().getEditorReferences()[editorIdx].getEditor(true); - } - - @Override - public String toString() { - return "editor " + editorIdx + " title area"; - } - - @Override - public Shell getShell() { - return getPart().getSite().getShell(); - } - - @Override - public Point getLocation() { - Rectangle bounds = DragOperations.getDisplayBounds(); - - return new Point( (bounds.x + bounds.width) - 4, bounds.y + 4); - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ExistingWindowProvider.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ExistingWindowProvider.java deleted file mode 100644 index 738e6fb1827..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ExistingWindowProvider.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.ui.IWorkbenchWindow; - -public class ExistingWindowProvider implements IWorkbenchWindowProvider { - - private final IWorkbenchWindow window; - - public ExistingWindowProvider(IWorkbenchWindow window) { - this.window = window; - } - - @Override - public IWorkbenchWindow getWorkbenchWindow() { - return window; - } - -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/IWorkbenchWindowProvider.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/IWorkbenchWindowProvider.java deleted file mode 100644 index cab0f890a1b..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/IWorkbenchWindowProvider.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.ui.IWorkbenchWindow; - -public interface IWorkbenchWindowProvider { - public IWorkbenchWindow getWorkbenchWindow(); -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/StandaloneViewPerspective.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/StandaloneViewPerspective.java deleted file mode 100644 index 1dca53da9d4..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/StandaloneViewPerspective.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.ui.IPageLayout; -import org.eclipse.ui.IPerspectiveFactory; - -public class StandaloneViewPerspective implements IPerspectiveFactory { - - public static final String OUTLINE_ID = IPageLayout.ID_OUTLINE; - - public static final String RESOURCE_ID = IPageLayout.ID_PROJECT_EXPLORER; - - public static final String TASK_ID = IPageLayout.ID_TASK_LIST; - - public static final String PERSP_ID = "org.eclipse.ui.tests.dnd.StandaloneViewPerspective"; - - public StandaloneViewPerspective() { - // do nothing - } - - @Override - public void createInitialLayout(IPageLayout layout) { - layout.setEditorAreaVisible(true); - - layout.addStandaloneView(RESOURCE_ID, true, IPageLayout.LEFT, 0.25f, IPageLayout.ID_EDITOR_AREA); - layout.addStandaloneView(OUTLINE_ID, true, IPageLayout.RIGHT, 0.25f, IPageLayout.ID_EDITOR_AREA); - layout.getViewLayout(OUTLINE_ID).setCloseable(false); - layout.addStandaloneView(TASK_ID, true, IPageLayout.BOTTOM, 0.25f, IPageLayout.ID_EDITOR_AREA); - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDragSource.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDragSource.java deleted file mode 100644 index 37cf5f36d93..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDragSource.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; - -public abstract class TestDragSource implements IWorkbenchWindowProvider { - private IWorkbenchPage page; - - @Override - public abstract String toString(); - - public abstract void drag(TestDropLocation target); - - public void setPage(IWorkbenchPage page) { - this.page = page; - } - - @Override - public IWorkbenchWindow getWorkbenchWindow() { - return getPage().getWorkbenchWindow(); - } - - public IWorkbenchPage getPage() { - if (page == null) { - page = PlatformUI - .getWorkbench().getActiveWorkbenchWindow().getActivePage(); - } - return page; - } - - -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDropLocation.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDropLocation.java deleted file mode 100644 index 10884d36f94..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDropLocation.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Shell; - -/** - * This is an interface intended for use in test suites. Objects can implement - * this interface to force any dragged object to be dropped at a particular - * location. - * - */ -public interface TestDropLocation { - - /** - * Location where the object should be dropped, in display coordinates - * - * @return a location in display coordinates - */ - Point getLocation(); - - /** - * The drop code will pretend that only the given shells are open, - * and that they have the specified Z-order. - * - * @return the shells to check for drop targets, from bottom to top. - */ - Shell[] getShells(); -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDragSource.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDragSource.java deleted file mode 100644 index e047c95c580..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDragSource.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.eclipse.ui.tests.dnd; - - -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.IViewDescriptor; -import org.junit.Assert; - -public class ViewDragSource extends TestDragSource { - - String targetPart; - - boolean wholeFolder; - - boolean maximized = false; - - public ViewDragSource(String part, boolean dragWholeFolder) { - this(part, dragWholeFolder, false); - } - - public ViewDragSource(String part, boolean dragWholeFolder, - boolean maximized) { - this.maximized = maximized; - this.targetPart = part; - - wholeFolder = dragWholeFolder; - } - - public IViewPart getPart() { - return getPage().findView(targetPart); - } - - @Override - public String toString() { - IViewDescriptor desc = PlatformUI.getWorkbench().getViewRegistry() - .find(targetPart); - String title = desc.getLabel(); - - if (wholeFolder) { - title = title + " folder"; - } - - if (maximized) { - title = "maximized " + title; - } - - return title; - } - - @Override - public void drag(TestDropLocation target) { - IViewPart part = getPart(); - - IWorkbenchPage page = getPage(); - if (maximized) { - page.toggleZoom(page.getReference(part)); - } - -// DragUtil.forceDropLocation(target); -// ViewStack parent = ((ViewStack) (pane.getContainer())); -// -// PartPane presentablePart = wholeFolder ? null : pane; -// parent.paneDragStart(presentablePart, Display.getDefault() -// .getCursorLocation(), false); - Assert.fail("DND needs updated"); - -// DragUtil.forceDropLocation(null); - } - -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDropTarget.java deleted file mode 100644 index 42947b718c7..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewDropTarget.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.IViewDescriptor; - -public class ViewDropTarget extends WorkbenchWindowDropTarget { - - String targetPart; - - int side; - - public ViewDropTarget(IWorkbenchWindowProvider provider, String part, int side) { - super(provider); - targetPart = part; - this.side = side; - } - - IViewPart getPart() { - return getPage().findView(targetPart); - } - - @Override - public String toString() { - IViewDescriptor desc = PlatformUI.getWorkbench().getViewRegistry() - .find(targetPart); - String title = desc.getLabel(); - - return DragOperations.nameForConstant(side) + " of " + title; - } - - @Override - public Point getLocation() { - return DragOperations.getLocation(side); - } - - @Override - public Shell getShell() { - return getPart().getSite().getShell(); - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTabDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTabDropTarget.java deleted file mode 100644 index 0ed1a2671f0..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTabDropTarget.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.IViewDescriptor; - -/** - * Note: this drop location is hardcoded to assume a presentation that has - * a tab drop location at the upper left corner, 8 pixels away from the - * edge in both dimensions. This drop location should be omitted from the - * tests in situations where this does not apply (this is not a problem - * right now since the current tests only use the tabs-on-top drop - * location). - * - */ -public class ViewTabDropTarget extends WorkbenchWindowDropTarget { - - String targetPart; - - public ViewTabDropTarget(IWorkbenchWindowProvider provider, String part) { - super(provider); - targetPart = part; - } - - IViewPart getPart() { - return getPage().findView(targetPart); - } - - @Override - public String toString() { - IViewDescriptor desc = PlatformUI.getWorkbench().getViewRegistry() - .find(targetPart); - String title = desc.getLabel(); - - return title + " view tab area"; - } - - @Override - public Point getLocation() { - Rectangle bounds = DragOperations.getDisplayBounds(); - - return new Point(bounds.x + 8, bounds.y + 8); - } - - @Override - public Shell getShell() { - return getPart().getSite().getShell(); - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTitleDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTitleDropTarget.java deleted file mode 100644 index 8cc07476794..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/ViewTitleDropTarget.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.IViewDescriptor; - -/** - * Note: this drop location is hardcoded to assume a presentation that has - * a tab drop location at the upper left corner, 8 pixels away from the - * edge in both dimensions. This drop location should be omitted from the - * tests in situations where this does not apply (this is not a problem - * right now since the current tests only use the tabs-on-top drop - * location). - * - */ -public class ViewTitleDropTarget extends WorkbenchWindowDropTarget { - - String targetPart; - - public ViewTitleDropTarget(IWorkbenchWindowProvider provider, String part) { - super(provider); - targetPart = part; - } - - IViewPart getPart() { - return getPage().findView(targetPart); - } - - @Override - public String toString() { - IViewDescriptor desc = PlatformUI.getWorkbench().getViewRegistry() - .find(targetPart); - String title = desc.getLabel(); - - return title + " view title area"; - } - - @Override - public Point getLocation() { - Rectangle bounds = DragOperations.getDisplayBounds(); - - return new Point( (bounds.x + bounds.width) - 8, bounds.y + 8); - } - - @Override - public Shell getShell() { - return getPart().getSite().getShell(); - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WindowDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WindowDropTarget.java deleted file mode 100644 index 255e4ea0a28..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WindowDropTarget.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.jface.util.Geometry; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Shell; - -public class WindowDropTarget extends WorkbenchWindowDropTarget { - - private final int side; - - public WindowDropTarget(IWorkbenchWindowProvider provider, int side) { - super(provider); - this.side = side; - } - - @Override - public String toString() { - return DragOperations.nameForConstant(side) + " of window"; - } - - @Override - public Point getLocation() { - Shell shell = getShell(); - Rectangle clientArea = shell.getClientArea(); - - return DragOperations.getPoint(Geometry.toDisplay(shell, clientArea), - side); - } -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WorkbenchWindowDropTarget.java b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WorkbenchWindowDropTarget.java deleted file mode 100644 index 6ef5d72df0f..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/WorkbenchWindowDropTarget.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.eclipse.ui.tests.dnd; - -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; - -public abstract class WorkbenchWindowDropTarget implements TestDropLocation { - - private final IWorkbenchWindowProvider window; - - @Override - public abstract String toString(); - - @Override - public abstract Point getLocation(); - - public WorkbenchWindowDropTarget(IWorkbenchWindowProvider window) { - this.window = window; - } - - public IWorkbenchWindow getWindow() { - return window.getWorkbenchWindow(); - } - - public Shell getShell() { - return getWindow().getShell(); - } - - public IWorkbenchPage getPage() { - return (IWorkbenchPage)getWindow().getActivePage(); - } - - @Override - public Shell[] getShells() { - return new Shell[] {getShell()}; - } - -} \ No newline at end of file diff --git a/tests/org.eclipse.ui.tests.dnd/test.xml b/tests/org.eclipse.ui.tests.dnd/test.xml deleted file mode 100644 index cacfb19017c..00000000000 --- a/tests/org.eclipse.ui.tests.dnd/test.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file