]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLModule.java
Externalize strings in org.simantics.scl.ui
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / editor2 / OpenSCLModule.java
1 package org.simantics.scl.ui.editor2;
2
3 import org.eclipse.core.commands.AbstractHandler;
4 import org.eclipse.core.commands.ExecutionEvent;
5 import org.eclipse.core.commands.ExecutionException;
6 import org.eclipse.swt.widgets.Display;
7 import org.eclipse.ui.IWorkbenchPage;
8 import org.eclipse.ui.PartInitException;
9 import org.eclipse.ui.PlatformUI;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12
13 public class OpenSCLModule extends AbstractHandler {
14
15     private static final Logger LOGGER = LoggerFactory.getLogger(OpenSCLModule.class);
16
17     @Override
18     public Object execute(ExecutionEvent event) throws ExecutionException {
19         SCLModuleSelectionDialog dialog = new SCLModuleSelectionDialog(
20                 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
21         if(dialog.open() == SCLModuleSelectionDialog.OK) {
22             String moduleName = (String)dialog.getFirstResult();
23             scheduleOpenModule(moduleName);
24         }
25         return null;
26     }
27
28     public static Runnable openModule(String moduleName) {
29         return () -> {
30             IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
31             if(page == null)
32                 return;
33             SCLModuleEditorInput input = new StandardSCLModuleEditorInput(moduleName);
34             try {
35                 page.openEditor(input, "org.simantics.scl.ui.editor2"); //$NON-NLS-1$
36             } catch (PartInitException e) {
37                 LOGGER.error("Could not open module {} ", moduleName, e); //$NON-NLS-1$
38             }
39         };
40     }
41
42     public static void scheduleOpenModule(String moduleName) {
43         Display.getCurrent().asyncExec(openModule(moduleName));
44     }
45
46 }