Open Editor at Start in an EclipseRCP application

2019-08-12 09:06发布

问题:

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.

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

回答1:

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
    }
}

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