+ * This method should eventually replace the original one once the Workbench has been updated + * to handle Views and Editors without distincton. + */ + @SuppressWarnings("unused") + public static void drag(IWorkbenchPart part, TestDropLocation target, boolean wholeFolder) { +// DragUtil.forceDropLocation(target); + +// PartSite site = (PartSite) part.getSite(); +// PartPane pane = site.getPane(); +// PartStack parent = ((PartStack) (pane.getContainer())); +// +// parent.paneDragStart(wholeFolder ? null : pane, Display.getDefault().getCursorLocation(), false); + + Assert.fail("DND needs some updating"); +// DragUtil.forceDropLocation(null); + } + + /** + * 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..76f7cad3705 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * 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.internal.WorkbenchPage; +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((WorkbenchPage) 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..b892ef76885 --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTestSuite.java @@ -0,0 +1,218 @@ +/******************************************************************************* + * 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.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IPageLayout; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.AllTests; + +import junit.framework.Test; + +@RunWith(AllTests.class) +@Ignore("DND support not implemented yet in E4") +public class DragTestSuite { + + public static Test suite() { + return (Test) new 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() { + + String resNav = IPageLayout.ID_PROJECT_EXPLORER; + String probView = IPageLayout.ID_PROBLEM_VIEW; + + // Drag sources for views + TestDragSource[] viewDragSources = new TestDragSource[] { + new ViewDragSource(resNav, false), + new ViewDragSource(resNav, true), + new ViewDragSource(probView, false), + new ViewDragSource(probView, true) }; + + // Drag sources for editors + TestDragSource[] editorDragSources = new TestDragSource[] { + new EditorDragSource(0, false), new EditorDragSource(0, true), + new EditorDragSource(2, false), new EditorDragSource(2, true) }; + + // Drop targets that will only be tested for views + + // Drag sources for maximized views + TestDragSource[] maximizedViewDragSources = new TestDragSource[] { + new ViewDragSource(resNav, false, true), + new ViewDragSource(resNav, true, true), + new ViewDragSource(probView, false, true), + new ViewDragSource(probView, true, true) }; + + // Now generate all test cases + for (TestDragSource source : maximizedViewDragSources) { + addAllCombinations(source, getMaximizedViewDropTargets(source)); + } + + for (TestDragSource source : viewDragSources) { + addAllCombinations(source, getViewDropTargets(source)); + addAllCombinations(source, getCommonDropTargets(source)); + + // Test dragging onto a detached window + addAllCombinationsDetached(source, getDetachedWindowDropTargets(source)); + } + + for (TestDragSource source : editorDragSources) { + addAllCombinations(source, getEditorDropTargets(source)); + addAllCombinations(source, getCommonDropTargets(source)); + + // Test dragging onto a detached window + addAllCombinationsDetached(source, getDetachedWindowDropTargets(source)); + } + //addTest(new TestSuite(Bug87211Test.class)); + } + + /** + * 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 TestDropLocation[] getMaximizedViewDropTargets(IWorkbenchWindowProvider originatingWindow) { + return new TestDropLocation[] { + new EditorAreaDropTarget(originatingWindow, SWT.RIGHT) }; + } + + private 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 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 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 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), + }; + } + + @org.junit.jupiter.api.Test + private void addAllCombinations(TestDragSource dragSource, + TestDropLocation[] dropTargets) { + + for (TestDropLocation dropTarget : dropTargets) { + if (dropTarget == null) { + continue; + } + + new DragTest(dragSource, dropTarget); + } + } + + @org.junit.jupiter.api.Test + private void addAllCombinationsDetached(TestDragSource dragSource, + TestDropLocation[] dropTargets) { + + if (isDetachingSupported) { + for (TestDropLocation dropTarget : dropTargets) { + new DetachedWindowDragTest(dragSource, dropTarget); + } + } + } + +} \ 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..93f2a5644f1 --- /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().getEditors()[editorIdx]; + } + + @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..91f18827945 --- /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().getEditors()[editorIdx]; + } + + @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..9b9c26c0212 --- /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().getEditors()[editorIdx]; + } + + @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..ddc28334cbb --- /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().getEditors()[editorIdx]; + } + + @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..ce7eb61f9eb --- /dev/null +++ b/tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/TestDragSource.java @@ -0,0 +1,34 @@ +package org.eclipse.ui.tests.dnd; + +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.WorkbenchPage; +import org.eclipse.ui.internal.WorkbenchWindow; + +public abstract class TestDragSource implements IWorkbenchWindowProvider { + private WorkbenchPage page; + + @Override + public abstract String toString(); + + public abstract void drag(TestDropLocation target); + + public void setPage(WorkbenchPage page) { + this.page = page; + } + + @Override + public IWorkbenchWindow getWorkbenchWindow() { + return getPage().getWorkbenchWindow(); + } + + public WorkbenchPage getPage() { + if (page == null) { + page = (WorkbenchPage) ((WorkbenchWindow) 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..5db6c11e1d0 --- /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.internal.WorkbenchPage; +import org.eclipse.ui.internal.WorkbenchPlugin; +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 = WorkbenchPlugin.getDefault().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(); + + WorkbenchPage 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..d38917370bd --- /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.internal.WorkbenchPlugin; +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 = WorkbenchPlugin.getDefault().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..587f2d1318e --- /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.internal.WorkbenchPlugin; +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 = WorkbenchPlugin.getDefault().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..493d28325d4 --- /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.internal.WorkbenchPlugin; +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 = WorkbenchPlugin.getDefault().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..4b4a6232ad1 --- /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.IWorkbenchWindow; +import org.eclipse.ui.internal.WorkbenchPage; + +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 WorkbenchPage getPage() { + return (WorkbenchPage)getWindow().getActivePage(); + } + + @Override + public Shell[] getShells() { + return new Shell[] {getShell()}; + } + +} \ No newline at end of file