public void run(final boolean fork, boolean cancelable,
final IRunnableWithProgress runnable)
throws InvocationTargetException, InterruptedException {
try {
operationInProgress = true;
final StatusLineManager mgr = getStatusLineManager();
if (mgr == null) {
runnable.run(new NullProgressMonitor());
return;
}
boolean cancelWasEnabled = mgr.isCancelEnabled();
final Control contents = getContents();
final Display display = contents.getDisplay();
Shell shell = getShell();
boolean contentsWasEnabled = contents.getEnabled();
MenuManager manager = getMenuBarManager();
Menu menuBar = null;
if (manager != null) {
menuBar = manager.getMenu();
manager = null;
}
boolean menuBarWasEnabled = false;
if (menuBar != null) {
menuBarWasEnabled = menuBar.getEnabled();
}
Control toolbarControl = getToolBarControl();
boolean toolbarWasEnabled = false;
if (toolbarControl != null) {
toolbarWasEnabled = toolbarControl.getEnabled();
}
Control coolbarControl = getCoolBarControl();
boolean coolbarWasEnabled = false;
if (coolbarControl != null) {
coolbarWasEnabled = coolbarControl.getEnabled();
}
// Disable the rest of the shells on the current display
Shell[] shells = display.getShells();
boolean[] enabled = new boolean[shells.length];
for (int i = 0; i < shells.length; i++) {
Shell current = shells[i];
if (current == shell) {
continue;
}
if (current != null && !current.isDisposed()) {
enabled[i] = current.getEnabled();
current.setEnabled(false);
}
}
Control currentFocus = display.getFocusControl();
try {
contents.setEnabled(false);
if (menuBar != null) {
menuBar.setEnabled(false);
}
if (toolbarControl != null) {
toolbarControl.setEnabled(false);
}
if (coolbarControl != null) {
coolbarControl.setEnabled(false);
}
mgr.setCancelEnabled(cancelable);
final Exception[] holder = new Exception[1];
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
try {
ModalContext.run(runnable, fork, mgr
.getProgressMonitor(), display);
} catch (InvocationTargetException ite) {
holder[0] = ite;
} catch (InterruptedException ie) {
holder[0] = ie;
}
}
});
if (holder[0] != null) {
if (holder[0] instanceof InvocationTargetException) {
throw (InvocationTargetException) holder[0];
} else if (holder[0] instanceof InterruptedException) {
throw (InterruptedException) holder[0];
}
}
} finally {
operationInProgress = false;
// Enable the rest of the shells on the current display
for (int i = 0; i < shells.length; i++) {
Shell current = shells[i];
if (current == shell) {
continue;
}
if (current != null && !current.isDisposed()) {
current.setEnabled(enabled[i]);
}
}
if (!contents.isDisposed()) {
contents.setEnabled(contentsWasEnabled);
}
if (menuBar != null && !menuBar.isDisposed()) {
menuBar.setEnabled(menuBarWasEnabled);
}
if (toolbarControl != null && !toolbarControl.isDisposed()) {
toolbarControl.setEnabled(toolbarWasEnabled);
}
if (coolbarControl != null && !coolbarControl.isDisposed()) {
coolbarControl.setEnabled(coolbarWasEnabled);
}
mgr.setCancelEnabled(cancelWasEnabled);
if (currentFocus != null && !currentFocus.isDisposed()) {
// It's necessary to restore focus after reenabling the controls
// because disabling them causes focus to jump elsewhere.
// Use forceFocus rather than setFocus to avoid SWT's
// search for children which can take focus, so focus