]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Add getActiveIEditorPart to E4WorkbenchUtils 08/308/1
authorjsimomaa <jani.simomaa@gmail.com>
Thu, 19 Jan 2017 11:17:33 +0000 (13:17 +0200)
committerjsimomaa <jani.simomaa@gmail.com>
Wed, 1 Feb 2017 10:03:11 +0000 (12:03 +0200)
Change-Id: Ie800b8da7a219e5c361620a1005a2a7428d760a5

bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java

index a7db1e2aa930e8dd0974aed267a941687309e95f..5299b898124135056d6f4f04c248f2c6b9a2c150 100644 (file)
@@ -14,9 +14,12 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
 import org.eclipse.e4.ui.workbench.modeling.EModelService;
 import org.eclipse.e4.ui.workbench.modeling.EPartService;
 import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
+import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
 import org.simantics.db.Resource;
 import org.simantics.utils.datastructures.ArrayMap;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
 
 /**
  * @author Tuukka Lehtonen
@@ -164,4 +167,20 @@ public class E4WorkbenchUtils {
         return partService.findPart(partId);
     }
 
+    @SuppressWarnings("restriction")
+    public static IEditorPart getActiveIEditorPart(MPart mActiveEditorPart) {
+        // TODO: Fix this when we get rid of CompatibilityEditors
+        IEditorPart activeEditor = null;
+        if (mActiveEditorPart != null) {
+            Object editor = mActiveEditorPart.getObject();
+            if (editor instanceof CompatibilityEditor) {
+                CompatibilityEditor compEditor = (CompatibilityEditor) editor;
+                activeEditor = compEditor.getEditor();
+            } else {
+                // TODO: This is not good practice with E4 but an OK fallback for now
+                activeEditor = WorkbenchUtils.getActiveEditor();
+            }
+        }
+        return activeEditor;
+    }
 }