Bug 60227 [Progress] support for clients implementing IRunnableContext
Clients which implement IRunnableContext directly need some support so that they can also show the BlockedJobsDialog. These clients currently typically run an operation as follows (for example SearchDialog): ModalContext.run(runnable, fork, getProgressMonitor(), getShell().getDisplay ()); One idea is to provide them with a helper that creates a progress monitor that handles setBlocked by showing the BlockedJobsDialog. For example, IProgressService.getProgressMonitorFor(IProgressMonitor); The wrapper could be implemented as shown below. It could probably reuse some of the WorkbenchWizardBlockedHandler. Once this support is in place the WorkbenchWindow should leverage this support. public class BlockedJobsAwareProgressMonitor extends ProgressMonitorWrapper { private BlockedJobsDialog blockedDialog; private Shell shell; private String currentTask; protected BlockedJobsAwareProgressMonitor(Shell shell, IProgressMonitor monitor) { super(monitor); this.shell = shell; } public void clearBlocked() { if (blockedDialog == null) return; blockedDialog.close(); blockedDialog = null; } public void setBlocked(IStatus reason) { showBlocked(shell, this, reason, currentTask); } public void showBlocked(Shell parentShell, IProgressMonitor blockingMonitor, IStatus blockingStatus, String blockedName) { if (blockedName == null) blockedName = parentShell.getText(); blockedDialog = new BlockedJobsDialog(parentShell, blockingMonitor, blockingStatus); blockedDialog.setBlockedTaskName(blockedName); blockedDialog.open(); } public void beginTask(String name, int totalWork) { super.beginTask(name, totalWork); currentTask = name; } }
bundles/org.eclipse.jface/src/org/eclipse/jface/operation/AccumulatingProgressMonitor.java
* 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jface.operation;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IProgressMonitorWithBlocking;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ProgressMonitorWrapper;
import org.eclipse.swt.widgets.Display;
import org.eclipse.jface.util.Assert;
/**
 * A progress monitor that accumulates <code>worked</code> and <code>subtask</code> 
 * calls in the following way by wrapping a standard progress monitor:
 * <ul>
 * <li> When a <code>worked</code> or <code>subtask</code> call occurs the first time,
 *		the progress monitor posts a runnable into the asynchronous SWT event queue.
 * </li>
 * <li> Subsequent calls to <code>worked</code> or <code>subtask</code> do not post
 *		a new runnable as long as a previous runnable still exists in the SWT event
 *		queue. In this case, the progress monitor just updates the internal state of
 *		the runnable that waits in the SWT event queue for its execution. If no runnable
 *		exists, a new one is created and posted into the event queue.
 * </ul>
 * <p>
 * This class is internal to the framework; clients outside JFace should not
 * use this class.
 * </p>
 */
 class AccumulatingProgressMonitor extends ProgressMonitorWrapper {