2

我想知道如何以编程方式打开编辑器。我首先创建了适当的文件,然后我想为这种类型的文件打开编辑器。但是那时我无法打开编辑器。

...
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
PlcEditor editor = new PlcEditor(emfResource);
page.openEditor(editor, "test");
...

我已经有了以下解决方案(有效),但在这里我无法调用我的编辑器的构造函数:

....
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart openEditor = IDE.openEditor(page, plcFile);
....
4

1 回答 1

2

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

You can then use:

IDE.openEditor(page, file, "tested.editors.MultiPageEditor");

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);

You can also use the contentTypeBinding child element of editor to specify content types then editor will handle.

于 2013-11-06T16:56:21.470 回答