]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLDefinition.java
Preventing unnecessary ModuleSource compilation in SCL-editor
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / editor2 / OpenSCLDefinition.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.ui.IWorkbenchPage;
7 import org.eclipse.ui.PartInitException;
8 import org.eclipse.ui.PlatformUI;
9 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
10 import org.simantics.scl.compiler.errors.Locations;
11 import org.simantics.scl.ui.browser.SCLDefinitionSelectionDialog;
12
13 public class OpenSCLDefinition extends AbstractHandler {
14
15     @Override
16     public Object execute(ExecutionEvent event) throws ExecutionException {
17         SCLDefinitionSelectionDialog dialog = new SCLDefinitionSelectionDialog(
18                 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
19         if(dialog.open() == SCLDefinitionSelectionDialog.OK) {
20             SCLValue value = (SCLValue)dialog.getFirstResult();
21             if(value != null)
22                 openDefinition(value);
23         }
24         return null;
25     }
26     
27     public static void openDefinition(SCLValue value) {
28         openDefinition(value.getName().module, value.definitionLocation);
29     }
30     
31     public static void openDefinition(String moduleName, long location) {
32         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
33         if(page == null)
34             return;
35         SCLModuleEditorInput input = new StandardSCLModuleEditorInput(moduleName);
36         try {
37             SCLModuleEditor2 editor = (SCLModuleEditor2)page.openEditor(input, "org.simantics.scl.ui.editor2");
38             if(location != Locations.NO_LOCATION) {
39                 int begin = Locations.beginOf(location);
40                 int end = Locations.endOf(location);
41                 editor.selectAndReveal(begin, end-begin);
42             }
43         } catch (PartInitException e) {
44             e.printStackTrace();
45         }
46     }
47
48 }