Sometimes it is necessary to write code to run in the UI thread, but when called back via a handler it's not always clear if the method is in the UI thread or not. In Eclipse 3.x there is a Display.getDefault().syncExec()
for running Runnables
inside the UI thread, or .asyncExec()
for a non-UI thread. Eclipse 4 introduces the UISynchronize
class, which is an abstract mechanism for executing code on the UI thread. (It's like an interface for Display
, except that Display
doesn't implement it and it's not an interface.) This provides syncExec()
and asyncExec()
methods which can be used to schedule Runnable
events. If a long calculation needs to update the UI after concluding, using UISynchronize
allows the UI update to be scheduled on the right thread.
Create a new
Button
as a field in theHello
part, and attach a selection listener such that when it is pressed, it invokessetEnabled(false)
on itself. At the same time, schedule aJob
to run after one...