The new Eclipse Rich AJAX Platform (RAP) is a server-side platform that multiple concurrent users can access via their browsers and Eclipse RCP developers can learn in no time.

by Riccardo Govoni

Nov 27, 2007

Page 3 of 4

Eclipse RAP Test Drive: A Simple ToDo List
This section walks you through writing a basic application to manage your ToDo lists with RAP. This sample will show how RAP stores user data are in different sessions, allowing for multiple concurrent users on the same application. (Refer to the downloadable source code for the full listings.)

Start by installing RAP. Be sure to follow the instructions shown on the RAP project site, as they contain some extra steps that you must take, such as defining the RAP target platform.

Next, start Eclipse and create a new plug-in project. Specify that you are not going to create an RCP application and choose "RAP application with a view" from the available RAP templates. When you complete the wizard, you will have a completely functional basic application. If you examine it closely, you will notice that it is 90 percent similar to an RCP application. The only difference is the application's starting point is org.eclipse.rwt.lifecycle.IentryPoint, as opposed to org.eclipse.equinox.app.Iapplication in the case of RCP.

Now modify the application to meet the sample application's needs. The ToDo items will have one of three possible statuses: incomplete, in progress, or complete. They all will be rendered as a list of push buttons. When a user clicks a button, the corresponding ToDo item moves from one status to the next. Therefore, define the Status enum as follows:

You can now run the application and test it with multiple concurrent browsers. As Figure 4 shows, each user has access only to his or her own ToDo list, without interfering with the others. You didn't have to implement anything specific for this to happen; RAP handles it all in the background with its session-management capabilities.

Figure 4. The ToDo List Application Accessed by Multiple Concurrent Browsers: Each user has access only to his or her own ToDo list, without interfering with the others.

Another Eclipse RAP Test Drive: An Online Newsticker
The second RAP example for you to experiment with is a newsticker: a simple view that will display news items as soon as they are published, one per line (see Figure 5).

Figure 5. The Newsticker Sample Application: Here's a simple view that displays news items as soon as they are published.

This example reveals another difference between RAP and RCP: server-side push events. RAP supports server-side generation of events, which updates the user interface and asynchronously pushes the events to the clients. You use the standard SWT method call Display.asyncexec() to dispatch such events, but you first have to inform RWT that you are going to use server-side generated events. You can do so using the org.eclipse.rwt.lifecycle.UICallback.activate() method (and its cousin UICallback.deactivate() when you're done).

This example focuses only on the code that triggers server-side events. The first thing you need to do is attach a listener to the button the user will click to start receiving events. The following listing shows an excerpt from the createPartControl() method of the application View, which performs just that:

Note that the code relies on UICallBack.activate(), since it is going to generate server-side push events. The notifierThread thread fetches events, and its behavior is defined in the createRunnable() method, shown here:

Remember to always use Display.asyncExec() when dealing with the user interface, otherwise the program will either behave erratically or raise exceptions.

As you can see, pushing events is quite easy in a RAP application, thanks to the underlying support from the SWT core. You can use server-side push for online chats or progress bars for long-running operations as well.