## Java wizard pages

The org.eclipse.jdt.ui.wizards package provides wizard pages for creating and configuring Java elements. Several prefabricated pages are provided for your use.

### Configuring Java build settings

JavaCapabilityConfigurationPage supports editing the Java build settings (source folder setup, referenced projects and, referenced and exported libraries).

If you need to provide a wizard that configures a project for your plug-in while also configuring it with the Java nature and other Java project capabilities, you should use this page (rather than subclassing NewJavaProjectWizardPage).

### Creating new Java elements

A hierarchy of wizard pages support the creation of new Java elements.

NewElementWizardPage is the abstract class that defines the basic operation of the wizard. Additional abstract classes are provided in the hierarchy for making customizations to the functionality provided by the concrete wizards.

The concrete creation wizards can be used directly and generally are not intended to be subclassed.

- NewClassWizardPage allows users to define a new Java class. To customize the behavior for this wizard, you should subclass NewTypeWizardPage.
- NewInterfaceWizardPage allows users to define a new Java interface. To customize the behavior for this wizard, you should subclass NewTypeWizardPage.
- NewJavaProjectWizardPage allows users to create a new Java project. To create a different kind of project with Java capabilities, you should use JavaCapabilityConfigurationPage where possible rather than subclassing this class.
- NewPackageWizardPage allows users to create a new Java package. To customize the behavior for this wizard, you should subclass NewContainerWizardPage rather than this class.

### Contributing a classpath container wizard page

The interface IClasspathContainerPage defines a structure for contributing a wizard page that allows a user to define a new classpath container entry or edit an existing one. If your plug-in has defined its own type of classpath container using the JDT Core org.eclipse.jdt.core.classpathContainerInitializer extension point, then you will probably want to define a corresponding wizard page for editing and creating classpath containers of this type.

Your plug-in's markup should provide an extension org.eclipse.jdt.ui.classpathContainerPage. In the extension markup, you provide the name of your class that implements IClasspathContainerPage. If you want to provide additional information in your wizard page about a classpath's context when it is selected, you can implement IClasspathContainerPageExtension to initialize any state that depends on the entries selected in the current classpath.

### Customizing a wizard page

Besides using prefabricated pages, you can subclass the wizard pages to add your own input fields or to influence the code generation. You should use the abstract classes in the NewElementWizardPage hierarchy to customize a wizard rather than subclassing the concrete classes.

Below is a sample of a new type wizard page that is customized to create JUnit test case classes. The page initializes the super class field with "junit.framework.TestCase" and adds a checkbox that controls whether method stubs for the `setUp()` and `tearDown()` method are to be created.

    public class TestCaseWizardPage extends NewTypeWizardPage {
        private Button fCreateStubs;

        public TestCaseWizardPage() {
            super(true, "TestCaseWizardPage");
        }

        /**
         * The wizard managing this wizard page must call this method
         * during initialization with a corresponding selection.
         */
        public void init(IStructuredSelection selection) {
            IJavaElement jelem= getInitialJavaElement(selection);
            initContainerPage(jelem);
            initTypePage(jelem);
            doStatusUpdate();
        }

        private void doStatusUpdate() {
            // define the components for which a status is desired
            IStatus[] status= new IStatus[] {
                fContainerStatus,
                isEnclosingTypeSelected() ? fEnclosingTypeStatus : fPackageStatus,
                fTypeNameStatus,
            };
            updateStatus(status);
        }

        protected void handleFieldChanged(String fieldName) {
            super.handleFieldChanged(fieldName);

            doStatusUpdate();
        }

        public void createControl(Composite parent) {
            initializeDialogUnits(parent);
            Composite composite= new Composite(parent, SWT.NONE);
            int nColumns= 4;
            GridLayout layout= new GridLayout();
            layout.numColumns= nColumns;
            composite.setLayout(layout);

            // Create the standard input fields
            createContainerControls(composite, nColumns);
            createPackageControls(composite, nColumns);
            createSeparator(composite, nColumns);
            createTypeNameControls(composite, nColumns);
            createSuperClassControls(composite, nColumns);

            // Create the checkbox controlling whether we want stubs
            fCreateStubs= new Button(composite, SWT.CHECK);
            fCreateStubs.setText("Add 'setUp()' and 'tearDown()' to new class");
            GridData gd= new GridData();
            gd.horizontalSpan= nColumns;
            fCreateStubs.setLayoutData(gd);

            setControl(composite);

            // Initialize the super type field and mark it as read-only
            setSuperClass("junit.framework.TestCase", false);
        }

        protected void createTypeMembers(IType newType, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
            if (fCreateStubs.getSelection()) {
                String setUpMathod= "public void setUp() {}";
                newType.createMethod(setUpMathod, null, false, null);

                String tearDownMathod= "public void setUp() {}"
                newType.createMethod(tearDownMathod, null, false, null);
            }
       }
    }