we need to get the the current display object in RAP 2.3 from inside a job for updating the UI. what is the suggested way to do that?
Asked
Active
Viewed 173 times
1 Answers
1
The Threads in RAP articles gives a thorough explanation about how threads and sessions interrelate in RAP.
To gain access to the Display from a Job, the Job needs to know which Display it is assigned to. Hence you need to pass the Displya to the Job. If the Job is scheduled from the UI thread, typical code may look like this:
static class DisplayJob extends Job {
private final Display display;
private DisplayJob( Display display ) {
super( "Job with UI Access" );
this.display = display;
}
@Override
protected IStatus run( IProgressMonitor monitor ) {
display.asyncExec( new Runnable() {
@Override
public void run() {
}
} );
return Status.OK_STATUS;
}
}
Button button = new Button( ...
button.addListener( SWT.Selection, new Listener() {
@Override
public void handleEvent( Event event ) {
new DisplayJob( event.display ).schedule();;
}
} );
Don't forget to check if the widgets aren't disposed before accessing them in the run()
method given to asyncExec()
- or use a helper therefore.
Note that the thread/session relation isn't specific to RAP but applies to all multi-user environments that have the concept of a session.

Rüdiger Herrmann
- 20,512
- 11
- 62
- 79
-
Thank you for your answer. I thought we could store the current display to session i.e RWT.getUISession().setAttribute("display", display); and use it later from inside the job. but it seems not possible. – Sharif Feb 10 '15 at 09:32