Suzan Cioc
Suzan Cioc

Reputation: 30097

How to create WizardPage correctly (Eclipse platform)

In the library code after creating page, the assertion check for control property occurs:

public void createPageControls(Composite pageContainer) {
        // the default behavior is to create all the pages controls
        for (int i = 0; i < pages.size(); i++) {
            IWizardPage page = (IWizardPage) pages.get(i);
            page.createControl(pageContainer);
            // page is responsible for ensuring the created control is
            // accessable
            // via getControl.
            Assert.isNotNull(page.getControl());
        }
    }

(last line)

So, while implementing WizardPage#createControl one should fill control with something.

In Vogella's sample he created intermediate Composite container and uses it: http://www.vogella.com/tutorials/EclipseWizards/article.html#wizards_example

But may I just use createContol's parent argument?

UPDATE

What if redefine WizardPage class and use it all times?

public abstract class WizardPageEx extends WizardPage {

    public WizardPageEx(String pageName, String title, ImageDescriptor titleImage) {
        super(pageName, title, titleImage);
    }

    public WizardPageEx(String pageName) {
        super(pageName);
    }

    @Override
    final public void createControl(Composite parent) {
        Composite control = new Composite(parent, SWT.NONE);
        createControlEx(control);
        setControl(control);
    }

    abstract public void createControlEx(Composite control);

}

what are disadvantages of such a decision?

Upvotes: 1

Views: 787

Answers (1)

greg-449
greg-449

Reputation: 111142

In WizardPage.createControl you must create some sort of Control - usually a Composite and you must call WizardPage.setControl(control) to tell WizardPage which is the top level control. So usually something like:

@Override
public void createControl(final Composite parent)
{
  final Composite composite = new Composite(parent, SWT.NULL);

  ...

  setControl(composite);
}

Upvotes: 3

Related Questions