]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLModule.java
Fix annoying editor focus jumping with Ctrl+Shift+D/M
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / editor2 / OpenSCLModule.java
index a9792a4d03339b49cd887232fc0a68537619979c..b2df02fb4f0dc22e661926b34a8eac157c8f4b30 100644 (file)
@@ -1,31 +1,46 @@
-package org.simantics.scl.ui.editor2;\r
-\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.ui.IWorkbenchPage;\r
-import org.eclipse.ui.PartInitException;\r
-import org.eclipse.ui.PlatformUI;\r
-\r
-public class OpenSCLModule extends AbstractHandler {\r
-\r
-    @Override\r
-    public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        SCLModuleSelectionDialog dialog = new SCLModuleSelectionDialog(\r
-                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());\r
-        if(dialog.open() == SCLModuleSelectionDialog.OK) {\r
-            String moduleName = (String)dialog.getFirstResult();\r
-            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();\r
-            if(page == null)\r
-                return null;\r
-            SCLModuleEditorInput input = new StandardSCLModuleEditorInput(moduleName);\r
-            try {\r
-                page.openEditor(input, "org.simantics.scl.ui.editor2");\r
-            } catch (PartInitException e) {\r
-                e.printStackTrace();\r
-            }\r
-        }\r
-        return null;\r
-    }\r
-\r
-}\r
+package org.simantics.scl.ui.editor2;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OpenSCLModule extends AbstractHandler {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(OpenSCLModule.class);
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        SCLModuleSelectionDialog dialog = new SCLModuleSelectionDialog(
+                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+        if(dialog.open() == SCLModuleSelectionDialog.OK) {
+            String moduleName = (String)dialog.getFirstResult();
+            scheduleOpenModule(moduleName);
+        }
+        return null;
+    }
+
+    public static Runnable openModule(String moduleName) {
+        return () -> {
+            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+            if(page == null)
+                return;
+            SCLModuleEditorInput input = new StandardSCLModuleEditorInput(moduleName);
+            try {
+                page.openEditor(input, "org.simantics.scl.ui.editor2");
+            } catch (PartInitException e) {
+                LOGGER.error("Could not open module {} ", moduleName, e);
+            }
+        };
+    }
+
+    public static void scheduleOpenModule(String moduleName) {
+        Display.getCurrent().asyncExec(openModule(moduleName));
+    }
+
+}