Eclipse:如何以编程方式打开编辑器 [英] Eclipse: How to open an editor programatically

查看:153
本文介绍了Eclipse:如何以编程方式打开编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何打开一个编辑器程序。我首先创建了专用的文件,然后我想打开这种类型的文件的编辑器。但是我不能打开编辑器。也许有人可以帮助我这个。

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆