Making the view selector available for the user in a RCP/RAP application is quite easy. For this small example we will use the RCP mail demo.

To create the project, select FileNewProjectPlug-in Project, and use benl.smartapps.maildemo as the project name.

Click on Next button.

It’s important that you set the Rich Client Application to yes. After clicking Next, select the RCP Mail Template and finally click the Finish button. This will result in Eclipse creating a new project based on the RCP Mail Demo. In the screen it opens you can press Launch an Eclipse application.

After clicking the launch link you will see following application

As you can see the application is missing the Perspective selector we usually have in Eclipse. To make it visible is quite easy. In the project find the ApplicationWorkbenchWindowAdvisor in the SRC folder.

If you open this class you will see the function preWindowOpen() function. This function will call in the constructor of the Workbench Window. Use this method to set options such as hiding the menu bar, etc.

The code that is already filled in under this function looks like the following:

Now we add the following code:

Now if we leave it as  is, we would get the Perspective selector in our workbench. However, we want to be sure that the user knows what it means. So after saving our changes we go back to our plugin.xml and go to the Extensions tab. Here we expand the  org.eclipse.ui.perspectives extension and select the RCP Perspective. The problem is that RCP Perspective doesn’t inform the end user what it is or what it will do. So when setting a perspective in the Extensions it is very important that the name field is filled in with a clear and understandable name which will inform the end user what kind of function it is. In our little example we will set it to Mail.

If we run the application now after saving our changes the application will look something like this:

The red marking shows what we just added. Now we can style this to look and make it look a bit more advanced.

First, we will give the view its own icon so that it’s more distinctive then the default icon perspective gives. We select the Mail perspective in the Extension tab. Choose your icon via the browse button or just type it in.

Note: ico files are not fully supported in Eclipse RAP.

Now we can do the customization of the look and feel trough 2 methods one of them is creating the plugin_customization.ini or you can do it hardcoded trough the ApplicationWorkbenchWindowAdvisor . Because we’re demonstrating that it can be done in RCP and RAP project this example will use the ApplicationWorkbenchWindowAdvisor so that it can be used in both projects. You can choose to use both method and creating a fragment file for the RAP project. For more information about using the plugin_customization.ini file you can read the article here.

So nowopen the ApplicationWorkbenchWindowAdvisor again and we can play a bit with the IWorkbenchPreferenceConstants.

For now we edit the code a bit like this:

Note: The IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS does not work for RAP applications.

You can look up more settings on the IWorkbenchPrefereceConstants in the RCP api. The above  settings will result in the following:

Now we need to set the default perspective. To do that we need to implement the getInitialWindowPerspectiveId function. Go back to the Extensions tab of the plugin.xml.

Here you can see the id of the Extensions:

To be sure that the ID is also known in the Perspective click on the class link. The Eclipse IDE will now open the perspective class. Here you can see the ID of the perspective as well and it should match the ID you saw in the Extension Element Details.

First, we have to set the private static final String PERSPECTIVE_ID. The ID will be the ID of the Perspective Extension you want as default. So in our case this would be benl.smartapps.maildemo.perspective. Then we add the public String getInitialWindowPerspectiveId() returning the PERSPECTIVE_ID. This would result in the following code:

Now the application will always open the default perspective by default if the user has not saved the state of the workbench.