/**
* @param runnable
*/
public static void runInBackgroundWithBusyIndicator(final Runnable runnable) {
final Display display = Display.getCurrent();
final Integer busyId = Integer.valueOf(nextBusyId++);
/* Guard against Illegal-Thread-Access */
if (display == null)
throw new IllegalStateException("Method was not called from the UI-Thread!"); //$NON-NLS-1$
/* Set the Cursor */
Cursor cursor = display.getSystemCursor(SWT.CURSOR_APPSTARTING);
Shell[] shells = display.getShells();
for (Shell shell : shells) {
Integer id = (Integer) shell.getData(BUSYID_NAME);
if (id == null) {
shell.setCursor(cursor);
shell.setData(BUSYID_NAME, busyId);
}
}
/* Run the Runnable and update cursor afterwards */
runUIUpdater(new UIBackgroundJob(null) {
@Override
protected void runInBackground(IProgressMonitor monitor) {
runnable.run();
}
@Override
protected void runInUI(IProgressMonitor monitor) {
if (!display.isDisposed()) {
Shell[] shells = display.getShells();
for (Shell shell : shells) {
Integer id = (Integer) shell.getData(BUSYID_NAME);
if (busyId.equals(id)) {
shell.setCursor(null);
shell.setData(BUSYID_NAME, null);