Eclipse:如何以编程方式打开编辑器 [英] Eclipse: How to open an editor programatically
问题描述
...
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);
....
干杯,
Phil
首先,您必须使用 org.eclipse.ui.editors
扩展名定义您的编辑器点:
< extension
point =org.eclipse.ui.editors >
< editor
name =示例多页面编辑器
extensions =mpe
icon =icons / sample.gif
contributorClass = .editors.MultiPageEditorContributor
class =tested.editors.MultiPageEditor
id =tested.editors.MultiPageEditor>
< / editor>
< / extension>
(上面是由提供的多页编辑器示例创建的)。
然后您可以使用:
IDE.openEditor(页面,文件,tested.editors .MultiPageEditor);
打开 IFile
指定的编辑器您的编辑器ID或扩展名
指定的编辑器将是默认值,您可以使用
IDE.openEditor(页面,文件);
您还可以使用 contentTypeBinding
子元素编辑器
指定内容类型,然后编辑器将处理。
I'm wondering how I can open an editor programaticaly. 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. Maybe someone can help me wth this.
...
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);
....
Cheers, Phil
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.
这篇关于Eclipse:如何以编程方式打开编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!