Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

3. Your first Eclipse RAP application

3.1. Create Project

Create a new plugin project "de.vogella.rap.first" via File -> New -> Project -> Plug-in Development -> Plug-in Project. Perform the following selection.

Select the "RAP Hello World" template and press "Finish".

3.2. Run

Select your "MANIFEST.MF", right click on it, select Run-as-> Rap Application.

This should start your first RAP application.

Congratulations! You have your first Eclipse RAP application running.

3.3. Entrypoint

Eclipse RAP requires an entrypoint similar to "org.eclipse.core.runtime.applications" for Eclipse RCP applications. The entrypoint for Eclipse RAP is defined via "org.eclipse.rap.ui.workbench.entrypoint".

View your Entrypoint via the entension "org.eclipse.rap.ui.workbench.entrypoint" in the file "MANIFEST.MF" . Please note that the parameter "default" is used in your runtime configuration of RAP.

.

3.4. Extending your UI

Create now a view. Select therefore in MANIFEST.MF the tab extension and add the extension point "org.eclipse.ui.views". Add then add the view with the id "de.vogella.rap.first.View". The procedure is the same as for Eclipse RCP application which is described in Adding views to Eclipse RCP applications .

Create the following view class.

				
package de.vogella.rap.first;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

public class View extends ViewPart {

	public static final String ID = "de.vogella.rap.first.View";

	@Override
	public void createPartControl(Composite parent) {
		Label label = new Label(parent, SWT.NONE);
		label.setText("This is my label");
		Text text = new Text(parent, SWT.NONE);
		text.setText("Input");
	}

	@Override
	public void setFocus() {

	}

}

			

Add the view to the perspective by changing Perspective.java to the following.

				
package de.vogella.rap.first;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

/**
 * Configures the perspective layout. This class is contributed 
 * through the plugin.xml.
 */
public class Perspective implements IPerspectiveFactory {

	public void createInitialLayout(IPageLayout layout) {
		String editorArea = layout.getEditorArea();
		layout.setEditorAreaVisible(false);
		
		layout.addStandaloneView(View.ID,  false, IPageLayout.LEFT, 0.25f, editorArea);
	
	}
}

			

Run your application and see your new view in actions.

Eclipse RAP supports most of the API JFace and Eclipse RCP support. If you want to learn how you can extend your Eclipse RAP application you can review Eclipse RCP Tutorial or Eclipse JFace TableViewer

Of course Eclipse RAP does only support a subset of these API (but this is increasing every release) so the best way of exploring it is to build your application and see which API are available.