| Java, Eclipse and Web programming Tutorials |
Version 0.7
Copyright © 2008 - 2009 Lars Vogel
19.12.2009
| Revision History | ||
|---|---|---|
| Revision 0.1- 0.2 | 03.03.2008 | Lars Vogel |
| Created | ||
| Revision 0.3 | 31.05.2009 | Lars Vogel |
| Updated to Eclipse 3.5 | ||
| Revision 0.4 | 01.06.2009 | Lars Vogel |
| Example updated, added theming based on the CSS style | ||
| Revision 0.5 | 01.06.2009 | Lars Vogel |
| Added missing themes file, build.properties, hint to Bug 278416 | ||
| Revision 0.6 | 12.06.2009 | Lars Vogel |
| Single Sourcing | ||
| Revision 0.7 | 17.06.2009 | Lars Vogel |
| Update due to solved bug 278416 | ||
| Revision 0.8 | 19.12.2009 | Lars Vogel |
| Fixed syntax error in View.java | ||
Eclipse RAP
This article describes the basic steps to create Eclipse RAP applications and how to use the CSS theming to modify their look. Eclipse RAP aims to enable developers to build rich, Ajax-enabled web applications by using the Eclipse development model.
This article assumes that you are already familiar with using the Eclipse IDE. This tutorial is based on Eclipse 3.5 (Galileo).
Table of Contents
Eclipse RAP is a Eclipse based platform for Ajax web applications which provides part of the API of Eclipse RCP . Eclipse RAP allows to use Eclipse RCP paradigm for developing Ajax web-applications.
RAP is based on the OSGi implementation Equinox . It is possible to run Eclipse RAP applications via the OSGi servlet bridge in a servlet container, e.g. Apache Tomcat or Jetty.
Eclipse RAP supports extension points, views, perspectives, selection service, commands, handlers, editors and databinding.
Eclipse archives this by providing its own implementations for SWT, JFace and the Workbench. Eclipse RAP replaces SWT with RWT (RAP widget toolkit) layer. This toolkit is based on the qooxdoo Ajax library. RWT is a distributed system; every RWT widget has a client and a server part. These part communicate via Ajax.
During development Eclipse RAP applications run in the embedded webserver Jetty.
Eclipse RAP does not provide all the possibilities Eclipse RCP (or the underlying plugins provide. For example Eclipse RAP has no Graphics Context which can be used in SWT to draw directly onto the SWT widgets.
Each Eclipse RAP releases provides more functionality so that the differences between Eclipse RCP and Eclipse RAP are getting smaller every day.
Before continuing create a new workspace for your Eclipse RAP projects. As you have to change the target platform to compile against Eclipse RAP your other project will not continue to work.
Use the Eclipse Update Manager to install the Rich Ajax Platform. This package can be found under the Galileo Update site under "Web, XML, and Java EE Development" -> Rich Ajax Platform SDK (RAP) See Using the Eclipse Update Manager for details.
Eclipse RAP have its own target platform. A target platform contains the artifacts, e.g. plugins, against which the Eclipse plugins are compiled. For example Eclipse RAP does not rely on SWT but on RWT therefore the target platform must provide these.
Download the RAP target platform from Eclipse RAP downloads and unzip it into a new directory, e.g. "c:\EclipseRAPTarget".
Change the target platform under Window -> Preferences -> Plug-in Development -> Target Platform
Press "Add".

Select "Nothing" as template and maintain the directory of the target platform as the location.


Switch to your new Target Platform.

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".

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.
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.
.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.
A Eclipse RAP application look similar to a Eclipse RCP application running in a browser. While this is cool, it is not necessary always what you want if you develop a web application.
Eclipse RAP therefore provides the possibility to change the look of the application via theming. Themes can be defined in css like files. The following will give an demonstration how to do this.
Create a new Eclipse RAP project "de.vogella.rap.theming". Use the "RAP Mail Template" as template.
Create a new folder "themes" in your project.
Add the directory themes to your build.properties. Otherwise the files from themes will not get included in an exported product.

Add the extension point "org.eclipse.rap.ui.themes". Use the following settings.

Create now the following file "theme.css" in the folder themes.
* {
backgound-color: yellow;
color: red;
}
Add now the "org.eclipse.rap.ui.branding" extension point which the following settings. Important is the servletName "rap" as this is used in your runtime configuration, your entrypoint and the theme you want to use.

This will result in the following rap application display.

For additional properties in the style sheet check the RAP Theming Wiki (link below).
With Eclipse RAP it is possible to develop a desktop application Eclipse RCP and a web application with the same source code. This is called single sourcing.
To use the same code basis for Eclipse RCP and Eclipse RAP you can use OSGi fragments. Fragments are special OSGi bundles, which extend another bundle and are merged at runtime with the extended bundle. You can put the RCP or RAP specific functionality into a fragment. If you create a RAP application you use the RAP fragment or if you want to create a RCP application you use the RCP fragment.
One difference between RCP and RAP is that in RCP you only have one user. In case you are using singletons which should be user specific then you have to use the RAP class SessionSingleBase. In case you have a real singleton for several users you need to consider concurrency issues. JFace Preference are already correctly supported in RAP.
For more on single sourcing check the RAP homepage .
Thank you for practicing with this tutorial.
Please note that I maintain this website in my private time. If you like the information I'm providing please help me by donating.For questions and discussion around this article please use the www.vogella.de Google Group. Also if you note an error in this article please post the error and if possible the correction to the Group.
I believe the following is a very good guideline for asking questions in general and also for the Google group How To Ask Questions The Smart Way.
http://www.vogella.de/code/codeeclipse.html Source Code of Examples
Articles about Java, Eclipse and Webdevelopment from www.vogella.de
http://www.eclipse.org/rap Eclipse RAP homepage
http://wiki.eclipse.org/RAP Eclipse RAP Wiki
http://wiki.eclipse.org/RAP_Theming Eclipse RAP Theming Wiki
http://www.ibm.com/developerworks/opensource/library/os-eclipse-richajax2/ Eclipse RAP article Part from IBU