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.swt.widgets.Display;
7 import org.eclipse.ui.IWorkbenchPage;
8 import org.eclipse.ui.PartInitException;
9 import org.eclipse.ui.PlatformUI;
10 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
11 import org.simantics.scl.compiler.errors.Locations;
12 import org.simantics.scl.ui.browser.SCLDefinitionSelectionDialog;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 public class OpenSCLDefinition extends AbstractHandler {
18 private static final Logger LOGGER = LoggerFactory.getLogger(OpenSCLDefinition.class);
21 public Object execute(ExecutionEvent event) throws ExecutionException {
22 SCLDefinitionSelectionDialog dialog = new SCLDefinitionSelectionDialog(
23 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
24 if(dialog.open() == SCLDefinitionSelectionDialog.OK) {
25 SCLValue value = (SCLValue)dialog.getFirstResult();
27 scheduleOpenDefinition(value.getName().module, value.definitionLocation);
32 public static void openDefinition(SCLValue value) {
33 openDefinition(value.getName().module, value.definitionLocation);
36 public static Runnable openDefinition(String moduleName, long location) {
38 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
41 SCLModuleEditorInput input = new StandardSCLModuleEditorInput(moduleName);
43 SCLModuleEditor2 editor = (SCLModuleEditor2)page.openEditor(input, "org.simantics.scl.ui.editor2");
44 if(location != Locations.NO_LOCATION) {
45 int begin = Locations.beginOf(location);
46 int end = Locations.endOf(location);
47 editor.selectAndReveal(begin, end-begin);
49 } catch (PartInitException e) {
55 public static void scheduleOpenDefinition(String moduleName, long location) {
56 Display.getCurrent().asyncExec(openDefinition(moduleName, location));