How to write a Wizard

From Bioclipse
Jump to: navigation, search
Development tutorial
Responsible author:Ola
Bioclipse version:N/A
"N/A" is not a number.
Last updated:2009-10-10
Tags:


General Wizard

A wizard should implement IWizard but usually extends Wizard:

 public class MossWizard extends Wizard {

   ...
 }

Useful methods to override:

@Override
public void addPages() {
  page1=new MyWizardPage();
  addPage(page1);
}
@Override
public boolean performFinish() {
 ..
}
@Override
public boolean performCancel() {
 ..
}
@Override
public boolean canFinish() {
 ..
}
@Override
public boolean canFinish() {
 ..
}

I recommend to use the super().canFinish (= do not override) which checks if all individual pages are complete.

WizardPage

A WizardPage must implement IWizardPage but usually extends WizardPage.

You must provide the method:

 public void createControl(Composite parent) {
 //Create GUI controls here
 }

Some tips to call in wizardpage:

  • getWizard() gives you the parent wizard for the page.
  • setErrorMessage("My ErrorMessage") - this sets an error message for the page and indicates that page is not complete.
  • setPageComplete(false)
  • setTitle(String)
  • setMessage(String)

Some methods that are convenient to override:

@Override
public boolean canFlipToNextPage() {
 ..
}
@Override
public IWizardPage getNextPage() {
 ..
}

I recommend to create a method that can be called from listeners on GUI objects:

public void checkForCompletion(){
 setErrorMessage(null);
 setPageComplete(false);
  
 if (checkSomething()==false){
  setErrorMessage("Incomplete");
  setPageComplete(false);
 }
 
 getWizard().getContainer().updateButtons();

}


NewProjectWizard

Use the following structure for this:

public class NewQSARProjectWizard extends Wizard implements INewWizard {
  
    public void addPages(){
       fFirstPage = new WizardNewProjectCreationPage("New XYZ project");
       addPage(fFirstPage);
    }

 }

Create the project in the performFinish(). See net.bioclipse.qsar.wizards.NewQSARProjectWizard for example.

Links for more information:

Links