简体   繁体   中英

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. 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. 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. 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.

Thanks for the help.

您可以将上面的代码与...getDisplay().syncExec(...)使用,然后将指向编辑器的指针存储在某些封闭的对象中。

如果直接从编辑器中启动配置(单击鼠标右键,以..身份运行),则可以仅使用ILaunchShortcut并覆盖其void launch(IEditorPart editor, String mode)方法来访问启动文件的编辑器从。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM