在EclipseRCP应用程序中启动时打开编辑器

在EclipseRCP应用程序中启动时打开编辑器

本文介绍了在EclipseRCP应用程序中启动时打开编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Java的Eclipse RCP应用程序进行大学项目的编程。

I'm currently programming on an eclipse RCP application in Java for an university project.

我的问题是我希望在应用程序启动时加载编辑器,但是我不知道哪种方法是正确的开始。在透视图中,我只能添加视图并设置编辑器空间,但不能设置任何编辑器。

My problem is that I want an editor loaded at application start, but I don't know which method is the right one to start with. In the perspective I can only add views and set my editor space, but I can't set any editors.

我尝试覆盖 WorkbenchWindowAdvisor.postWindowOpen()方法,但这只给我一个例外...

I tried overwrite the WorkbenchWindowAdvisor.postWindowOpen() method, but this only got me an exception...

推荐答案

您说您遇到了异常。这是什么?您如何覆盖postWindowOpen(),可以发布代码吗?如果我知道这些事,我可以为您提供更多帮助。

You say you got an exception.. what was it? How did you overwrite postWindowOpen(), can you post your code? I could help you more if I knew these things.

无论如何,以下代码会在应用程序启动时打开编辑器:

Anyway, the following code opens the editor at application startup:

@Override
public void postWindowOpen() {

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

    try {
        page.openEditor(editorInput, editorId);
    } catch (PartInitException e) {
        // Handle the exception here
    }
}

其中 editorInput是编辑器的输入, editorId是ID。

另外,我强烈建议阅读Lars Vogel的编辑器教程:

where "editorInput" is the input of your editor and "editorId" it's ID.
Also, I highly recommend reading Lars Vogel's tutorial on editors:
http://www.vogella.de/articles/EclipseEditors/article.html

这篇关于在EclipseRCP应用程序中启动时打开编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:42