Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "FAQ How do I run a lengthy process in a wizard?"

 
m
 
Line 1: Line 1:
The <tt>IWizardContainer</tt> passed to your wizard extends the interface called
+
The <tt>IWizardContainer</tt> passed to your wizard extends the interface called <tt>IRunnableContext</tt>.  This means that you can pass it an <tt>IRunnableWithProgress</tt> 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&#146;ll have to use <tt>Display.asyncExec</tt>.  The FAQ Examples plug-in includes a sample wizard, called <tt>AddingWizard</tt>, that computes the sum of two integers, using the wizard container&#146;s progress monitor:
<tt>IRunnableContext</tt>.  This means that you can pass it
+
an <tt>IRunnableWithProgress</tt> 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&#146;ll have
+
to use <tt>Display.asyncExec</tt>.  The FAQ Examples plug-in includes
+
a sample wizard, called <tt>AddingWizard</tt>, that computes
+
the sum of two integers, using the wizard container&#146;s progress monitor:
+
 
<pre>
 
<pre>
 
   getContainer().run(true, true, new IRunnableWithProgress() {
 
   getContainer().run(true, true, new IRunnableWithProgress() {
Line 24: Line 16:
 
</pre>
 
</pre>
  
 
+
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 <tt>needsProgressMonitor</tt> method on <tt>IWizard</tt> to return <tt>true</tt>.
 
+
 
+
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 <tt>needsProgressMonitor</tt> method on <tt>IWizard</tt>
+
to return <tt>true</tt>.
+
 
+
 
+
 
+
  
 
== See Also: ==
 
== See Also: ==
 
+
*[[FAQ How do I use progress monitors?]]
 
+
*[[FAQ Why do I get an invalid thread access exception?]]
[[FAQ_How_do_I_use_progress_monitors%3F]]
+
 
+
 
+
[[FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F]]
+
  
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>

Latest revision as of 12:56, 21 December 2006

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&#146;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&#146;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++) {
            monitor.subTask(Integer.toString(i));
            //sleep to simulate long running operation
            Thread.sleep(100);
            monitor.worked(1);
         }
         monitor.done();
      }
   });

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:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.

Back to the top