import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.simantics.scl.compiler.elaboration.modules.SCLValue;
-import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.module.InvalidModulePathException;
import org.simantics.scl.compiler.module.ModuleUtils;
import org.simantics.scl.compiler.source.ModuleSource;
import org.simantics.scl.osgi.SCLOsgi;
import org.simantics.scl.ui.editor.completion.SCLTextEditorEnvironment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class OpenDeclaration extends AbstractHandler {
+ private static final Logger LOGGER = LoggerFactory.getLogger(OpenDeclaration.class);
+
private static boolean isIdentifierPart(char c) {
return Character.isJavaIdentifierPart(c) || c=='.';
}
String moduleName = ModuleUtils.resolveAbsolutePath(input.getModuleName(), lineAtCaret.substring(p1+1, p2));
ModuleSource source = SCLOsgi.SOURCE_REPOSITORY.getModuleSource(moduleName, null);
if (source != null) {
- OpenSCLModule.openModule(moduleName);
+ OpenSCLModule.scheduleOpenModule(moduleName);
}
} catch (InvalidModulePathException e) {
- // Nothing to do
+ LOGGER.error("Could not open declaration {} {}", input.getModuleName(), lineAtCaret, e);
}
}
else {
SCLValue value = editorEnvironment.getValue(identifierAtCaret);
//System.out.println("identifierAtCaret = " + identifierAtCaret + " [" + Locations.beginOf(value.definitionLocation) + ", " + Locations.endOf(value.definitionLocation) + "]");
if(value != null)
- OpenSCLDefinition.openDefinition(value);
+ OpenSCLDefinition.scheduleOpenDefinition(value.getName().module, value.definitionLocation);
}
return null;
}
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.simantics.scl.compiler.elaboration.modules.SCLValue;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.ui.browser.SCLDefinitionSelectionDialog;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class OpenSCLDefinition extends AbstractHandler {
+ private static final Logger LOGGER = LoggerFactory.getLogger(OpenSCLDefinition.class);
+
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
SCLDefinitionSelectionDialog dialog = new SCLDefinitionSelectionDialog(
if(dialog.open() == SCLDefinitionSelectionDialog.OK) {
SCLValue value = (SCLValue)dialog.getFirstResult();
if(value != null)
- openDefinition(value);
+ scheduleOpenDefinition(value.getName().module, value.definitionLocation);
}
return null;
}
-
+
public static void openDefinition(SCLValue value) {
openDefinition(value.getName().module, value.definitionLocation);
}
-
- public static void openDefinition(String moduleName, long location) {
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- if(page == null)
- return;
- SCLModuleEditorInput input = new StandardSCLModuleEditorInput(moduleName);
- try {
- SCLModuleEditor2 editor = (SCLModuleEditor2)page.openEditor(input, "org.simantics.scl.ui.editor2");
- if(location != Locations.NO_LOCATION) {
- int begin = Locations.beginOf(location);
- int end = Locations.endOf(location);
- editor.selectAndReveal(begin, end-begin);
+
+ public static Runnable openDefinition(String moduleName, long location) {
+ return () -> {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ if(page == null)
+ return;
+ SCLModuleEditorInput input = new StandardSCLModuleEditorInput(moduleName);
+ try {
+ SCLModuleEditor2 editor = (SCLModuleEditor2)page.openEditor(input, "org.simantics.scl.ui.editor2");
+ if(location != Locations.NO_LOCATION) {
+ int begin = Locations.beginOf(location);
+ int end = Locations.endOf(location);
+ editor.selectAndReveal(begin, end-begin);
+ }
+ } catch (PartInitException e) {
+ LOGGER.error("", e);
}
- } catch (PartInitException e) {
- e.printStackTrace();
- }
+ };
+ }
+
+ public static void scheduleOpenDefinition(String moduleName, long location) {
+ Display.getCurrent().asyncExec(openDefinition(moduleName, location));
}
}
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));
}
}
if(bundle != null) {
CreateModuleAction.createModule(bundle, packageName.getText(), moduleName.getText());
parentBrowser.refresh();
- OpenSCLModule.openModule(packageName.getText() + "/" + moduleName.getText());
+ OpenSCLModule.scheduleOpenModule(packageName.getText() + "/" + moduleName.getText());
}
} catch (IOException e) {
ErrorDialog.openError(getParentShell(), "Module creation failed", e.getMessage(),
return;
ModuleNameTreeEntry entry = (ModuleNameTreeEntry)((IStructuredSelection)selection).getFirstElement();
if(entry.isModule)
- OpenSCLModule.openModule(entry.fullName);
+ OpenSCLModule.scheduleOpenModule(entry.fullName);
}
});