Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » How to use the progress monitor with a custom wizard
icon5.gif  How to use the progress monitor with a custom wizard [message #903398] Thu, 23 August 2012 09:33 Go to next message
Gary Long is currently offline Gary Long
Messages: 3
Registered: August 2012
Junior Member
Hello Smile

I created a custom WizardDialog and a custom Wizard. The problem is that I can't find how to activate the progress monitor available in the wizard. I set the needsProgressMonitor to true but it doesn't show when I start the wizard dialog :

My code is :

ImpactGenerationWizard wizard = new ImpactGenerationWizard();
wizard.setWindowTitle(wizardTitle);
wizard.setHelpAvailable(false);
wizard.addPages(impacts);
wizard.setNeedsProgressMonitor(true);

ImpactGenerationWizardDialog wd = new ImpactGenerationWizardDialog(shell, wizard);				
wd.open();


I read something about using the wd.run(fork, cancelable, runnable) but I don't really understand how it works.

Any help will be appreciated.

Thank you Smile
Re: How to use the progress monitor with a custom wizard [message #903484 is a reply to message #903398] Thu, 23 August 2012 15:59 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten Schlathölter
Messages: 208
Registered: February 2012
Location: Düsseldorf
Senior Member
Hi Gary,
its as simple as that. Use the wd.run() method to execute the code that needs the progress indicator. As soon as you begin the using the IProgressMonitor, the bar will become visible.


Here is a very simple example:

Wizard testWizard = new Wizard() {
			
   @Override
   public boolean performFinish() {
      return false;
   }
};

WizardPage page = new WizardPage("name","title",null) {
		
   @Override
   public void createControl(Composite arg0) {
      Button button = new Button(arg0, SWT.PUSH);
      setControl(button);
      button.setText("press me");
      button.addSelectionListener(new SelectionListener() {
					
      @Override
      public void widgetSelected(SelectionEvent arg0) {
         try {
	   getContainer().run(true, true, new IRunnableWithProgress() {
								
		@Override
		public void run(IProgressMonitor arg0) 
                    throws InvocationTargetException,
			InterruptedException {
		   int amount = 10;
		   arg0.beginTask("Task1", 10);
		   for (int i=0; i<amount;i++)
		   {
			arg0.internalWorked(1);
			Thread.sleep(2000);
		         if (arg0.isCanceled())
			{
			   break;
			}
      	 	   }
		}
	   });
	}
	catch (Exception e)
	{
	   e.printStackTrace();
	}
       }
						
       @Override
       public void widgetDefaultSelected(SelectionEvent arg0) {
       }
   });
}
};

testWizard.setNeedsProgressMonitor(true);
testWizard.addPage(page);
WizardDialog dialog = new WizardDialog(null, testWizard);
dialog.open();

[Updated on: Thu, 23 August 2012 16:04]

Report message to a moderator

Re: How to use the progress monitor with a custom wizard [message #903542 is a reply to message #903484] Fri, 24 August 2012 04:29 Go to previous messageGo to next message
Gary Long is currently offline Gary Long
Messages: 3
Registered: August 2012
Junior Member
Thank you for your answer Smile

I would like to use it to monitor the progress of all pages of the wizard. Is it possible to configure the ProgressMonitor to increment each time the next button of the wizard dialog is pressed?
Re: How to use the progress monitor with a custom wizard [message #903849 is a reply to message #903542] Sun, 26 August 2012 08:26 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten Schlathölter
Messages: 208
Registered: February 2012
Location: Düsseldorf
Senior Member
Hi Gary,
the standard progress monitor functionality of WizardDialog is not intended for that purpose. In fact as soon as you start a run() operation via the WizardDialog, all wizard controls are disabled until the run() method has been completed. So you wouldn't even be able to press the next button. To accomplish the above requirement you have to manage the progress control yourself.

Here is a simple example which might already suit your needs:

 package org.eclipse.swt.snippets;
   			
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.ProgressMonitorPart;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Snippet {

   private class ProgressWizardPage extends WizardPage
   {
      public ProgressWizardPage(String pageName) {
         super(pageName);
      }
      
      @Override
      public void createControl(Composite arg0) {
         Button button = new Button(arg0, SWT.PUSH);
         setControl(button);
         button.setText(getName()+":  simple page control");
      }
   }
   
   private class ProgressWizardDialog extends WizardDialog
   {
      ProgressMonitorPart part;
      
      int pageCount = 1;
      public ProgressWizardDialog(Shell parentShell, IWizard newWizard) {
         super(parentShell, newWizard);
      }

      @Override
      protected ProgressMonitorPart createProgressMonitorPart(
            Composite composite, GridLayout pmlayout) {
         part = super.createProgressMonitorPart(composite, pmlayout);
         return part;
      }
      
      @Override
      protected void nextPressed() {
         super.nextPressed();
         pageCount++;
         updateWizardProgress();
      }

      @Override
      protected void backPressed() {
         super.backPressed();
         pageCount--;
         updateWizardProgress();
      }
      
      private void updateWizardProgress() {
         getShell().getDisplay().asyncExec(new Runnable() {
            @Override
            public void run() {
               getProgressMonitor().beginTask("Completion: ", getWizard().getPageCount());
               getProgressMonitor().worked(pageCount);
            }
         });
      }

      @Override
      protected Control createContents(Composite parent) {
         Control ret = super.createContents(parent);
         
         part.setVisible(true);
         updateWizardProgress();
         
         return ret;
      }
      
   };
   
   public static void main(String[] args) {
      new Snippet().run();
   }
   
   public void run()
   {
      Display display = new Display();

      final Wizard testWizard = new Wizard() {

         @Override
         public boolean performFinish() {
            return false;
         }
      };
      
      testWizard.setNeedsProgressMonitor(true);
      
      for (int i=0;i<15;i++)
      {
         testWizard.addPage(new ProgressWizardPage("page"+i));   
      }
      
      ProgressWizardDialog dialog = new ProgressWizardDialog(null, testWizard);
      dialog.open();

      display.dispose();
   }
}

Re: How to use the progress monitor with a custom wizard [message #903914 is a reply to message #903398] Mon, 27 August 2012 05:02 Go to previous message
Gary Long is currently offline Gary Long
Messages: 3
Registered: August 2012
Junior Member
Thank you for your help Smile
It helped me a lot ^^

Previous Topic:WizardPage depend of previous WizardPages
Next Topic:Treeviewer expander gives false indication
Goto Forum:
  


Current Time: Tue Jul 29 04:45:45 EDT 2014

Powered by FUDForum. Page generated in 0.02618 seconds