blob: 543423d38915ca19bb2b29f74e19b58edebb0c9a [file] [log] [blame]
<div>
<h3>Heads up: Webkit bug, affects Chrome, Safari and Opera</h3>
<p>
Recently, a <a href="https://bugs.webkit.org/show_bug.cgi?id=125070">bug</a> has been introduced
in WebKit that leads to RAP UIs becoming partly invisible when a Canvas widget is included.
This problem also affects earlier versions of RAP running in recent WebKit-based browsers.
A workaround is outlined in <?=bug(428717)?>, but didn't make it into this milestone.
We're confident to include it in M3. For older versions of RAP, please visit the
<a href="https://wiki.eclipse.org/RAP/FAQ#Widgets_disappearing_in_Google_Chrome.2C_Safari_or_Opera">FAQ</a>
for workarounds that you can apply yourself.
</p>
<h3>Drag&amp;Drop Support for Client Files</h3>
<p>
You can now allow users to upload files from their desktop by dropping them onto a widget.
To do so, you use the SWT Drag&amp;Drop API with the transfer type
<code>ClientFileTransfer</code>.
The following example shows how to enable a Label to accept files:
</p>
<pre lang="java">
Label dropLabel = new Label( parent, SWT.BORDER );
dropLabel.setText( &quot;Drop files here&quot; );
DropTarget dropTarget = new DropTarget( dropLabel, DND.DROP_MOVE );
dropTarget.setTransfer( new Transfer[]{ ClientFileTransfer.getInstance() } );
dropTarget.addDropListener( new DropTargetAdapter() {
@Override
public void drop( DropTargetEvent event ) {
filesDropped( (ClientFile[])event.data );
}
} );
</pre>
<p>
The <code>event.data</code> field will contain an array of <code>ClientFile</code>s, that
provide information on the dropped files.
It's an array because the user can also select and drag multiple files.
To actually upload the dropped files, the new client service <code>ClientFileUploader</code>
can be used:
</p>
<pre>
ClientFileUploader uploader = RWT.getClient().getService( ClientFileUploader.class );
uploader.submit( uploadUrl, clientFiles );
</pre>
<p>
Finally, you have to accept and store the files on the server.
The fileupload component in the <a href="http://eclipse.org/rap/incubator/">RAP Incubator</a>
can be used to handle uploads in RAP easily.
The <code>FileDialog</code>, also in the RAP Incubator, now also accepts dropped files.
</p>
<h3>New API for Singletons</h3>
<p>
We already provide the class <em>SingletonUtil</em> to facilitate the conversion of classic
singletons to UISession-scoped singletons for use in RAP's multi-user environment.
This class has a new method named <em>getUniqueInstance</em> that accepts a UISession instance
as a parameter. You can obtain a unique instance of a given class for the current UISession like so:
</p>
<pre lang="java">
public static MySingleton getInstance() {
UISession uiSession = RWT.getUISession();
return SingletonUtil.getUniqueInstance( MySingleton.class, uiSession );
}
</pre>
<p>
In this case, the method is equivalent to the existing method <code>getSessionInstance()</code>.
However, with the additional parameter, it allows you to obtain the singleton instance
for a given UISession <em>even from another thread</em> without having to wrap your code
in a runnable and pass it to <code>uiSession.exec()</code>.
To prepare your singleton for access from background threads, you may consider adding a
parameter to the getInstance method as shown below.
This pattern also allows for better unit tests.
</p>
<pre lang="java">
private static MySingleton getInstance( UISession uiSession ) {
return SingletonUtil.getUniqueInstance( MySingleton.class, uiSession );
}
</pre>
<p>
The old method <code>getSessionInstance()</code> still exists and delegates to the new one,
so you should be able to adjust your code using an “Inline Method” refactoring.
</p>
<h3>Support for Application Singletons</h3>
<p>
Similar to UISession singletons, you can now also create singletons with application scope.
Whenever you run multiple RAP applications in a single VM, there may be classes in a shared
bundle that should have exactly one instance per application.
</p>
<pre lang="java">
ApplicationContext context = RWT.getApplicationContext();
SingletonUtil.getUniqueInstance( MySingleton.class, applicationContext );
</pre>
</div>