Merge "Bug 403109 - If the current IWorkbenchPart is not an IDiagramContainer, try to adapt it."
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/IDiagramContainerUI.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/IDiagramContainerUI.java
index bd2c413..f6239a5 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/IDiagramContainerUI.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/IDiagramContainerUI.java
@@ -65,8 +65,8 @@
public interface IDiagramContainerUI extends IDiagramContainer, IAdaptable {
/**
- * The ID of the context as it is registed with the org.eclipse.ui.contexts
- * extension point.
+ * The ID of the context as it is registered with the
+ * org.eclipse.ui.contexts extension point.
*
* @since 0.10
*/
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/action/PasteAction.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/action/PasteAction.java
index 110644e..1ac9732 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/action/PasteAction.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/action/PasteAction.java
@@ -94,12 +94,18 @@
PasteContext context = new PasteContext(pes);
Point pasteLocation = new Point(-1, -1);
IWorkbenchPart workbenchPart = getWorkbenchPart();
+ IDiagramContainerUI diagramContainer = null;
if (workbenchPart instanceof IDiagramContainerUI) {
- IDiagramContainerUI diagramContainer = (IDiagramContainerUI) workbenchPart;
+ diagramContainer = (IDiagramContainerUI) workbenchPart;
+ } else {
+ diagramContainer = (IDiagramContainerUI) workbenchPart.getAdapter(IDiagramContainerUI.class);
+ }
+
+ if (diagramContainer != null) {
pasteLocation = diagramContainer.getDiagramBehavior().calculateRealMouseLocation(
diagramContainer.getDiagramBehavior().getMouseLocation());
+ context.setLocation(pasteLocation.x, pasteLocation.y);
}
- context.setLocation(pasteLocation.x, pasteLocation.y);
return context;
}
}
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/platform/GFPropertySection.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/platform/GFPropertySection.java
index 765df07..2afb1ec 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/platform/GFPropertySection.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/platform/GFPropertySection.java
@@ -102,18 +102,27 @@
*/
protected IDiagramEditor getDiagramEditor() {
IWorkbenchPart part = getPart();
- if (part instanceof IDiagramEditor) {
- return (IDiagramEditor) part;
+
+ IDiagramEditor ret = checkAdapter(part, IDiagramEditor.class);
+ if (ret != null) {
+ return ret;
}
IContributedContentsView contributedView = (IContributedContentsView) part.getAdapter(IContributedContentsView.class);
if (contributedView != null) {
part = contributedView.getContributingPart();
}
- if (part instanceof IDiagramEditor) {
- return (IDiagramEditor) part;
+
+ ret = checkAdapter(part, IDiagramEditor.class);
+ return ret;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <U> U checkAdapter(IAdaptable adaptable, Class<U> clazz) {
+ if (clazz.isInstance(adaptable)) {
+ return (U) adaptable;
}
- return null;
+ return (U) adaptable.getAdapter(clazz);
}
/**
@@ -122,19 +131,18 @@
*/
protected IDiagramContainer getDiagramContainer() {
IWorkbenchPart part = getPart();
- if (part instanceof IDiagramContainer) {
- return (IDiagramContainer) part;
+ IDiagramContainer ret = checkAdapter(part, IDiagramContainer.class);
+ if (ret != null) {
+ return ret;
}
+
IContributedContentsView contributedView = (IContributedContentsView) part
.getAdapter(IContributedContentsView.class);
if (contributedView != null) {
part = contributedView.getContributingPart();
}
- if (part instanceof IDiagramContainer) {
- return (IDiagramContainer) part;
- }
-
- return null;
+ ret = checkAdapter(part, IDiagramContainer.class);
+ return ret;
}
/**