## 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.

### 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. Clients can instantiate and configure the wizard page. To implement your own type wizard subclass NewTypeWizardPage. To simply open the original 'New Java Class wizard' use the OpenNewClassWizardAction.
- NewInterfaceWizardPage allows users to define a new Java interface. Clients can instantiate and configure the wizard page. To implement your own type wizard subclass NewTypeWizardPage. To simply open the original 'New Java Interface wizard' use the OpenNewInterfaceWizardAction.
- NewEnumWizardPage allows users to define a new Java enumeration. Clients can instantiate and configure the wizard page. To implement your own type wizard subclass NewTypeWizardPage. To simply open the original 'New Java Enum wizard' use the OpenNewEnumWizardAction.
- NewAnnotationWizardPage allows users to define a new Java annotations. Clients can instantiate and configure the wizard page. To implement your own type wizard subclass NewTypeWizardPage. To simply open the original 'New Java Annotation wizard' use the OpenNewAnnotationWizardAction.
- NewPackageWizardPage allows users to create a new Java package. Clients can instantiate and configure the wizard page. To simply open the original 'New Java Package wizard' use the OpenNewPackageWizardAction.
- NewJavaProjectWizardPageOne and NewJavaProjectWizardPageTwo allow users to create a new Java project wizard. Clients can use and configure these pages in their own project wizard. To simply open the original 'New Java Project wizard' use the OpenNewJavaProjectWizardAction

### 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 need additional information in your wizard page about the classpath's context when it is selected, you can implement IClasspathContainerPageExtension. If your configuration page wants to returns more than one entry when being added, implement IClasspathContainerPageExtension2.

### 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 tearDown() {}";
                newType.createMethod(tearDownMathod, null, false, null);
            }
       }
    }