Adding a View in RCP Application

In the turotial Creating a Simple Hello World RCP Application, we already know how to create a simple Hello World application.
Now, how about adding some view to it!

A simple Hello World RCP application doesn't support creating view in it. So, for this purpose, we need to add some dependencies in it.

Adding Dependencies

Step 1: Create a simple RCP Application with Hello World template.

Step 2: Open MANIFEST.MF file and go to Extensions tab. Now, it looks like this.

Step 3: Click on Add, write: org.eclipse.ui.views. Select the dependency and click on Finish. The dependency will be added to your All Dependencies section.

Creating a View

Step 1: Right click on Views dependency. New -> View. Then, provide some details. Save it,

Step 2: Create the View class. For that purpose, click on class* hyperlink in the page. A class creation dialogue is opened. Click on Finish.

Step 3: Select the class you have just generated in Navigator , right click on it, select open with WindowBuilder Editor. WindowBuilder will help you to create java class in a more interactive way.

Step 4: Go to Design tab. The design will look like this.

Step 5: Add some small functionalities in the design page.
 For example,you can add composite at first, and then add Label and write something inside it. The result will look something like this.

Step 6: Open in Java editor. Add this code :

 public static final String ID = "SimpleRCPWithView.MainView";

Make sure that the id you mentioned here is same as the id you provided while creating the view MainView. You can get that id in MANIFEST.MF -> Extensions.

Step 7:  Modify the file (which is automatically generated) so that it looks like this.

public class Perspective implements IPerspectiveFactory {

 public void createInitialLayout(IPageLayout layout) {
  layout.addStandaloneView(MainView.ID, false, IPageLayout.LEFT, 1.0f, layout.getEditorArea());

Step 8: Run this code. The output will be :

Read Also:

Creating a Simple Hello World RCP Application.
Export a RCP application as a Product

Happy Learning!