From da95734a7815c7f45d06fcd9229d7aed4274c82f Mon Sep 17 00:00:00 2001 From: Pauline DEVILLE Date: Wed, 24 Apr 2019 16:26:36 +0200 Subject: Bug 546686: [SashEditor] Remove internal dependencies * Remove unused Class in eclipsecopy (no dependency in papyrus) ** SwtUtil ** TestDropLocation ** CompatibilityDragTarget Change-Id: Ic9f0cf3cdb1fbf5306a9720f6033bea02e48f656 Signed-off-by: Pauline DEVILLE --- .../eclipsecopy/CompatibilityDragTarget.java | 63 ------ .../sasheditor/internal/eclipsecopy/SwtUtil.java | 242 --------------------- .../internal/eclipsecopy/TestDropLocation.java | 42 ---- 3 files changed, 347 deletions(-) delete mode 100755 plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/CompatibilityDragTarget.java delete mode 100755 plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/SwtUtil.java delete mode 100755 plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/TestDropLocation.java diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/CompatibilityDragTarget.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/CompatibilityDragTarget.java deleted file mode 100755 index 0d2001062a2..00000000000 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/CompatibilityDragTarget.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2017 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.papyrus.infra.core.sasheditor.internal.eclipsecopy; - -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.Control; - -/** - * Compatibility layer for the old-style drag-and-drop. Adapts an old-style - * IPartDropListener into an IDragTarget. - * - */ -public class CompatibilityDragTarget { - - // Define width of part's "hot" border - private static final int MARGIN = 30; - - /** - * Returns the relative position of the given point (in display coordinates) - * with respect to the given control. Returns one of SWT.LEFT, SWT.RIGHT, SWT.CENTER, SWT.TOP, - * or SWT.BOTTOM if the point is on the control or SWT.DEFAULT if the point is not on the control. - * - * @param control - * control to perform hit detection on - * @param toTest - * point to test, in display coordinates - * @return - */ - public static int getRelativePosition(Control c, Point toTest) { - Point p = c.toControl(toTest); - Point e = c.getSize(); - - if (p.x > e.x || p.y > e.y || p.x < 0 || p.y < 0) { - return SWT.DEFAULT; - } - - // first determine whether mouse position is in center of part - int hmargin = Math.min(e.x / 3, MARGIN); - int vmargin = Math.min(e.y / 3, MARGIN); - - Rectangle inner = new Rectangle(hmargin, vmargin, e.x - (hmargin * 2), - e.y - (vmargin * 2)); - if (inner.contains(p)) { - return SWT.CENTER; - } - return Geometry.getClosestSide(inner, p); - } - -} diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/SwtUtil.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/SwtUtil.java deleted file mode 100755 index f264aca4df0..00000000000 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/SwtUtil.java +++ /dev/null @@ -1,242 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2015, 2019 IBM Corporation, CEA LIST 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 - * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 546686 - *******************************************************************************/ -package org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy; - -import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.PapyrusDragUtils; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Monitor; -import org.eclipse.swt.widgets.Shell; - -/** - * Contains static methods for manipulating SWT controls - * - * @since 3.0 - */ -public class SwtUtil { - - private SwtUtil() { - - } - - /** - * Returns true if the given control is null or has been disposed - * - * @param toTest - * the control to test - * @return false if it is safe to invoke methods on the given control - */ - public static boolean isDisposed(Control toTest) { - return toTest == null || toTest.isDisposed(); - } - - /** - * Returns the control that is covering the given control, or null if none. - * - * @param toTest - * control to test - * @return a control that obscures the test control or null if none - */ - public static Control controlThatCovers(Control toTest) { - return controlThatCovers(toTest, PapyrusDragUtils.getDisplayBounds(toTest)); - } - - private static Control controlThatCovers(Control toTest, Rectangle testRegion) { - Composite parent = toTest.getParent(); - - if (parent == null || toTest instanceof Shell) { - return null; - } - - for (Control element : parent.getChildren()) { - Control control = element; - - if (control == toTest) { - break; - } - - if (!control.isVisible()) { - continue; - } - - Rectangle nextBounds = PapyrusDragUtils.getDisplayBounds(control); - - if (nextBounds.intersects(testRegion)) { - return control; - } - } - - return controlThatCovers(parent, testRegion); - } - - /** - * Determines if one control is a child of another. - * - * @param potentialParent - * @param childToTest - * @return true if the second argument is a child of the first - * or the same object, false otherwise - */ - public static boolean isChild(Control potentialParent, Control childToTest) { - if (childToTest == null) { - return false; - } - - if (childToTest == potentialParent) { - return true; - } - - return isChild(potentialParent, childToTest.getParent()); - } - - public static boolean isFocusAncestor(Control potentialParent) { - if (potentialParent == null) { - return false; - } - Control focusControl = Display.getCurrent().getFocusControl(); - if (focusControl == null) { - return false; - } - return isChild(potentialParent, focusControl); - } - - /** - * Finds and returns the most specific SWT control at the given location. - * (Note: this does a DFS on the SWT widget hierarchy, which is slow). - * - * @param displayToSearch - * @param locationToFind - * @return the most specific SWT control at the given location - */ - public static Control findControl(Display displayToSearch, - Point locationToFind) { - Shell[] shells = displayToSearch.getShells(); - - return findControl(shells, locationToFind); - } - - /** - * Searches the given list of controls for a control containing the given point. - * If the array contains any composites, those composites will be recursively - * searched to find the most specific child that contains the point. - * - * @param toSearch - * an array of composites - * @param locationToFind - * a point (in display coordinates) - * @return the most specific Control that overlaps the given point, or null if none - */ - public static Control findControl(Control[] toSearch, Point locationToFind) { - for (int idx = toSearch.length - 1; idx >= 0; idx--) { - Control next = toSearch[idx]; - - if (!next.isDisposed() && next.isVisible()) { - - Rectangle bounds = PapyrusDragUtils.getDisplayBounds(next); - - if (bounds.contains(locationToFind)) { - if (next instanceof Composite) { - Control result = findControl((Composite) next, - locationToFind); - - if (result != null) { - return result; - } - } - - return next; - } - } - } - - return null; - } - - public static Control[] getAncestors(Control theControl) { - return getAncestors(theControl, 1); - } - - private static Control[] getAncestors(Control theControl, int children) { - Control[] result; - - if (theControl.getParent() == null) { - result = new Control[children]; - } else { - result = getAncestors(theControl.getParent(), children + 1); - } - - result[result.length - children] = theControl; - - return result; - } - - public static Control findCommonAncestor(Control control1, Control control2) { - Control[] control1Ancestors = getAncestors(control1); - Control[] control2Ancestors = getAncestors(control2); - - Control mostSpecific = null; - - for (int idx = 0; idx < Math.min(control1Ancestors.length, control2Ancestors.length); idx++) { - Control control1Ancestor = control1Ancestors[idx]; - if (control1Ancestor == control2Ancestors[idx]) { - mostSpecific = control1Ancestor; - } else { - break; - } - } - - return mostSpecific; - } - - /** - * Finds the control at the given location. - * - * @param toSearch - * @param locationToFind - * location (in display coordinates) - * @return the control at the given location - */ - public static Control findControl(Composite toSearch, Point locationToFind) { - Control[] children = toSearch.getChildren(); - - return findControl(children, locationToFind); - } - - /** - * - * Returns true iff the given rectangle is located in the client area of any - * monitor. - * - * @param display - * the display - * @param someRectangle - * a rectangle in display coordinates (not null) - * @return true iff the given point can be seen on any monitor - */ - public static boolean intersectsAnyMonitor(Display display, - Rectangle someRectangle) { - for (Monitor monitor : display.getMonitors()) { - if (monitor.getClientArea().intersects(someRectangle)) { - return true; - } - } - - return false; - } - -} diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/TestDropLocation.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/TestDropLocation.java deleted file mode 100755 index d8230b46f50..00000000000 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/TestDropLocation.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2015 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.papyrus.infra.core.sasheditor.internal.eclipsecopy; - -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. - * - * @since 3.0 - */ -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(); -} -- cgit v1.2.3