Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPauline DEVILLE2019-05-06 08:13:48 -0400
committerNicolas FAUVERGUE2019-05-20 05:54:22 -0400
commit206f77979ba67b2842b83e93b679c26c1c8a4c85 (patch)
tree67da3937ef011ba7d9d8e9f3374c08860a866e18 /plugins
parent5fa5dbaf710fc2fb3510a405fca12e2c239c60d8 (diff)
downloadorg.eclipse.papyrus-206f77979ba67b2842b83e93b679c26c1c8a4c85.tar.gz
org.eclipse.papyrus-206f77979ba67b2842b83e93b679c26c1c8a4c85.tar.xz
org.eclipse.papyrus-206f77979ba67b2842b83e93b679c26c1c8a4c85.zip
Bug 546686: [SashEditor] Remove internal dependencies
* Remove dependency to import org.eclipse.ui.internal.DragCursors create cursor on dragManader instead Change-Id: I9b2d90ebf8b7042261e44e584cd94a6fe17737bf Signed-off-by: Pauline DEVILLE <pauline.deville@cea.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/SashWindowsContainer.java7
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/TabFolderPart.java12
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/DragManager.java167
3 files changed, 173 insertions, 13 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/SashWindowsContainer.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/SashWindowsContainer.java
index 02d8ae22505..c6deb38061c 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/SashWindowsContainer.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/SashWindowsContainer.java
@@ -13,6 +13,7 @@
* Christian W. Damus (CEA) - bug 437217
* Christian W. Damus - bug 488791
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 546686
+ * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 546686
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.internal;
@@ -53,7 +54,6 @@ import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.internal.DragCursors;
/**
@@ -63,7 +63,6 @@ import org.eclipse.ui.internal.DragCursors;
*
* @author dumoulin
*/
-@SuppressWarnings("restriction")
public class SashWindowsContainer implements ISashWindowsContainer {
/**
@@ -1148,9 +1147,7 @@ public class SashWindowsContainer implements ISashWindowsContainer {
*/
@Override
public Cursor getCursor() {
- // System.out.println(SashWindowsContainer.this.getClass().getSimpleName() + ".getCursor()-" + count++);
- return DragCursors.getCursor(DragCursors.positionToDragCursor(cursor));
-
+ return DragManager.getInstance().getDragCursor(cursor);
}
@Override
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/TabFolderPart.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/TabFolderPart.java
index 0010caa1f57..309dd045c85 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/TabFolderPart.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/TabFolderPart.java
@@ -14,6 +14,7 @@
* Christian W. Damus (CEA) - bug 392301
* Christian W. Damus - bug 469188
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 546686
+ * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 546686
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.internal;
@@ -51,7 +52,6 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.internal.DragCursors;
/**
* Controller associated to a tabfolder.
@@ -69,7 +69,6 @@ import org.eclipse.ui.internal.DragCursors;
* TODO : be more precise for the generic type ?
* TODO : Listen to the page change event, and call setActivePage().
*/
-@SuppressWarnings("restriction")
public class TabFolderPart extends AbstractTabFolderPart implements IFolder {
/** Interface to the model */
@@ -702,7 +701,7 @@ public class TabFolderPart extends AbstractTabFolderPart implements IFolder {
*/
protected class DropTarget implements IDropTarget {
- int cursor = SWT.CENTER;
+ private Cursor cursor = null;
private TabFolderPart sourcePart;
@@ -761,9 +760,10 @@ public class TabFolderPart extends AbstractTabFolderPart implements IFolder {
*/
@Override
public Cursor getCursor() {
- // System.out.println(TabFolderPart.this.getClass().getSimpleName() + ".getCursor()-" + count++);
- return DragCursors.getCursor(DragCursors.positionToDragCursor(cursor));
-
+ if (cursor == null) {
+ cursor = DragManager.getInstance().getDragCursor(SWT.CENTER);
+ }
+ return cursor;
}
@Override
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/DragManager.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/DragManager.java
index 501354e3d81..1acf5ea6df5 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/DragManager.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/DragManager.java
@@ -10,6 +10,7 @@
*
* Contributors:
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 546686
*
*****************************************************************************/
@@ -19,16 +20,20 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.Geometry;
+import org.eclipse.papyrus.infra.core.sasheditor.Activator;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tracker;
+import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.internal.DragCursors;
/**
* This allows to manage the drag actions with drag targets.
@@ -191,7 +196,7 @@ public class DragManager {
snapTarget = target.getSnapRectangle();
tracker.setCursor(target.getCursor());
} else {
- tracker.setCursor(DragCursors.getCursor(DragCursors.INVALID));
+ tracker.setCursor(getInvalidDragCursor());
}
// If snapping then reset the tracker's rectangle based on the current drop target
@@ -340,4 +345,162 @@ public class DragManager {
// No controls could handle this event -- check for default targets
return getDropTarget(defaultTargets, toSearch, draggedObject, position, dragRectangle);
}
+
+ /**
+ * @return an invalid cursor
+ */
+ public Cursor getInvalidDragCursor() {
+ return DragCursors.getCursor(DragCursors.INVALID);
+ }
+
+ /**
+ * @param swtPositionConstant
+ * the SWT position constant corresponding to the drag position (ex: SWT.RIGHT, SWT.CENTER ...)
+ * @return a cursor corresponding to the swtPositionConstant
+ */
+ public Cursor getDragCursor(int swtPositionConstant) {
+ return DragCursors.getCursor(DragCursors.positionToDragCursor(swtPositionConstant));
+ }
+
+ private static class DragCursors {
+
+ public static final int INVALID = 0;
+
+ public static final int LEFT = INVALID + 1;
+
+ public static final int RIGHT = LEFT + 1;
+
+ public static final int TOP = RIGHT + 1;
+
+ public static final int BOTTOM = TOP + 1;
+
+ public static final int CENTER = BOTTOM + 1;
+
+ public static final int OFFSCREEN = CENTER + 1;
+
+ public static final int FASTVIEW = OFFSCREEN + 1;
+
+ public static final Cursor cursors[] = new Cursor[8];
+
+ /**
+ * Return the cursor for a drop scenario, as identified by code. Code must be one of INVALID,
+ * LEFT, RIGHT, TOP, etc. If the code is not found default to INVALID.
+ *
+ * @param code
+ * the code
+ * @return the cursor
+ */
+ public static Cursor getCursor(int code) {
+ Display display = Display.getCurrent();
+ if (cursors[code] == null) {
+ int imageSize = 16;
+ ISharedImages sharedImages = getSharedImages();
+ ImageData sourceImage = null;
+ ImageData maskImage = null;
+ switch (code) {
+ case LEFT:
+ sourceImage = getImageDate(ISharedImages.IMG_OBJS_DND_LEFT_SOURCE, sharedImages);
+ maskImage = getImageDate(ISharedImages.IMG_OBJS_DND_LEFT_MASK, sharedImages);
+ break;
+ case RIGHT:
+ sourceImage = getImageDate(ISharedImages.IMG_OBJS_DND_RIGHT_SOURCE, sharedImages);
+ maskImage = getImageDate(ISharedImages.IMG_OBJS_DND_RIGHT_MASK, sharedImages);
+ break;
+ case TOP:
+ sourceImage = getImageDate(ISharedImages.IMG_OBJS_DND_TOP_SOURCE, sharedImages);
+ maskImage = getImageDate(ISharedImages.IMG_OBJS_DND_TOP_MASK, sharedImages);
+ break;
+ case BOTTOM:
+ sourceImage = getImageDate(ISharedImages.IMG_OBJS_DND_BOTTOM_SOURCE, sharedImages);
+ maskImage = getImageDate(ISharedImages.IMG_OBJS_DND_BOTTOM_MASK, sharedImages);
+ break;
+ case CENTER:
+ sourceImage = getImageDate(ISharedImages.IMG_OBJS_DND_STACK_SOURCE, sharedImages);
+ maskImage = getImageDate(ISharedImages.IMG_OBJS_DND_STACK_MASK, sharedImages);
+ break;
+ case OFFSCREEN:
+ sourceImage = getImageDate(ISharedImages.IMG_OBJS_DND_OFFSCREEN_SOURCE, sharedImages);
+ maskImage = getImageDate(ISharedImages.IMG_OBJS_DND_OFFSCREEN_MASK, sharedImages);
+ break;
+ case FASTVIEW:
+ sourceImage = getImageDate(ISharedImages.IMG_OBJS_DND_TOFASTVIEW_SOURCE, sharedImages);
+ maskImage = getImageDate(ISharedImages.IMG_OBJS_DND_TOFASTVIEW_MASK, sharedImages);
+ break;
+ default:
+ case INVALID:
+ sourceImage = getImageDate(ISharedImages.IMG_OBJS_DND_INVALID_SOURCE, sharedImages);
+ maskImage = getImageDate(ISharedImages.IMG_OBJS_DND_INVALID_MASK, sharedImages);
+ break;
+ }
+ if (sourceImage == null) {
+ Activator.log.warn("The source image of the drag cursor is null"); //$NON-NLS-1$
+ return null;
+ }
+ if (maskImage == null) {
+ Activator.log.warn("The mask image of the drag cursor is null"); //$NON-NLS-1$
+ cursors[code] = new Cursor(display, sourceImage, imageSize, imageSize);
+ } else {
+ cursors[code] = new Cursor(display, sourceImage, maskImage, imageSize, imageSize);
+ }
+ }
+ return cursors[code];
+ }
+
+ /**
+ * Convert the swt position into a internal position
+ *
+ * @param swtCode
+ * the swt position
+ * @return the internal position corresponding to the given swt position
+ */
+ public static int positionToDragCursor(int swtPositionConstant) {
+ switch (swtPositionConstant) {
+ case SWT.LEFT:
+ return LEFT;
+ case SWT.RIGHT:
+ return RIGHT;
+ case SWT.TOP:
+ return TOP;
+ case SWT.BOTTOM:
+ return BOTTOM;
+ case SWT.CENTER:
+ return CENTER;
+ default:
+ return INVALID;
+ }
+ }
+
+ /**
+ * Get shared images
+ *
+ * @return shared images
+ */
+ private static ISharedImages getSharedImages() {
+ if (PlatformUI.getWorkbench() != null) {
+ return PlatformUI.getWorkbench().getSharedImages();
+ }
+ return null;
+ }
+
+ /**
+ * Get the image data corresponding to the symbolic name
+ *
+ * @param symbolicName
+ * the symbolic name of the image
+ * @param sharedImages
+ * shared images
+ * @return the image data corresponding to the symbolic name
+ */
+ private static ImageData getImageDate(String symbolicName, ISharedImages sharedImages) {
+ int zoom = 100; // this is 100, since this is the default value of zoom (used to avoid use of the deprecated method ImageDescriptor#getImageData())
+ if (sharedImages != null) {
+ ImageDescriptor descriptor = sharedImages.getImageDescriptor(symbolicName);
+ if (descriptor != null) {
+ return descriptor.getImageData(zoom);
+ }
+ }
+ return null;
+ }
+
+ }
}

Back to the top