Eclipse:如何以编程方式打开编辑器 [英] Eclipse: How to open an editor programmatically
问题描述
我想知道如何以编程方式打开编辑器。我首先创建了适当的文件,然后要打开此文件类型的编辑器。但是我当时无法打开编辑器。
I'm wondering how I can open an editor programmatically. I first created the appropriated file and then I want to open the editor for this type of file. But I'm not able to open the editor then.
...
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
PlcEditor editor = new PlcEditor(emfResource);
page.openEditor(editor, "test");
...
我已经有以下解决方案(有效),但是在这里无法调用我的编辑器的构造函数:
I already had the following solution (which works), but here I wasn't able to call the constructr of my editor:
....
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart openEditor = IDE.openEditor(page, plcFile);
....
推荐答案
首先,您必须使用 org.eclipse.ui.editors
扩展点将您的编辑器定义为Eclipse:
First you must define your editor to Eclipse using the org.eclipse.ui.editors
extension point:
<extension
point="org.eclipse.ui.editors">
<editor
name="Sample Multi-page Editor"
extensions="mpe"
icon="icons/sample.gif"
contributorClass="tested.editors.MultiPageEditorContributor"
class="tested.editors.MultiPageEditor"
id="tested.editors.MultiPageEditor">
</editor>
</extension>
(以上由提供的多页编辑器示例创建)。
(above is as created by the provided multi-page editor example).
然后可以使用:
IDE.openEditor(page, file, "tested.editors.MultiPageEditor");
在 IFile
上打开编辑器您的编辑器ID,或为扩展名
指定的编辑器将是默认值,您可以使用
to open the editor on an IFile
specifying your editor id, or for the extension
specified the editor will be the default and you can just use
IDE.openEditor(page, file);
您还可以使用 contentTypeBinding
子元素编辑器
来指定内容类型,然后编辑器将处理。
You can also use the contentTypeBinding
child element of editor
to specify content types then editor will handle.
这篇关于Eclipse:如何以编程方式打开编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!