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 Runnable
instances inside the UI thread immediately, or .asyncExec()
for running them on the UI thread later. 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). The syncExec
and asyncExec
methods 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 a...