|
Eclipse Rich Ajax Platform | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.eclipse.rwt.lifecycle.UICallBack
public final class UICallBack
A utility class that provides methods to perform tasks related to UI updates from background threads.
| Method Summary | |
|---|---|
static void |
activate(java.lang.String id)
Call this method to enable UI updates from background threads (e.g. |
static void |
deactivate(java.lang.String id)
This method deactivates a previously activated UI callback
with the same id. |
static void |
runNonUIThreadWithFakeContext(Display display,
java.lang.Runnable runnable)
Sometimes a background thread needs to access values that are stored in the session object that started the thread. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void runNonUIThreadWithFakeContext(Display display,
java.lang.Runnable runnable)
display - The display that is bound to the session that contains the
data to which the current thread should get access.runnable - The runnable that contains the critical code that
needs to have access to a request context.SessionSingletonBase,
org.eclipse.rwt.internal.service.ContextProviderpublic static void activate(java.lang.String id)
Display.asyncExec()}.
The UI callback must be activated from the UI thread before the background thread starts.
Each activation is given a session-unique id to allow reference-counting activation and
deactivation.
If not deactivated explicitly, any active UI callbacks are released when the session terminates.
Note: this method must only be called from the UI-Thread of an RWT application.
Example code:
final String callbackId = "callback id";
Runnable bgRunnable = new Runnable() {
public void run() {
// do some work...
// schedule the UI update
display.asyncExec( new Runnable() {
public void run() {
if( !widget.isDisposed() ) {
// update the UI
}
}
} );
// Deactivate the UI call-back
UICallBack.runNonUIThreadWithFakeContext( display, new Runnable() {
public void run() {
UICallBack.deactivate( callbackId );
}
} );
}
};
UICallBack.activate( callbackId );
Thread bgThread = new Thread( bgRunnable );
bgThread.setDaemon( true );
bgThread.start();
id - a session unique identifier to trace the activation and
deactivation. Must not be null.
SWTException - nullDisplay.syncExec(java.lang.Runnable),
Display.asyncExec(java.lang.Runnable),
Display.getThread(),
Display.wake()public static void deactivate(java.lang.String id)
activated UI callback
with the same id.
Calling this method with an id that wasn't activated before has no effect.
For each id, the system maintains a reference counter so that multiple activations of the same id must be followed by the same number deactivations in oder to actually stop the UI callback.
Note: this method must only be called from code that is associated with a session.
That is, either code running in the UI thread or executed via
runNonUIThreadWithFakeContext(Display, Runnable)
id - A session unique identifier to trace the activation and
deactivation. Must not be null
SWTException - nullDisplay.syncExec(java.lang.Runnable),
Display.asyncExec(java.lang.Runnable),
Display.getThread(),
Display.wake()
|
Eclipse Rich Ajax Platform | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Copyright (c) EclipseSource and others 2002, 2012. All rights reserved.