1 package org.simantics.scl.ui.editor2;
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;
13 public class OpenSCLDefinition extends AbstractHandler {
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();
22 openDefinition(value);
27 public static void openDefinition(SCLValue value) {
28 openDefinition(value.getName().module, value.definitionLocation);
31 public static void openDefinition(String moduleName, long location) {
32 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
35 SCLModuleEditorInput input = new StandardSCLModuleEditorInput(moduleName);
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);
43 } catch (PartInitException e) {