Friday, August 17, 2007

Tabbed Views in Eclipse RCP

Tabbed Views in Eclipse RCP sounds really complicated but Eclipse has made this really easy. Just follow these simple instructions and you will be off and running with multiple tabbed views.

  1. Open your perspective.java file (If you don't have this file yet, you are in trouble!)
  2. in public void createInitialLayout(IPageLayout layout) you should have some code that looks similar to this:
    layout.addStandaloneView(ItagTreeView.ID, true, IPageLayout.LEFT, 1.0f, editorArea);
    layout.addStandaloneView(ChartView.ID, true, IPageLayout.RIGHT, 0.5f, ItagTreeView.ID);
    layout.addStandaloneView(FormView.ID, true, IPageLayout.BOTTOM, 0.5f, ItagTreeView.ID);

    // create a folder for multiple analysis views so that they will open up
    // in tabs next to the table view.
    IFolderLayout folder = layout.createFolder("Tables", IPageLayout.BOTTOM, 0.5f, ChartView.ID);
    folder.addPlaceholder(AnalysisView.ID + ":*");
    folder.addView(TableView.ID);

    The above code has 4 views and the table view is it. Our AnalysisView is a 2nd tab under the TableView.

    You can see instead of calling addStandaloneView we call createFolder. The "folder" is how we combine several views to make a tabbed view presentation.
I hope that this will help anyone struggling to add tabbed views for an Eclipse RCP application. If you have any questions or comments please feel free to contact me.

3 comments:

alwi said...

Thanks! It solved my problem. Is there a way to do it by using plugin.xml?

Unknown said...

I have never tried with plugin.xml but I am sure there is.

laforge2001 said...

you can use the org.eclipse.ui.perspectiveExtensions extension to add views declaratively via the plugin.xml. Lars Vogel has a nice example of this here: http://www.vogella.de/articles/RichClientPlatform/article.html#views_perspective