FAQ How do I run a lengthy process in a wizard?

From Eclipsepedia

Jump to: navigation, search

The IWizardContainer passed to your wizard extends the interface called IRunnableContext. This means that you can pass it an IRunnableWithProgress and that it will give progress feedback to the user while it runs. Keep in mind that as with all long-running operations, the container will generally fork a different thread to run your operation. If you want to manipulate any widgets from the operation, you’ll have to use Display.asyncExec. The FAQ Examples plug-in includes a sample wizard, called AddingWizard, that computes the sum of two integers, using the wizard container’s progress monitor:

   getContainer().run(true, true, new IRunnableWithProgress() {
      public void run(IProgressMonitor monitor) {
         int sum = n1 + n2;
         monitor.beginTask("Computing sum: ", sum);
         for (int i = 0; i < sum; i++) {
            //sleep to simulate long running operation

Your wizard can specify whether it needs a progress bar or a simple busy cursor. For operations that may take more than a second, you should use a progress bar. This is done by implementing needsProgressMonitor method on IWizard to return true.

See Also:
