[英]Access Active Editor from Eclipse Launch Delegate
I am developing an interpreter for a visual programming language that I am implementing using Eclipse, EMF and GEF. 我正在为使用Eclipse,EMF和GEF实现的可视化编程语言开发解释器。 I am currently creating an interpreter for the diagrams. 我目前正在为图表创建解释器。
To execute a diagram, I decided to implement a launcher configuration. 为了执行图,我决定实现启动器配置。 When the configuration is executed I want to read the EMF model from the active editor and interpret it. 执行配置后,我想从活动编辑器中读取EMF模型并对其进行解释。 The problem I have is that the active editor can only be accessed from the UI thread, and I don't want the interpreter to execute in the UI tread since it may be a long process. 我的问题是只能从UI线程访问活动编辑器,并且我不希望解释器在UI界面中执行,因为这可能是一个漫长的过程。 This is the code that works but should not be used: 这是有效的代码,但不应使用:
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
IEditorPart activeEditor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
OPMGraphicalEditor editor = (OPMGraphicalEditor) activeEditor;
OPMObjectProcessDiagram opd = editor.getOPD();
Interpreter.INSTANCE.interpret(opd);
}
});
}
I'm sure there is a proper way to do this, but I haven't found it. 我敢肯定有适当的方法可以做到这一点,但是我还没有找到。 The examples for launch configurations that I found in the internet use external programs, but I am (currently) implementing my interpreter as part of the workbench. 我在Internet上找到的启动配置示例使用外部程序,但是(当前)我正在将解释器实现为工作台的一部分。
Thanks for the help. 谢谢您的帮助。
您可以将上面的代码与...getDisplay().syncExec(...)
使用,然后将指向编辑器的指针存储在某些封闭的对象中。
如果直接从编辑器中启动配置(单击鼠标右键,以..身份运行),则可以仅使用ILaunchShortcut
并覆盖其void launch(IEditorPart editor, String mode)
方法来访问启动文件的编辑器从。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.