Part 1: RAP 2.1 and Client Scripting
The ClientScripting project also received a bigger update in time for the upcoming Kepler release. Though optimized for RAP 2.1, it’s not an official part of the release, hence “Phase II”. Support for the RAP 1.5 and 2.0 releases continues in their respective streams, but will not include any of the new features.
Previously, ClientListeners were registered with their slightly unfamiliar
addTo method. Now they implement the SWT
Listener interface and can be added to a widget like any other untyped listener:
text.addListener( SWT.Verify, new ClientListener( script ) );
Hint: Creating multiple equal
ClientListener instances is currently not optimized, so “recycle” if you can. For example…
textOne.addListener( SWT.Verify, new ClientListener( script ) ); textTwo.addListener( SWT.Verify, new ClientListener( script ) );
…transfers the script code to the client twice, while…
ClientListener listener = new ClientListener( script ); textOne.addListener( SWT.Verify, listener ); textTwo.addListener( SWT.Verify, listener );
…does it only once.
More Supported Event Types
ClientListener can now also be used to listen to
Hide events on any
Control, while support for the
Paint events has been added to the
Canvas widgets respectively. Paint events can be triggered by calling
canvas.redraw() on the client or on the server, and the listener can then use a subset of the HTML5-Canvas API to draw. (Here is a code example.)
While the widget-objects in ClientScripting have most of the setters of their Java-counterparts, only a few getters are available. New for Kepler are
List#getSelection(). This makes the list widget pretty useable with ClientScripting.
… I will tell you how to pass data to a ClientListener.