Differences between RWT and SWT
Introduction to the RAP Widget Toolkit
At the core of RAP operates the RAP Widget Toolkit (RWT), which largely implements the same
API as the Standard Widget Toolkit (SWT). That is why many projects that build upon SWT
(like JFace)
can run on RWT with little or no modifications. It can
also be used with or without the Eclipse 3.x
workbench layer.
Note that RWT
refers only to this widget toolkit, while RAP
refers to the
project in its entirety, including its ports of JFace, Workbench and Forms, OSGI
integration, add-ons, Branding and Interaction Design API, tooling, demos and custom themes.
RWT implements most (40+)
SWT Widgets, including their events and layout manager. It also supports SWT-like
key and mouse event handling, drag and drop and painting (on Canvas).
If you are not already familiar with SWT, we recommend to first learn the SWT basics
(almost all valid for RWT) by reading the official documentation
and snippets provided by the
SWT project homepage.
A full reference specific to RWT can be found
here.
Compatibility to SWT
RAP generally follows the rule If it compiles, it works
. That means that all SWT API
implemented in RWT is working within the requirements set by SWT.
If an SWT feature is not implemented, the corresponding API is also missing.
If this is the case, it is likely because it's hard or impossible to implement in RWT.
In some cases, SWT classes and methods are implemented as empty stubs to enable single-sourcing,
but only where this is a valid according of the SWT documentation of the API.
Examples are the accessibility API and some SWT constants that are marked as HINT.
SWT was developed for desktop applications, but RWT is used to build web applications.
For this reason, there are some features that SWT supports that RWT does not,
while RWT adds some features that are tailored to the specific requirements of web
application development.
However, RWT does not add any new API to the classes adopted from SWT.
All RWT-specific features are accessible by API in the namespace
org.eclipse.rap.rwt.
Many are activated using a
widget's
setData
method with a constant from the
RWT
class as the
key. Example:
table.setData( RWT.MARKUP_ENABLED, Boolean.TRUE )
Other additional features may be accessed via client services.
Notable Additional Features
-
Client Class and Client Services
All features specific to the RAP client (which is exchangeable)
are handled by the client class and the client services.
This includes support for browser history, JavaScript execution and retrieving the clients
time zone offset.
The Client
interface and client services are documented in more detail
here.
-
HTTP File Upload
Unlike SWT, RWT can not simply access the user's file system and read data from it.
As an alternative, the
FileUpload
widget can be used. The widget looks like a button, but when clicked will open the file picker
dialog of the user's browser.
After a file has been selected, it can programmatically be send to any HTTP server.
As of RAP 2.3 it is also possible to use any widget as a drop target for files dragged from
outside the browser (e.g. the Windows Explorer).
Important: These features only allow sending the file to a given
URL, they do not handle the receiving part.
If you require a complete solution for uploading and
opening the file in your application, consider using the
FileDialog
implementation based on the FileUpload widget.
-
Markup in Widgets
Several widgets in RWT support a subset of HTML in their text property.
Detailed information can be found here.
-
Tree and Table Enhancements
The RWT Tree and Table widgets provide a number of features not found in SWT.
This includes the possibility to exclude some columns from scrolling,
pre-caching of items, as well as support for templates, markup and advanced theming.
Find out more about it here.
-
DropDown Widget
The
DropDown
widget enables simple and efficient input assist for text fields.
It is basically a pop-up list that can be attached to any Text widget.
It behaves very similar to Combo, but does not automatically change the content of
the widget it is attached to.
Instead it fires selection events that may be used to modify the value of the Text widget
programatically.
A ready-to-use, enhanced auto-complete solution for text fields can be found in the
RAP Incubator.
The component is called
AutoSuggest
and uses the DropDown widget internally.
-
Theming
In SWT, the default visual representation of an widget is determined by the operating
system. In RAP this is done by the
theming
which can be adjusted by the developer using CSS.
-
Multi-User Environment
RAP operates in a multi-user environment and provides some additional API that helps
dealing with the consequences.
An detailed introduction can be found here.
-
Scripting
Since the RAP WebClient is JavaScript based you can also write event listeners in JavaScript
instead of Java. This may be used to implement features that require instantaneous user
feedback or rely heavily on key events. Read more about it in the
Scripting section.
Notable Limitations
-
Unimplemented Features
While the API for touch event handling and accessibility configuration is present in RWT,
it does not natively support either. This is a valid implementation according to the SWT
documentation. Accessibility in RAP may be achieved by
adding ARIA attributes though.
-
Unimplemented Widgets:
StyledText, Tracker, TaskBar, Tray
These widgets are currently not available in RWT. If you require a rich text editor in RAP,
take a look in the RAP Incubator and Wiki.
-
Painting Limitations
SWT can paint on any widget or image using a
GC,
while RAP only allows painting on the
Canvas
widget.
In some cases the
drawText,
drawString
and
drawImage
methods may disregard the drawing order and overlap elements that are drawn later.
Some methods are unimplemented, including copyArea,
setClipping, setTransform, setInterpolation,
setLineDash and setXORMode.
Performance and results of a drawing operations can differ depending on the browser.
It is possible to use the native HTML5 Canvas directly instead of the SWT GC using RWT
Scripting.
See also Self-Drawing custom widgets
.
-
Limitations in Dialogs:
Dialog,
ColorDialog,
FontDialog,
MessageBox
When using the
JEE compatibility mode,
opening a dialog does not block program execution.
To obtain their return value, a callback must be registered using the RWT-specific class
DialogUtil.
-
Limitations of the Browser widget
Since the
Browser
widget is based on the HTML iframe element, there are some restrictions.
Detailed information can be found here.
-
Limitations in Mouse and Key Events
See Mouse and Key Event Handling in RAP
.
-
Limitations in Verify and Modify Events:
Modify
and
Verify
events are not fired instantaneously, but with a small delay, possibly
combining a number of changes into one event. Also, the values of the
VerifyEvent
fields
text,
start
and
end
currently always report the entire text to have changed.
However, when using a ClientListener (written in JavaScript),
these limitations do not exist.
-
Limitations in Drag and Drop
In
DragSourceEvent,
the fields
image,
offsetX
and
offsetY
have no effect.
DropTargetEvents
may be omitted while the mouse cursor is still in motion. When dragging files from the
clients OS (to drop on a drop target with ClientFileTransfer), feedback effects
are not renderd, operation types (move/copy/link) are ignored, and no DragEnter /
DragOver / DragLeave events are fired.
-
Limitations when using background threads
See articles Session access from a background thread
and Server Push.