]> 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 a0208e5b24d28f2dc0696f512062920af53e281a..b2df02fb4f0dc22e661926b34a8eac157c8f4b30 100644 (file)
@@ -3,33 +3,44 @@ 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();
-            openModule(moduleName);
+            scheduleOpenModule(moduleName);
         }
         return null;
     }
 
-    public static void openModule(String moduleName) {
-        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) {
-            e.printStackTrace();
-        }
+    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));
     }
 
 }