Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2019-04-24 10:03:51 -0400
committerNicolas FAUVERGUE2019-04-24 11:03:05 -0400
commit0084ded37d775a6065de8f2a2c8504d71efdf2d6 (patch)
treef0151409ef89b09bbfab9517dab2782c69e518a8
parenta5a54e96a8005d091921a29f96b7b315726f6438 (diff)
downloadorg.eclipse.papyrus-0084ded37d775a6065de8f2a2c8504d71efdf2d6.tar.gz
org.eclipse.papyrus-0084ded37d775a6065de8f2a2c8504d71efdf2d6.tar.xz
org.eclipse.papyrus-0084ded37d775a6065de8f2a2c8504d71efdf2d6.zip
Bug 546686: [SashEditor] Remove internal dependencies
- Remove the Workbench import -> Replaced by activator log - Manage DragUtil as 2 classes: - DragManager: Manage the dragListener - PapyrusDragUtils: Calculate locations - Remove copied eclipse classes not needed - Remove the StatusUtils import -> Manage it by an utility class into oep.infra.tools Change-Id: Ib982410516500ea2edf3ed27f62a0c9dca3cdff1 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/AbstractPanelPart.java5
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/ActiveEditorServicesSwitcher.java10
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/ComponentPart.java6
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/EditorPart.java10
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/PTabFolder.java39
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/SashPanelPart.java18
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/SashWindowsContainer.java28
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/TabFolderPart.java20
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/DragManager.java343
-rw-r--r--[-rwxr-xr-x]plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/IDragOverListener.java (renamed from plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/IDragOverListener.java)4
-rw-r--r--[-rwxr-xr-x]plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/IDropTarget.java (renamed from plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/IDropTarget.java)4
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/PapyrusDragUtils.java55
-rwxr-xr-xplugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/AbstractDropTarget.java32
-rwxr-xr-xplugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/DragUtil.java417
-rwxr-xr-xplugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/IDropTarget2.java29
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/PresentationUtil.java8
-rwxr-xr-xplugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/SwtUtil.java10
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.tools/pom.xml2
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/StatusUtils.java125
21 files changed, 600 insertions, 569 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/META-INF/MANIFEST.MF b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/META-INF/MANIFEST.MF
index 3a1f53acab2..779ecd47a72 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/META-INF/MANIFEST.MF
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/META-INF/MANIFEST.MF
@@ -17,7 +17,7 @@ Require-Bundle: org.eclipse.ui;bundle-version="[3.107.0,4.0.0)";visibility:=reex
org.eclipse.e4.core.contexts;bundle-version="[1.5.0,2.0.0)";resolution:=optional,
org.eclipse.e4.ui.model.workbench;bundle-version="[1.2.0,3.0.0)";resolution:=optional,
org.eclipse.core.expressions;bundle-version="[3.5.0,4.0.0)",
- org.eclipse.papyrus.infra.tools;bundle-version="[3.0.0,4.0.0)"
+ org.eclipse.papyrus.infra.tools;bundle-version="[3.1.0,4.0.0)"
Bundle-Vendor: %providerName
Bundle-Version: 2.1.0.qualifier
Bundle-ManifestVersion: 2
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/AbstractPanelPart.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/AbstractPanelPart.java
index cc6d6010f9c..d97588e4ae1 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/AbstractPanelPart.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/AbstractPanelPart.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2009 CEA LIST & LIFL
+ * Copyright (c) 2009, 2019 CEA LIST & LIFL
*
*
* All rights reserved. This program and the accompanying materials
@@ -11,12 +11,13 @@
*
* Contributors:
* Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 546686
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.internal;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.IDropTarget;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDropTarget;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/ActiveEditorServicesSwitcher.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/ActiveEditorServicesSwitcher.java
index 6b4e3679047..26b2a5f5809 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/ActiveEditorServicesSwitcher.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/ActiveEditorServicesSwitcher.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2009 CEA LIST & LIFL
+ * Copyright (c) 2009, 2019 CEA LIST & LIFL
*
*
* All rights reserved. This program and the accompanying materials
@@ -11,6 +11,7 @@
*
* Contributors:
* Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 546686
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.internal;
@@ -28,7 +29,6 @@ import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IKeyBindingService;
import org.eclipse.ui.INestableKeyBindingService;
import org.eclipse.ui.IPartService;
-import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.services.INestable;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
import org.eclipse.ui.services.IServiceLocator;
@@ -125,7 +125,7 @@ public class ActiveEditorServicesSwitcher implements IActiveEditorChangedListene
activeEditor = newEditor;
// Set focus
- IPartService partService = (IPartService) getOuterEditorSite().getService(IPartService.class);
+ IPartService partService = getOuterEditorSite().getService(IPartService.class);
if (newEditor != null && partService.getActivePart() == getOuterEditorSite().getPart()) {
newEditor.setFocus();
}
@@ -203,7 +203,7 @@ public class ActiveEditorServicesSwitcher implements IActiveEditorChangedListene
nestableService.activateKeyBindingService(editor.getEditorSite());
} else {
- WorkbenchPlugin.log("MultiPageEditorPart.activateSite() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
+ Activator.log.error("MultiPageEditorPart.activateSite() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " + service.getClass().getName() + " instead.", null); //$NON-NLS-1$ //$NON-NLS-2$
}
// Activate the services for the new service locator.
final IServiceLocator serviceLocator = editor.getEditorSite();
@@ -236,7 +236,7 @@ public class ActiveEditorServicesSwitcher implements IActiveEditorChangedListene
final INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
nestableService.activateKeyBindingService(null);
} else {
- WorkbenchPlugin.log("MultiPageEditorPart.deactivateSite() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
+ Activator.log.error("MultiPageEditorPart.deactivateSite() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " + service.getClass().getName() + " instead.", null); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/ComponentPart.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/ComponentPart.java
index 7f808dbeaf9..ca3b4ad0710 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/ComponentPart.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/ComponentPart.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2009, 2016 CEA LIST & LIFL, Christian W. Damus, and others
+ * Copyright (c) 2009, 2016, 2019 CEA LIST & LIFL, Christian W. Damus, and others
*
*
* All rights reserved. This program and the accompanying materials
@@ -12,6 +12,7 @@
* Contributors:
* Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
* Christian W. Damus - bugs 469188, 494543
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 546686
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.internal;
@@ -23,7 +24,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.papyrus.infra.core.sasheditor.Activator;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IComponentModel;
import org.eclipse.papyrus.infra.core.sasheditor.editor.IComponentPage;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.IDropTarget;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDropTarget;
import org.eclipse.papyrus.infra.tools.util.PlatformHelper;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
@@ -188,7 +189,6 @@ public class ComponentPart extends PagePart implements IComponentPage {
/**
* This is a container method. Not necessary in Leaf Tile.
- * TODO: change the interface.
*
* @param draggedObject
* @param sourcePart
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/EditorPart.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/EditorPart.java
index 1ba765e1c6f..edec6975652 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/EditorPart.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/EditorPart.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2009, 2016 CEA LIST, LIFL, Christian W. Damus, and others.
+ * Copyright (c) 2009, 2016, 2019 CEA LIST, LIFL, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -11,6 +11,7 @@
* Contributors:
* Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
* Christian W. Damus - bugs 469188, 474467, 494543
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 546686
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.internal;
@@ -28,10 +29,11 @@ import org.eclipse.papyrus.infra.core.sasheditor.Activator;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.AbstractPageModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IEditorModel;
import org.eclipse.papyrus.infra.core.sasheditor.editor.IEditorPage;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.IDropTarget;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDropTarget;
import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.IMultiPageEditorSite;
import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.MultiPageEditorSite;
import org.eclipse.papyrus.infra.tools.util.PlatformHelper;
+import org.eclipse.papyrus.infra.tools.util.StatusUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
@@ -50,7 +52,6 @@ import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.internal.ErrorEditorPart;
-import org.eclipse.ui.internal.misc.StatusUtil;
import org.eclipse.ui.part.EditorActionBarContributor;
import org.eclipse.ui.part.IWorkbenchPartOrientation;
@@ -210,7 +211,7 @@ public class EditorPart extends PagePart implements IEditorPage {
private void createErrorEditorPart(Composite parent, Exception e) {
try {
- PartInitException partInitException = new PartInitException(StatusUtil.getLocalizedMessage(e), StatusUtil.getCause(e));
+ PartInitException partInitException = new PartInitException(StatusUtils.getLocalizedMessage(e), StatusUtils.getCause(e));
editorPart = new ErrorEditorPart(partInitException.getStatus());
// Initialize it and create its controls.
editorControl = createEditorPartControl(parent, editorPart);
@@ -541,7 +542,6 @@ public class EditorPart extends PagePart implements IEditorPage {
/**
* This is a container method. Not necessary in Leaf Tile.
- * TODO: change the interface.
*
* @param draggedObject
* @param position
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/PTabFolder.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/PTabFolder.java
index 07267653325..92f7e5e3152 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/PTabFolder.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/PTabFolder.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2008, 2015 CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2008, 2015, 2019 CEA LIST, Christian W. Damus, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -12,6 +12,7 @@
* Contributors:
* Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
* Christian W. Damus - bug 469188
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 546686
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.internal;
@@ -20,7 +21,8 @@ import java.util.HashSet;
import java.util.Set;
import org.eclipse.jface.util.Geometry;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.DragUtil;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.DragManager;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.PapyrusDragUtils;
import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.PresentationUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
@@ -244,9 +246,9 @@ public class PTabFolder {
boolean allowSnapping = true;
Rectangle sourceBounds = Geometry.toDisplay(tabFolder.getParent(), tabFolder.getBounds());
if (tab == null) { // drag folder
- DragUtil.performDrag(tabFolder, sourceBounds, displayPos, allowSnapping);
+ DragManager.getInstance().performDrag(tabFolder, sourceBounds, displayPos, allowSnapping);
} else { // drag item
- DragUtil.performDrag(tab, sourceBounds, displayPos, allowSnapping);
+ DragManager.getInstance().performDrag(tab, sourceBounds, displayPos, allowSnapping);
}
}
@@ -339,33 +341,6 @@ public class PTabFolder {
listenersManager.fireMouseDown(itemIndex, e);
}
-
- /**
- * Returns true iff the given point is on the border of the folder. By default, double-clicking,
- * context menus, and drag/drop are disabled on the folder's border.
- *
- * @param toTest
- * a point (display coordinates)
- * @return true iff the point is on the presentation border
- * @since 3.1
- */
- private boolean isOnBorder(Point toTest) {
- Control content = getControl();
- if (content != null) {
- Rectangle displayBounds = DragUtil.getDisplayBounds(content);
-
- if (tabFolder.getTabPosition() == SWT.TOP) {
- return toTest.y >= displayBounds.y;
- }
-
- if (toTest.y >= displayBounds.y && toTest.y < displayBounds.y + displayBounds.height) {
- return true;
- }
- }
-
- return false;
- }
-
/**
* Get the item under the specified position.
*/
@@ -437,7 +412,7 @@ public class PTabFolder {
* Get bounds of the tabs area in display coordinate.
*/
public Rectangle getTabArea() {
- Rectangle bounds = DragUtil.getDisplayBounds(tabFolder);
+ Rectangle bounds = PapyrusDragUtils.getDisplayBounds(tabFolder);
//
if (tabFolder.getTabPosition() == SWT.TOP) {
bounds.height = tabFolder.getTabHeight();
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/SashPanelPart.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/SashPanelPart.java
index 51c1fa9f751..97ee808cd92 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/SashPanelPart.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/SashPanelPart.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
+ * Copyright (c) 2008, 2019 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
@@ -11,6 +11,7 @@
*
* Contributors:
* Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 546686
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.internal;
@@ -19,8 +20,8 @@ package org.eclipse.papyrus.infra.core.sasheditor.internal;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IAbstractPanelModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashPanelModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.DragUtil;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.IDropTarget;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDropTarget;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.PapyrusDragUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
@@ -38,7 +39,6 @@ import org.eclipse.swt.widgets.Composite;
* @param T
* Type of the external model representing the sash.
*/
-@SuppressWarnings({ "restriction" })
public class SashPanelPart extends AbstractPanelPart implements IPanelParent {
/** Interface to the model */
@@ -253,14 +253,14 @@ public class SashPanelPart extends AbstractPanelPart implements IPanelParent {
@Override
public AbstractPart findPart(Point toFind) throws NotFoundException {
- Rectangle bounds = DragUtil.getDisplayBounds(container); // container.getBounds();
+ Rectangle bounds = PapyrusDragUtils.getDisplayBounds(container); // container.getBounds();
// Try the left/up pane
- bounds = DragUtil.getDisplayBounds(container.getLeftParent());
+ bounds = PapyrusDragUtils.getDisplayBounds(container.getLeftParent());
if (bounds.contains(toFind)) {
return currentChildParts[0].findPart(toFind);
}
- bounds = DragUtil.getDisplayBounds(container.getRightParent());
+ bounds = PapyrusDragUtils.getDisplayBounds(container.getRightParent());
if (bounds.contains(toFind)) {
// Return right part
return currentChildParts[1].findPart(toFind);
@@ -285,7 +285,7 @@ public class SashPanelPart extends AbstractPanelPart implements IPanelParent {
return this;
}
- Rectangle bounds = DragUtil.getDisplayBounds(container); // container.getBounds();
+ Rectangle bounds = PapyrusDragUtils.getDisplayBounds(container); // container.getBounds();
if (isVertical()) {
if (toFind.y < bounds.y + (bounds.height / 2)) {
@@ -333,6 +333,8 @@ public class SashPanelPart extends AbstractPanelPart implements IPanelParent {
/**
* SashPanelPart can't be a DropTarget. Do nothing.
+ *
+ * @see org.eclipse.papyrus.infra.core.sasheditor.internal.AbstractPanelPart#getDropTarget(java.lang.Object, org.eclipse.papyrus.infra.core.sasheditor.internal.TabFolderPart, org.eclipse.swt.graphics.Point)
*/
@Override
public IDropTarget getDropTarget(Object draggedObject, TabFolderPart sourcePart, Point position) {
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 84f49e1b370..02d8ae22505 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
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2009, 2016 LIFL, CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2009, 2016, 2019 LIFL, CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -12,6 +12,7 @@
* Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 437217
* Christian W. Damus - bug 488791
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 546686
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.internal;
@@ -37,9 +38,10 @@ import org.eclipse.papyrus.infra.core.sasheditor.editor.IPageLifeCycleEventsList
import org.eclipse.papyrus.infra.core.sasheditor.editor.IPageVisitor;
import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
import org.eclipse.papyrus.infra.core.sasheditor.editor.ITabMouseEventsListener;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.DragUtil;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.IDragOverListener;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.IDropTarget;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.DragManager;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDragOverListener;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDropTarget;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.PapyrusDragUtils;
import org.eclipse.papyrus.infra.core.sasheditor.utils.IObservableList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
@@ -82,7 +84,7 @@ public class SashWindowsContainer implements ISashWindowsContainer {
/**
* Tracker maintaining the history of the active pages.
- *
+ *
* @since 2.0.0
*/
private ActivePageHistoryTracker activePageHistoryTracker;
@@ -977,7 +979,7 @@ public class SashWindowsContainer implements ISashWindowsContainer {
*
*/
private void initDrag(Composite container) {
- DragUtil.addDragTarget(container, dragOverListener);
+ DragManager.getInstance().addDragTarget(container, dragOverListener);
}
@@ -985,7 +987,7 @@ public class SashWindowsContainer implements ISashWindowsContainer {
/**
*
- * @see org.eclipse.ui.internal.dnd.IDragOverListener#drag(org.eclipse.swt.widgets.Control, java.lang.Object, org.eclipse.swt.graphics.Point, org.eclipse.swt.graphics.Rectangle)
+ * @see org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDragOverListener#drag(org.eclipse.swt.widgets.Control, java.lang.Object, org.eclipse.swt.graphics.Point, org.eclipse.swt.graphics.Rectangle)
*/
@Override
public IDropTarget drag(Control currentControl, Object draggedObject, Point position, Rectangle dragRectangle) {
@@ -997,7 +999,7 @@ public class SashWindowsContainer implements ISashWindowsContainer {
final int srcTabIndex = PTabFolder.getDraggedObjectTabIndex(draggedObject);
// System.out.println("drag to position=" + position);
- Rectangle containerDisplayBounds = DragUtil.getDisplayBounds(container);
+ Rectangle containerDisplayBounds = PapyrusDragUtils.getDisplayBounds(container);
AbstractPanelPart targetPart = null;
// Check if the cursor is inside the container
@@ -1011,7 +1013,7 @@ public class SashWindowsContainer implements ISashWindowsContainer {
if (targetPart != null) {
final Control targetControl = targetPart.getControl();
- final Rectangle targetBounds = DragUtil.getDisplayBounds(targetControl);
+ final Rectangle targetBounds = PapyrusDragUtils.getDisplayBounds(targetControl);
int side = Geometry.getClosestSide(targetBounds, position);
int distance = Geometry.getDistanceFromEdge(targetBounds, position, side);
@@ -1127,7 +1129,7 @@ public class SashWindowsContainer implements ISashWindowsContainer {
/**
* A folder is dropped.
*
- * @see org.eclipse.ui.internal.dnd.IDropTarget#drop()
+ * @see org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDropTarget#drop()
*/
@Override
public void drop() {
@@ -1142,7 +1144,7 @@ public class SashWindowsContainer implements ISashWindowsContainer {
/**
* Return the cursor used during drag.
*
- * @see org.eclipse.ui.internal.dnd.IDropTarget#getCursor()
+ * @see org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDropTarget#getCursor()
*/
@Override
public Cursor getCursor() {
@@ -1157,10 +1159,10 @@ public class SashWindowsContainer implements ISashWindowsContainer {
Rectangle targetDisplayBounds;
if (targetPart != null) {
- targetDisplayBounds = DragUtil.getDisplayBounds(targetPart.getControl());
+ targetDisplayBounds = PapyrusDragUtils.getDisplayBounds(targetPart.getControl());
} else {
// targetBounds = DragUtil.getDisplayBounds(getParent());
- targetDisplayBounds = DragUtil.getDisplayBounds(container);
+ targetDisplayBounds = PapyrusDragUtils.getDisplayBounds(container);
}
if (side == SWT.CENTER || side == SWT.NONE) {
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 95f01aa50cb..171d7d7d14a 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
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2008, 2015 CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2008, 2015, 2019 CEA LIST, Christian W. Damus, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -13,6 +13,7 @@
* Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 392301
* Christian W. Damus - bug 469188
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 546686
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.sasheditor.internal;
@@ -27,10 +28,11 @@ import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ITabFolderModel;
import org.eclipse.papyrus.infra.core.sasheditor.editor.ICloseablePart;
import org.eclipse.papyrus.infra.core.sasheditor.editor.IFolder;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.DragManager;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDragOverListener;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDropTarget;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.PapyrusDragUtils;
import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.AbstractTabFolderPart;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.DragUtil;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.IDragOverListener;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.IDropTarget;
import org.eclipse.papyrus.infra.tools.util.PlatformHelper;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
@@ -99,7 +101,7 @@ public class TabFolderPart extends AbstractTabFolderPart implements IFolder {
/**
*
- * @see org.eclipse.ui.internal.dnd.IDragOverListener#drag(org.eclipse.swt.widgets.Control, java.lang.Object, org.eclipse.swt.graphics.Point, org.eclipse.swt.graphics.Rectangle)
+ * @see org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDragOverListener#drag(org.eclipse.swt.widgets.Control, java.lang.Object, org.eclipse.swt.graphics.Point, org.eclipse.swt.graphics.Rectangle)
*/
@Override
public IDropTarget drag(Control currentControl, Object draggedObject, Point position, Rectangle dragRectangle) {
@@ -441,7 +443,7 @@ public class TabFolderPart extends AbstractTabFolderPart implements IFolder {
*
*/
private void initDrag(Composite container) {
- DragUtil.addDragTarget(container, dragOverListener);
+ DragManager.getInstance().addDragTarget(container, dragOverListener);
}
@@ -658,7 +660,7 @@ public class TabFolderPart extends AbstractTabFolderPart implements IFolder {
} else {
// If the closest side is the side with the tabs, consider this a stack operation.
// Otherwise, let the drop fall through to whatever the default behavior is
- Rectangle displayBounds = DragUtil.getDisplayBounds(pTabFolder.getControl());
+ Rectangle displayBounds = PapyrusDragUtils.getDisplayBounds(pTabFolder.getControl());
int closestSide = Geometry.getClosestSide(displayBounds, position);
if (closestSide == pTabFolder.getTabFolder().getTabPosition()) {
return createDropTarget(sourcePart, sourceIndex, displayBounds, -1);
@@ -739,7 +741,7 @@ public class TabFolderPart extends AbstractTabFolderPart implements IFolder {
/**
*
- * @see org.eclipse.ui.internal.dnd.IDropTarget#drop()
+ * @see org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.IDropTarget#drop()
*/
@Override
public void drop() {
@@ -756,7 +758,7 @@ public class TabFolderPart extends AbstractTabFolderPart implements IFolder {
/**
* Return the cursor used during drag.
*
- * @see org.eclipse.ui.internal.dnd.IDropTarget#getCursor()
+ * @see org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy.IDropTarget#getCursor()
*/
@Override
public Cursor getCursor() {
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
new file mode 100644
index 00000000000..501354e3d81
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/DragManager.java
@@ -0,0 +1,343 @@
+/*****************************************************************************
+ * Copyright (c) 2019 CEA LIST and others.
+ *
+ * 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
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.internal.dnd;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+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;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tracker;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.DragCursors;
+
+/**
+ * This allows to manage the drag actions with drag targets.
+ */
+public class DragManager {
+
+ /**
+ * The drag target ID.
+ */
+ private static final String DROP_TARGET_ID = "org.eclipse.ui.internal.dnd.dropTarget"; //$NON-NLS-1$
+
+ /**
+ * The singleton instance.
+ */
+ private static DragManager instance;
+
+ /**
+ * Private constructor to avoid instanciation.
+ */
+ private DragManager() {
+ // do nothing
+ }
+
+ /**
+ * Get the singleton instance.
+ *
+ * @return The singleton instance.
+ */
+ public static DragManager getInstance() {
+ if (null == instance) {
+ instance = new DragManager();
+ }
+ return instance;
+ }
+
+ /**
+ * List of IDragOverListener
+ */
+ private List<IDragOverListener> defaultTargets = new ArrayList<>();
+
+ /**
+ * Sets the drop target for the given control. It is possible to add one or more targets for a "null" control. This becomes a default target that is used if no other targets are found (for example, when dragging objects off the application window).
+ *
+ * @param control
+ * The control that should be treated as a drag target, or null to indicate the default target.
+ * @param target
+ * The drag target to handle the given control.
+ */
+ public void addDragTarget(final Control control, final IDragOverListener target) {
+ if (control == null) {
+ defaultTargets.add(target);
+ } else {
+ List<IDragOverListener> targetList = getTargetList(control);
+
+ if (targetList == null) {
+ targetList = new ArrayList<>(1);
+ }
+ targetList.add(target);
+ control.setData(DROP_TARGET_ID, targetList);
+ }
+ }
+
+ /**
+ * Return the list of 'IDragOverListener' elements associated with the given control. If there's a 'global' listener then always return it.
+ *
+ * @param control
+ * The control that should be treated as a drag target, or null to indicate the default target.
+ * @return The list of 'IDragOverListener' elements associated with the given control.
+ */
+ @SuppressWarnings("unchecked")
+ private List<IDragOverListener> getTargetList(final Control control) {
+ return (List<IDragOverListener>) control.getData(DROP_TARGET_ID);
+ }
+
+ /**
+ * Removes a drop target from the given control.
+ *
+ * @param control
+ * The control that should be treated as a drag target, or null to indicate the default target.
+ * @param target
+ * The drag target to handle the given control.
+ */
+ public void removeDragTarget(final Control control, final IDragOverListener target) {
+ if (control == null) {
+ defaultTargets.remove(target);
+ } else {
+ final List<IDragOverListener> targetList = getTargetList(control);
+ if (targetList != null) {
+ targetList.remove(target);
+ if (targetList.isEmpty()) {
+ control.setData(DROP_TARGET_ID, null);
+ }
+ }
+ }
+ }
+
+ /**
+ * This allows to perform the drag of the needed item.
+ *
+ * @param draggedItem
+ * The object being dragged.
+ * @param sourceBounds
+ * initial bounding rectangle for the dragged item.
+ * @param initialLocation
+ * initial position of the mouse cursor.
+ * @param allowSnapping
+ * <code>true</code> if the rectangle should snap to the drop location. This must be <code>false</code> if the user might be doing drag-and-drop using the keyboard.
+ * @return <code>true</code> if the drag was correctly done, <code>false</code> otherwise.
+ */
+ public boolean performDrag(final Object draggedItem, final Rectangle sourceBounds, final Point initialLocation, final boolean allowSnapping) {
+
+ final IDropTarget target = dragToTarget(draggedItem, sourceBounds, initialLocation, allowSnapping);
+ if (target == null) {
+ return false;
+ }
+
+ target.drop();
+
+ return true;
+ }
+
+ /**
+ * Drags the given item, given an initial bounding rectangle in display coordinates.
+ * Due to a quirk in the Tracker class, changing the tracking rectangle when using the keyboard will also cause the mouse cursor to move. Since "snapping" causes the tracking rectangle to change based on the position of the mouse cursor, it is impossible
+ * to do drag-and-drop with the keyboard when snapping is enabled.
+ *
+ * @param draggedItem
+ * The object being dragged.
+ * @param sourceBounds
+ * initial bounding rectangle for the dragged item.
+ * @param initialLocation
+ * initial position of the mouse cursor.
+ * @param allowSnapping
+ * <code>true</code> if the rectangle should snap to the drop location. This must be <code>false</code> if the user might be doing drag-and-drop using the keyboard.
+ * @return <code>true</code> if the drag was correctly done, <code>false</code> otherwise.
+ */
+ private IDropTarget dragToTarget(final Object draggedItem, final Rectangle sourceBounds, final Point initialLocation, final boolean allowSnapping) {
+ final Display display = Display.getCurrent();
+
+ // Create a tracker. This is just an XOR rect on the screen.
+ // As it moves we notify the drag listeners.
+ final Tracker tracker = new Tracker(display, SWT.NULL);
+ tracker.setStippled(true);
+
+ tracker.addListener(SWT.Move, event -> display.syncExec(() -> {
+ // Get the curslor location as a point
+ Point location = new Point(event.x, event.y);
+
+ // Select a drop target; use the global one by default
+ IDropTarget target = null;
+
+ Control targetControl = display.getCursorControl();
+
+ // Get the drop target for this location
+ target = getDropTarget(targetControl, draggedItem, location, tracker.getRectangles()[0]);
+
+ // Set up the tracker feedback based on the target
+ Rectangle snapTarget = null;
+ if (target != null) {
+ snapTarget = target.getSnapRectangle();
+ tracker.setCursor(target.getCursor());
+ } else {
+ tracker.setCursor(DragCursors.getCursor(DragCursors.INVALID));
+ }
+
+ // If snapping then reset the tracker's rectangle based on the current drop target
+ if (allowSnapping) {
+ if (snapTarget == null) {
+ snapTarget = new Rectangle(sourceBounds.x + location.x - initialLocation.x, sourceBounds.y + location.y - initialLocation.y, sourceBounds.width, sourceBounds.height);
+ }
+
+ // Try to prevent flicker: don't change the rectangles if they're already in
+ // the right location
+ Rectangle[] currentRectangles = tracker.getRectangles();
+
+ if (!(currentRectangles.length == 1 && currentRectangles[0].equals(snapTarget))) {
+ tracker.setRectangles(new Rectangle[] { Geometry.copy(snapTarget) });
+ }
+ }
+ }));
+
+ // Setup...when the drag starts we might already be over a valid target, check this...
+ // If there is a 'global' target then skip the check
+ IDropTarget target = null;
+ Control startControl = display.getCursorControl();
+
+ if (startControl != null && allowSnapping) {
+ target = getDropTarget(startControl, draggedItem, initialLocation, sourceBounds);
+ }
+
+ // Set up an initial tracker rectangle
+ Rectangle startRect = sourceBounds;
+ if (target != null) {
+ Rectangle rect = target.getSnapRectangle();
+
+ if (rect != null) {
+ startRect = rect;
+ }
+
+ tracker.setCursor(target.getCursor());
+ }
+
+ if (startRect != null) {
+ tracker.setRectangles(new Rectangle[] { Geometry.copy(startRect) });
+ }
+
+ // Tracking Loop...tracking is preformed on the 'SWT.Move' listener registered
+ // against the tracker.
+
+ // HACK:
+ // Some control needs to capture the mouse during the drag or other
+ // controls will interfere with the cursor
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ if (shell != null) {
+ shell.setCapture(true);
+ }
+
+ // Run tracker until mouse up occurs or escape key pressed.
+ boolean trackingOk = tracker.open();
+
+ // HACK:
+ // Release the mouse now
+ if (shell != null) {
+ shell.setCapture(false);
+ }
+
+ // Done tracking...
+
+ // Get the current drop target
+ IDropTarget dropTarget = null;
+ Point finalLocation = display.getCursorLocation();
+ Control targetControl = display.getCursorControl();
+ dropTarget = getDropTarget(targetControl, draggedItem, finalLocation, tracker.getRectangles()[0]);
+
+ // Cleanup...
+ tracker.dispose();
+
+ // if we're going to perform a 'drop' then delay the issuing of the 'finished'
+ // callback until after it's done...
+ if (trackingOk) {
+ return dropTarget;
+ }
+
+ return null;
+ }
+
+ /**
+ * Given a list of IDragOverListeners and a description of what is being dragged, it returns
+ * a IDropTarget for the current drop.
+ *
+ * @param toSearch
+ * The listener to search.
+ * @param mostSpecificControl
+ * The control.
+ * @param draggedObject
+ * The dragged object.
+ * @param position
+ * The initial position of the object to drag.
+ * @param dragRectangle
+ * The dimension of the drag action.
+ * @return The drop target corresponding to the position of the drop.
+ */
+ private IDropTarget getDropTarget(final List<IDragOverListener> toSearch, final Control mostSpecificControl, final Object draggedObject, final Point position, final Rectangle dragRectangle) {
+ if (toSearch == null) {
+ return null;
+ }
+
+ final Iterator<IDragOverListener> iter = toSearch.iterator();
+ while (iter.hasNext()) {
+ final IDragOverListener next = iter.next();
+ final IDropTarget dropTarget = next.drag(mostSpecificControl, draggedObject, position, dragRectangle);
+
+ if (dropTarget != null) {
+ return dropTarget;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the drag target for the given control or null if none.
+ *
+ * @param toSearch
+ * The listener to search.
+ * @param draggedObject
+ * The dragged object.
+ * @param position
+ * The initial position of the object to drag.
+ * @param dragRectangle
+ * The dimension of the drag action.
+ * @return The drop target corresponding to the position of the drop.
+ */
+ public IDropTarget getDropTarget(final Control toSearch, final Object draggedObject, final Point position, final Rectangle dragRectangle) {
+ // Search for a listener by walking the control's parent hierarchy
+ for (Control current = toSearch; current != null; current = current.getParent()) {
+ final IDropTarget dropTarget = getDropTarget(getTargetList(current), toSearch, draggedObject, position, dragRectangle);
+
+ if (dropTarget != null) {
+ return dropTarget;
+ }
+
+ // Don't look to parent shells for drop targets
+ if (current instanceof Shell) {
+ break;
+ }
+ }
+
+ // No controls could handle this event -- check for default targets
+ return getDropTarget(defaultTargets, toSearch, draggedObject, position, dragRectangle);
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/IDragOverListener.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/IDragOverListener.java
index 8d1a162182c..4abc4b01e29 100755..100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/IDragOverListener.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/IDragOverListener.java
@@ -11,7 +11,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy;
+package org.eclipse.papyrus.infra.core.sasheditor.internal.dnd;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
@@ -36,6 +36,6 @@ public interface IDragOverListener {
* current drag rectangle (may be an empty rectangle if none)
* @return a valid drop target or null if none
*/
- IDropTarget drag(Control currentControl, Object draggedObject,
+ public IDropTarget drag(Control currentControl, Object draggedObject,
Point position, Rectangle dragRectangle);
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/IDropTarget.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/IDropTarget.java
index 8c38ea939bd..95c853b8bb2 100755..100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/IDropTarget.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/IDropTarget.java
@@ -11,7 +11,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.papyrus.infra.core.sasheditor.internal.eclipsecopy;
+package org.eclipse.papyrus.infra.core.sasheditor.internal.dnd;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Rectangle;
@@ -22,7 +22,7 @@ import org.eclipse.swt.graphics.Rectangle;
* it is the job of the IDragOverListener to supply the drop target with information about
* the object currently being dragged.
*
- * @see org.eclipse.ui.internal.dnd.IDragOverListener
+ * @see org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.IDragOverListener
*/
public interface IDropTarget {
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/PapyrusDragUtils.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/PapyrusDragUtils.java
new file mode 100644
index 00000000000..83e5ef7640f
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/dnd/PapyrusDragUtils.java
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * Copyright (c) 2019 CEA LIST and others.
+ *
+ * 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
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.sasheditor.internal.dnd;
+
+import org.eclipse.jface.util.Geometry;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * The utility methods about the drag of sash editors.
+ */
+public class PapyrusDragUtils {
+
+ /**
+ * Shorthand method. returns the bounding rectangle for the given control, in display coordinates. Note that all 'Shell' controls are expected to be 'top level' so DO NOT do the origin offset for them.
+ *
+ * @param boundsControl
+ * The given {@link Control}.
+ * @return The bounding rectangle for the given control.
+ */
+ public static Rectangle getDisplayBounds(final Control boundsControl) {
+ final Control parent = boundsControl.getParent();
+ if (null == parent || boundsControl instanceof Shell) {
+ return boundsControl.getBounds();
+ }
+
+ return Geometry.toDisplay(parent, boundsControl.getBounds());
+ }
+
+ /**
+ * Returns the location of the given event, in display coordinates.
+ *
+ * @return The location of the given event, in display coordinates.
+ */
+ public static Point getEventLoc(Event event) {
+ final Control ctrl = (Control) event.widget;
+ return ctrl.toDisplay(new Point(event.x, event.y));
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/AbstractDropTarget.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/AbstractDropTarget.java
deleted file mode 100755
index 5b5157bb7f1..00000000000
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/AbstractDropTarget.java
+++ /dev/null
@@ -1,32 +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.Cursor;
-import org.eclipse.swt.graphics.Rectangle;
-
-/**
- */
-public abstract class AbstractDropTarget implements IDropTarget {
- @Override
- public abstract void drop();
-
- @Override
- public abstract Cursor getCursor();
-
- @Override
- public Rectangle getSnapRectangle() {
- return null;
- }
-}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/DragUtil.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/DragUtil.java
deleted file mode 100755
index 68c01d478f4..00000000000
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/DragUtil.java
+++ /dev/null
@@ -1,417 +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 java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-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;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Tracker;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.internal.DragCursors;
-
-/**
- * Provides the methods for attaching drag-and-drop listeners to SWT controls.
- */
-public class DragUtil {
- private static final String DROP_TARGET_ID = "org.eclipse.ui.internal.dnd.dropTarget"; //$NON-NLS-1$
-
- /**
- * The location where all drags will end. If this is non-null, then
- * all user input is ignored in drag/drop. If null, we use user input
- * to determine where objects should be dropped.
- */
- private static TestDropLocation forcedDropTarget = null;
-
- /**
- * List of IDragOverListener
- */
- private static List defaultTargets = new ArrayList();
-
- /**
- * Sets the drop target for the given control. It is possible to add one or more
- * targets for a "null" control. This becomes a default target that is used if no
- * other targets are found (for example, when dragging objects off the application
- * window).
- *
- * @param control
- * the control that should be treated as a drag target, or null
- * to indicate the default target
- * @param target
- * the drag target to handle the given control
- */
- public static void addDragTarget(Control control, IDragOverListener target) {
- if (control == null) {
- defaultTargets.add(target);
- } else {
- List targetList = getTargetList(control);
-
- if (targetList == null) {
- targetList = new ArrayList(1);
- }
- targetList.add(target);
- control.setData(DROP_TARGET_ID, targetList);
- }
- }
-
- /**
- * Return the list of 'IDragOverListener' elements associated with
- * the given control. If there's a 'global' listener then always
- * return it.
- *
- * @param control
- * @return
- */
- private static List getTargetList(Control control) {
- List result = (List) control.getData(DROP_TARGET_ID);
- return result;
- }
-
- /**
- * Removes a drop target from the given control.
- *
- * @param control
- * @param target
- */
- public static void removeDragTarget(Control control,
- IDragOverListener target) {
- if (control == null) {
- defaultTargets.remove(target);
- } else {
- List targetList = getTargetList(control);
- if (targetList != null) {
- targetList.remove(target);
- if (targetList.isEmpty()) {
- control.setData(DROP_TARGET_ID, null);
- }
- }
- }
- }
-
- /**
- * Shorthand method. Returns the bounding rectangle for the given control, in
- * display coordinates. Note that all 'Shell' controls are expected to be 'top level'
- * so DO NOT do the origin offset for them.
- *
- * @param draggedItem
- * @param boundsControl
- * @return
- */
- public static Rectangle getDisplayBounds(Control boundsControl) {
- Control parent = boundsControl.getParent();
- if (parent == null || boundsControl instanceof Shell) {
- return boundsControl.getBounds();
- }
-
- return Geometry.toDisplay(parent, boundsControl.getBounds());
- }
-
- public static boolean performDrag(final Object draggedItem,
- Rectangle sourceBounds, Point initialLocation, boolean allowSnapping) {
-
- IDropTarget target = dragToTarget(draggedItem, sourceBounds,
- initialLocation, allowSnapping);
-
- if (target == null) {
- return false;
- }
-
- target.drop();
-
- // If the target can handle a 'finished' notification then send one
- if (target instanceof IDropTarget2) {
- ((IDropTarget2) target).dragFinished(true);
- }
-
- return true;
- }
-
- /**
- * Drags the given item to the given location (in display coordinates). This
- * method is intended for use by test suites.
- *
- * @param draggedItem
- * object being dragged
- * @param finalLocation
- * location being dragged to
- * @return true iff the drop was accepted
- */
- public static boolean dragTo(Display display, Object draggedItem,
- Point finalLocation, Rectangle dragRectangle) {
- Control currentControl = SwtUtil.findControl(display, finalLocation);
-
- IDropTarget target = getDropTarget(currentControl, draggedItem,
- finalLocation, dragRectangle);
-
- if (target == null) {
- return false;
- }
-
- target.drop();
-
- return true;
- }
-
- /**
- * Forces all drags to end at the given position (display coordinates). Intended
- * for use by test suites. If this method is called, then all subsequent calls
- * to performDrag will terminate immediately and behave as though the object were
- * dragged to the given location. Calling this method with null cancels this
- * behavior and causes performDrag to behave normally.
- *
- * @param forcedLocation
- * location where objects will be dropped (or null to
- * cause drag/drop to behave normally).
- */
- public static void forceDropLocation(TestDropLocation forcedLocation) {
- forcedDropTarget = forcedLocation;
- }
-
- /**
- * Drags the given item, given an initial bounding rectangle in display coordinates.
- * Due to a quirk in the Tracker class, changing the tracking rectangle when using the
- * keyboard will also cause the mouse cursor to move. Since "snapping" causes the tracking
- * rectangle to change based on the position of the mouse cursor, it is impossible to do
- * drag-and-drop with the keyboard when snapping is enabled.
- *
- * @param draggedItem
- * object being dragged
- * @param sourceBounds
- * initial bounding rectangle for the dragged item
- * @param initialLocation
- * initial position of the mouse cursor
- * @param allowSnapping
- * true iff the rectangle should snap to the drop location. This must
- * be false if the user might be doing drag-and-drop using the keyboard.
- *
- * @return
- */
- static IDropTarget dragToTarget(final Object draggedItem,
- final Rectangle sourceBounds, final Point initialLocation,
- final boolean allowSnapping) {
- final Display display = Display.getCurrent();
-
- // Testing...immediately 'drop' onto the test target
- if (forcedDropTarget != null) {
- Point location = forcedDropTarget.getLocation();
-
- Control currentControl = SwtUtil.findControl(forcedDropTarget.getShells(), location);
- return getDropTarget(currentControl, draggedItem, location,
- sourceBounds);
- }
-
- // Create a tracker. This is just an XOR rect on the screen.
- // As it moves we notify the drag listeners.
- final Tracker tracker = new Tracker(display, SWT.NULL);
- tracker.setStippled(true);
-
- tracker.addListener(SWT.Move, event -> display.syncExec(() -> {
- // Get the curslor location as a point
- Point location = new Point(event.x, event.y);
-
- // Select a drop target; use the global one by default
- IDropTarget target = null;
-
- Control targetControl = display.getCursorControl();
-
- // Get the drop target for this location
- target = getDropTarget(targetControl,
- draggedItem, location,
- tracker.getRectangles()[0]);
-
- // Set up the tracker feedback based on the target
- Rectangle snapTarget = null;
- if (target != null) {
- snapTarget = target.getSnapRectangle();
-
- tracker.setCursor(target.getCursor());
- } else {
- tracker.setCursor(DragCursors
- .getCursor(DragCursors.INVALID));
- }
-
- // If snapping then reset the tracker's rectangle based on the current drop target
- if (allowSnapping) {
- if (snapTarget == null) {
- snapTarget = new Rectangle(sourceBounds.x
- + location.x - initialLocation.x,
- sourceBounds.y + location.y
- - initialLocation.y,
- sourceBounds.width, sourceBounds.height);
- }
-
- // Try to prevent flicker: don't change the rectangles if they're already in
- // the right location
- Rectangle[] currentRectangles = tracker.getRectangles();
-
- if (!(currentRectangles.length == 1 && currentRectangles[0]
- .equals(snapTarget))) {
- tracker.setRectangles(new Rectangle[] { Geometry.copy(snapTarget) });
- }
- }
- }));
-
- // Setup...when the drag starts we might already be over a valid target, check this...
- // If there is a 'global' target then skip the check
- IDropTarget target = null;
- Control startControl = display.getCursorControl();
-
- if (startControl != null && allowSnapping) {
- target = getDropTarget(startControl,
- draggedItem, initialLocation,
- sourceBounds);
- }
-
- // Set up an initial tracker rectangle
- Rectangle startRect = sourceBounds;
- if (target != null) {
- Rectangle rect = target.getSnapRectangle();
-
- if (rect != null) {
- startRect = rect;
- }
-
- tracker.setCursor(target.getCursor());
- }
-
- if (startRect != null) {
- tracker.setRectangles(new Rectangle[] { Geometry.copy(startRect) });
- }
-
- // Tracking Loop...tracking is preformed on the 'SWT.Move' listener registered
- // against the tracker.
-
- // HACK:
- // Some control needs to capture the mouse during the drag or other
- // controls will interfere with the cursor
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- if (shell != null) {
- shell.setCapture(true);
- }
-
- // Run tracker until mouse up occurs or escape key pressed.
- boolean trackingOk = tracker.open();
-
- // HACK:
- // Release the mouse now
- if (shell != null) {
- shell.setCapture(false);
- }
-
- // Done tracking...
-
- // Get the current drop target
- IDropTarget dropTarget = null;
- Point finalLocation = display.getCursorLocation();
- Control targetControl = display.getCursorControl();
- dropTarget = getDropTarget(targetControl, draggedItem,
- finalLocation, tracker.getRectangles()[0]);
-
- // Cleanup...
- tracker.dispose();
-
- // if we're going to perform a 'drop' then delay the issuing of the 'finished'
- // callback until after it's done...
- if (trackingOk) {
- return dropTarget;
- } else if (dropTarget != null && dropTarget instanceof IDropTarget2) {
- // If the target can handle a 'finished' notification then send one
- ((IDropTarget2) dropTarget).dragFinished(false);
- }
-
- return null;
- }
-
- /**
- * Given a list of IDragOverListeners and a description of what is being dragged, it returns
- * a IDropTarget for the current drop.
- *
- * @param toSearch
- * @param mostSpecificControl
- * @param draggedObject
- * @param position
- * @param dragRectangle
- * @return
- */
- private static IDropTarget getDropTarget(List toSearch,
- Control mostSpecificControl, Object draggedObject, Point position,
- Rectangle dragRectangle) {
- if (toSearch == null) {
- return null;
- }
-
- Iterator iter = toSearch.iterator();
- while (iter.hasNext()) {
- IDragOverListener next = (IDragOverListener) iter.next();
-
- IDropTarget dropTarget = next.drag(mostSpecificControl,
- draggedObject, position, dragRectangle);
-
- if (dropTarget != null) {
- return dropTarget;
- }
- }
-
- return null;
- }
-
- /**
- * Returns the drag target for the given control or null if none.
- *
- * @param toSearch
- * @param e
- * @return
- */
- public static IDropTarget getDropTarget(Control toSearch,
- Object draggedObject, Point position, Rectangle dragRectangle) {
- // Search for a listener by walking the control's parent hierarchy
- for (Control current = toSearch; current != null; current = current
- .getParent()) {
- IDropTarget dropTarget = getDropTarget(getTargetList(current),
- toSearch, draggedObject, position, dragRectangle);
-
- if (dropTarget != null) {
- return dropTarget;
- }
-
- // Don't look to parent shells for drop targets
- if (current instanceof Shell) {
- break;
- }
- }
-
- // No controls could handle this event -- check for default targets
- return getDropTarget(defaultTargets, toSearch, draggedObject, position,
- dragRectangle);
- }
-
- /**
- * Returns the location of the given event, in display coordinates
- *
- * @return
- */
- public static Point getEventLoc(Event event) {
- Control ctrl = (Control) event.widget;
- return ctrl.toDisplay(new Point(event.x, event.y));
- }
-
-}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/IDropTarget2.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/IDropTarget2.java
deleted file mode 100755
index 7af99910c8d..00000000000
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/IDropTarget2.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 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;
-
-/**
- * This interface allows a particular drop target to be informed that
- * the drag operation was cancelled. This allows the target to clean
- * up any extended drag feedback.
- *
- * @since 3.2
- *
- */
-public interface IDropTarget2 extends IDropTarget {
- /**
- * This is called whenever a drag operation is cancelled
- */
- void dragFinished(boolean dropPerformed);
-}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/PresentationUtil.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/PresentationUtil.java
index bcb7ec27c9a..d216f3b4b3f 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/PresentationUtil.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/internal/eclipsecopy/PresentationUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
+ * Copyright (c) 2004, 2006, 2019 IBM Corporation, CEA LIST and others.
* 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
@@ -9,10 +9,12 @@
*
* 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.jface.util.Geometry;
+import org.eclipse.papyrus.infra.core.sasheditor.internal.dnd.PapyrusDragUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
@@ -57,7 +59,7 @@ public class PresentationUtil {
* opening a tracker.
*/
private static boolean hasMovedEnough(Event event) {
- return Geometry.distanceSquared(DragUtil.getEventLoc(event), anchor) >= HYSTERESIS
+ return Geometry.distanceSquared(PapyrusDragUtils.getEventLoc(event), anchor) >= HYSTERESIS
* HYSTERESIS;
}
@@ -85,7 +87,7 @@ public class PresentationUtil {
dragSource = (Control) event.widget;
currentListener = (Listener) dragSource.getData(LISTENER_ID);
- anchor = DragUtil.getEventLoc(event);
+ anchor = PapyrusDragUtils.getEventLoc(event);
if (dragEvent != null && (dragEvent.widget != dragSource)) {
dragEvent = null;
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
index 86dc802bd67..f264aca4df0 100755
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2015 IBM Corporation and others.
+ * 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
@@ -10,9 +10,11 @@
*
* 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;
@@ -51,7 +53,7 @@ public class SwtUtil {
* @return a control that obscures the test control or null if none
*/
public static Control controlThatCovers(Control toTest) {
- return controlThatCovers(toTest, DragUtil.getDisplayBounds(toTest));
+ return controlThatCovers(toTest, PapyrusDragUtils.getDisplayBounds(toTest));
}
private static Control controlThatCovers(Control toTest, Rectangle testRegion) {
@@ -72,7 +74,7 @@ public class SwtUtil {
continue;
}
- Rectangle nextBounds = DragUtil.getDisplayBounds(control);
+ Rectangle nextBounds = PapyrusDragUtils.getDisplayBounds(control);
if (nextBounds.intersects(testRegion)) {
return control;
@@ -145,7 +147,7 @@ public class SwtUtil {
if (!next.isDisposed() && next.isVisible()) {
- Rectangle bounds = DragUtil.getDisplayBounds(next);
+ Rectangle bounds = PapyrusDragUtils.getDisplayBounds(next);
if (bounds.contains(locationToFind)) {
if (next instanceof Composite) {
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF b/plugins/infra/core/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
index 0669725e0da..8256a2425d2 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
@@ -13,7 +13,7 @@ Require-Bundle: org.eclipse.papyrus.infra.core.log;bundle-version="[1.2.0,2.0.0)
org.apache.commons.io;bundle-version="2.2.0"
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
-Bundle-Version: 3.0.0.qualifier
+Bundle-Version: 3.1.0.qualifier
Eclipse-BuddyPolicy: dependent
Bundle-Name: %Bundle-Name
Bundle-Activator: org.eclipse.papyrus.infra.tools.Activator
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.tools/pom.xml b/plugins/infra/core/org.eclipse.papyrus.infra.tools/pom.xml
index e6ea131dd4d..b0887fe3bcd 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.tools/pom.xml
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.tools/pom.xml
@@ -6,6 +6,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.tools</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/StatusUtils.java b/plugins/infra/core/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/StatusUtils.java
new file mode 100644
index 00000000000..ccb595da715
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/StatusUtils.java
@@ -0,0 +1,125 @@
+/*****************************************************************************
+ * Copyright (c) 2019 CEA LIST and others.
+ *
+ * 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
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.tools.util;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+/**
+ * Utility methods to manage status.
+ */
+public class StatusUtils {
+
+ /**
+ * Returns a localized message describing the given exception. If the given exception does not have a localized message, this returns the string "An error occurred".
+ *
+ * @param exception
+ * The current exception.
+ * @return The localized message of the exception.
+ */
+ public static String getLocalizedMessage(final Throwable exception) {
+ String message = exception.getLocalizedMessage();
+
+ if (message != null) {
+ return message;
+ }
+
+ // Workaround for the fact that CoreException does not implement a getLocalizedMessage() method.
+ // Remove this branch when and if CoreException implements getLocalizedMessage()
+ if (exception instanceof CoreException) {
+ CoreException ce = (CoreException) exception;
+ return ce.getStatus().getMessage();
+ }
+
+ return "An unexpected exception was thrown."; //$NON-NLS-1$
+ }
+
+ /**
+ * This allows to get the cause of an exception.
+ *
+ * @param exceptionThe
+ * current exception.
+ * @return The cause of an exception.
+ */
+ public static Throwable getCause(final Throwable exception) {
+ // Figure out which exception should actually be logged -- if the given exception is a wrapper, unwrap it
+ Throwable cause = null;
+ if (exception != null) {
+ if (exception instanceof CoreException) {
+ // Workaround: CoreException contains a cause, but does not actually implement getCause().
+ // If we get a CoreException, we need to manually unpack the cause. Otherwise, use the general-purpose mechanism. Remove this branch if CoreException ever implements a correct getCause() method.
+ final CoreException ce = (CoreException) exception;
+ cause = ce.getStatus().getException();
+ } else {
+ // use reflect instead of a direct call to getCause(), to allow compilation against JCL Foundation (bug 80053)
+ try {
+ final Method causeMethod = exception.getClass().getMethod("getCause"); //$NON-NLS-1$
+ final Object o = causeMethod.invoke(exception);
+ if (o instanceof Throwable) {
+ cause = (Throwable) o;
+ }
+ } catch (NoSuchMethodException e) {
+ // ignore
+ } catch (IllegalArgumentException e) {
+ // ignore
+ } catch (IllegalAccessException e) {
+ // ignore
+ } catch (InvocationTargetException e) {
+ // ignore
+ }
+ }
+
+ if (null == cause) {
+ cause = exception;
+ }
+ }
+
+ return cause;
+ }
+
+ /**
+ * This method must not be called outside the workbench.
+ * Utility method for creating status.
+ *
+ * @param pluginId
+ * The plugin identifier.
+ * @param severity
+ * The severity of the status to create.
+ * @param message
+ * The message of the status to create.
+ * @param exception
+ * The exception of the status to create.
+ * @return The created status.
+ */
+ public static IStatus newStatus(final String pluginId, final int severity, final String message, final Throwable exception) {
+
+ String statusMessage = message;
+ if (message == null || message.trim().length() == 0) {
+ if (exception.getMessage() == null) {
+ statusMessage = exception.toString();
+ } else {
+ statusMessage = exception.getMessage();
+ }
+ }
+
+ return new Status(severity, pluginId, severity, statusMessage, getCause(exception));
+ }
+
+}

Back to the top