| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| <head> |
| <meta name="copyright" content= |
| "Copyright (c) IBM Corporation and others 2000, 2011. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." /> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| <meta http-equiv="Content-Style-Type" content="text/css" /> |
| <link rel="STYLESHEET" href="../book.css" charset="ISO-8859-1" type="text/css" /> |
| <title>Java wizard pages</title> |
| <link rel="stylesheet" type="text/css" href="../book.css" /> |
| </head> |
| <body> |
| <h2>Java wizard pages</h2> |
| <p>The <a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/package-summary.html"><b>org.eclipse.jdt.ui.wizards</b></a> |
| |
| package provides wizard pages for creating and configuring Java elements. Several |
| prefabricated pages are provided for your use.</p> |
| <h3 class="c1">Creating new Java elements</h3> |
| <p>A hierarchy of wizard pages support the creation of new Java elements. </p> |
| <p><a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewElementWizardPage.html"><b>NewElementWizardPage</b></a> |
| 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.</p> |
| <p>The concrete creation wizards can be used directly and generally are not intended to be |
| subclassed. </p> |
| <ul> |
| |
| <li><a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewClassWizardPage.html"><b>NewClassWizardPage</b></a> |
| allows users to define a new Java class. Clients can instantiate and configure the wizard page. To |
| implement your own type wizard subclass <a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewTypeWizardPage.html"><b>NewTypeWizardPage</b></a>. |
| To simply open the original 'New Java Class wizard' use the <a href= |
| "../reference/api/org/eclipse/jdt/ui/actions/OpenNewClassWizardAction.html"><b>OpenNewClassWizardAction</b></a>.</li> |
| <li><a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewInterfaceWizardPage.html"><b>NewInterfaceWizardPage</b></a> |
| allows users to define a new Java interface. Clients can instantiate and configure the wizard page. |
| To implement your own type wizard subclass <a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewTypeWizardPage.html"><b>NewTypeWizardPage</b></a>. |
| To simply open the original 'New Java Interface wizard' use the <a href= |
| "../reference/api/org/eclipse/jdt/ui/actions/OpenNewInterfaceWizardAction.html"><b>OpenNewInterfaceWizardAction</b></a>.</li> |
| <li><a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewEnumWizardPage.html"><b>NewEnumWizardPage</b></a> |
| |
| allows users to define a new Java enumeration. Clients can instantiate and configure the wizard |
| page. To implement your own type wizard subclass <a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewTypeWizardPage.html"><b>NewTypeWizardPage</b></a>. |
| To simply open the original 'New Java Enum wizard' use the <a href= |
| "../reference/api/org/eclipse/jdt/ui/actions/OpenNewEnumWizardAction.html"><b>OpenNewEnumWizardAction</b></a>.</li> |
| <li><a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewAnnotationWizardPage.html"><b>NewAnnotationWizardPage</b></a> |
| allows users to define a new Java annotations. Clients can instantiate and configure the wizard |
| page. To implement your own type wizard subclass <a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewTypeWizardPage.html"><b>NewTypeWizardPage</b></a>. |
| To simply open the original 'New Java Annotation wizard' use the <a href= |
| "../reference/api/org/eclipse/jdt/ui/actions/OpenNewAnnotationWizardAction.html"><b>OpenNewAnnotationWizardAction</b></a>.</li> |
| <li><a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewPackageWizardPage.html"><b>NewPackageWizardPage</b></a> |
| 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 <a href= |
| "../reference/api/org/eclipse/jdt/ui/actions/OpenNewPackageWizardAction.html"><b>OpenNewPackageWizardAction</b></a>.</li> |
| |
| <li><a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.html"><b>NewJavaProjectWizardPageOne</b></a> |
| and <a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageTwo.html"><b>NewJavaProjectWizardPageTwo</b></a> |
| 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 <a href= |
| "../reference/api/org/eclipse/jdt/ui/actions/OpenNewJavaProjectWizardAction.html"><b>OpenNewJavaProjectWizardAction</b></a></li> |
| </ul> |
| <h3>Contributing a classpath container wizard page</h3> |
| <p>The interface <a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/IClasspathContainerPage.html"><b>IClasspathContainerPage</b></a> |
| 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 <b><a href= |
| "../reference/extension-points/org_eclipse_jdt_core_classpathContainerInitializer.html">org.eclipse.jdt.core.classpathContainerInitializer</a></b> |
| |
| extension point, then you will probably want to define a corresponding wizard page for editing and |
| creating classpath containers of this type.</p> |
| <p>Your plug-in's markup should provide an extension <b><a href= |
| "../reference/extension-points/org_eclipse_jdt_ui_classpathContainerPage.html">org.eclipse.jdt.ui.classpathContainerPage</a>. </b> |
| In the extension markup, you provide the name of your class that implements <a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/IClasspathContainerPage.html"><b>IClasspathContainerPage</b></a>. |
| If you need additional information in your wizard page about the classpath's context when it is |
| selected, you can implement <a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/IClasspathContainerPageExtension.html"><b>IClasspathContainerPageExtension</b></a>. |
| If your configuration page wants to returns more than one entry when being added, implement |
| <a href="../reference/api/org/eclipse/jdt/ui/wizards/IClasspathContainerPageExtension.html"><b>IClasspathContainerPageExtension2</b></a>.</p> |
| <h3>Customizing a wizard page</h3> |
| |
| <p>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 |
| <a href= |
| "../reference/api/org/eclipse/jdt/ui/wizards/NewElementWizardPage.html"><b>NewElementWizardPage</b></a> |
| hierarchy to customize a wizard rather than subclassing the concrete classes.</p> |
| <p>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 <code>setUp()</code> and |
| <code>tearDown()</code> method are to be created.</p> |
| <pre class="color1"> |
| 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); |
| } |
| } |
| } |
| |
| </pre> |
| </body> |
| </html> |