如何以编程方式在eclipse 4.4中打开文本编辑器? [英] how to open a text editor in eclipse 4.4 programmatically?

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

问题描述

我想以编程方式在eclipse 4.4中打开一个文本编辑器.我已经使用IDE类进行了尝试,但是在Eclipse 4.4中无法访问.我该怎么办?

I want to open a text editor in eclipse 4.4 programmatically. I've tried it using IDE class but it is not accessible in eclipse 4.4. How can I do this?

推荐答案

e4仅包含部分,而没有编辑器和视图.它还没有任何预定义的文本编辑器.

e4 only has parts, not editors and views. It also doesn't have any predefined text editors.

假设您要同时打开多个编辑器部件,则需要在编辑器的应用程序模型中定义一个部件描述符".

Assuming you want to have several editor parts open at the same time you need to define a 'Part Descriptor' in the application model for the editor.

然后,您可以使用以下描述从描述符中创建零件:

You then create a part from the descriptor using:

@Inject
EPartService partService;


MPart part = partService.createPart("descriptor id");

您现在需要将此添加到应用程序模型中.通常,这将是'MPartStack'的子代:

You now need to add this to the application model. Usually this will be a child of an 'MPartStack':

@Inject
EModelService modelService;
@Inject
MApplication app;

MPartStack editorStack = (MPartStack)modelService.find("part stack id", app);

editorStack.getChildren().add(part);

最后显示零件:

partService.showPart(part, PartState.ACTIVATE);

您在零件描述符中为编辑器指定的类将必须实现文本编辑器.您可以使用JFace文本编辑器类,但不能使用"org.eclipse.ui.xxx"编辑器类.

The class you specify in the part descriptor for the editor will have to implement the text editor. You can use the JFace text editor classes but not the 'org.eclipse.ui.xxx' editor classes.

对于一个非常简单的文本编辑器, TextViewer Document 类就足够了.

For a very simple text editor the TextViewer and Document classes are enough.

这篇关于如何以编程方式在eclipse 4.4中打开文本编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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