]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4WorkbenchUtils.java
Combination of Simantics-platform related changes and fixes for district
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / e4 / E4WorkbenchUtils.java
index 3c1888a0112c2c2f382e82c05915372ce51d440d..6d7daeb3c6ff191f8e04e444240bf99776f699d3 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Map;
 
 import org.eclipse.e4.core.contexts.IEclipseContext;
 import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.commands.MCommand;
 import org.eclipse.e4.ui.model.application.ui.MUIElement;
 import org.eclipse.e4.ui.model.application.ui.advanced.MArea;
 import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
@@ -14,9 +15,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
@@ -166,5 +170,32 @@ public class E4WorkbenchUtils {
             part = partService.createPart(partId);
         return part;
     }
+    
+    public static MCommand getMCommandById(String id) {
+        IEclipseContext context = PlatformUI.getWorkbench().getService(IEclipseContext.class);
+        MApplication application = context.get(MApplication.class);
+        for (MCommand command : application.getCommands()) {
+            if (id.equals(command.getElementId())) {
+                return command;
+            }
+        }
+        return null;
+    }
 
+    @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;
+    }
 }