Question

I have an eclipse JFace wizard with a single page (let's call this page1) which is added to the mainWizard using addPage(page1).

I wish to have a second page (page2), but this can only be created from a value determined from page1 (and so cannot be added to the mainWizard)

Is there a way I can add this from page1 to be create when I push its next button?

EDIT: Currently I have created the new page in page1, and then overridden getNextPage() as follows

@Override
public IWizardPage getNextPage() {
 if (page2 != null) {
  return page2;
 }
 System.err.println("page not populated");
 return null;
}

and although I don't get the "page not populated" message, when I press next I'm hit with a NullPointerException on WizardDialog.setWizard.

Was it helpful?

Solution 2

The typical approach when writing a JFace wizard is to extend Wizard class and add pages in the addPages() method. While that's convenient for many cases, you can choose to implement IWizard interface directly and have all the control you need over the creation and sequencing of pages.

OTHER TIPS

The org.eclipse.jface.wizard.Wizard has all that is needed to add pages dynamically at the end of the existing steps. You can do so by overriding getNextPage to return a new page if conditions are met:

@Override
public IWizardPage getNextPage() {
   IWizardPage nextPage = super.getNextPage(page);
   if (nextPage == null) {
      if (userInputRequiresMorePage){
         // The user input is such that we need an additional page to append to the wizard.
         IWizardPage nextPage = new MyAdditionalPage();
      }
   }
   return nextPage;
}

If your wizard start with only one page, "back" and "next" buttons do not appear by default. As you may need more steps, you want to display them. You can do so by setting the proper flag using the API

public void org.eclipse.jface.wizard.Wizard.setForcePreviousAndNextButtons(boolean b)

You can create a second page which just has a composite and call addPage for that in the wizard addPages.

In the second page override the setVisible(boolean) method and create the controls you need when the page becomes visible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top