Eclipse icon

Resource Creation Wizards

Custom resource creation wizards are the best way to support the creation of resources using a process that you control. New file wizards allow you to control naming, location, and contents. New project wizards allow you to add natures, properties, and standard structures.

This example demonstrates the implementation of a new file wizard, with customized content. The com.ibm.lab.soln.resources plug-in has an example of a new project wizard.

The implementation of a resource wizard requires that you define an extension in your plug-in and provide an implementation of the extension. The plugin.xml defines two resource creation wizard extensions. The wizards contain a mix of custom wizard pages created from scratch and pages that build on basic file and folder creation wizard pages provided as part of Eclipse.

Running the Solution

To run the example, launch the run-time instance of Eclipse (Run > Run As > Run-time Workbench).

Usage scenarios for the two resource creation wizard examples are detailed below.

Simple Resource Creation Wizard with Multiple Pages

The first resource creation wizard demonstrates how wizard pages provided by Eclipse can be reused and the page progression control logic integrated into the wizard framework using the page complete status for each wizard page.

  1. Open the New wizard selection dialog (File > New > Other...) and select the entry titled Soln: My New Wizards, and then Soln: My Basic Wizard. This will start the resource creation wizard implemented by the MyBasicWizard class. The wizard page implemented by the MyBasicWizardPage1 class is shown as this page is the first added by the wizards addPages() method:

    This page is a customized version of the Eclipse new file page (see the MyNewFileWizardPage class). The input validation, such as the error shown based on a failed file name test, is provided by the WizardNewFileCreationPage class from Eclipse. By overriding the getInitialContents() method this page even provides initial content for the file.
    Once a valid file name has been entered, select Next to continue.

  2. The next page demonstrates the control logic available in a wizard. At first, the Next and Finish are not enabled. Only by selecting the checkbox can you change the page complete state of this page to true and thereby enable the Next button:

    This is an example of a control requiring user interaction before the page is complete. Your code could use any rule you wish to control the page complete status. This includes checking if data has been entered and if it is valid, or cross field validation to ensure that the data entered in different places is consistent.

    The Finish button is still not enabled because this example wizard hasn't yet collected all the information it needs in order to create the resource.

  3. Selecting Next will advance to the final page.


  4. This page also requires an interaction, so select one of the radio buttons. You can now select Finish to complete the wizard and create the file specified on the first page.

This example demonstrated the use of wizard pages provided as part of Eclipse and simple page control logic.

Using Dynamic Wizard Pages to Support Resource Creation

The second resource creation wizard demonstrates dynamic page content. That is, the wizard's addPages() method defines the initial page – all subsequent pages are determined by user interaction.

The purpose of this wizard is to allow you to create any number of folders or files through one wizard interaction. Beginning with the first page, the wizard control logic allows you to request what type of resource creation page you want to see next. After the first page, each time you move on to the next page the the resource creation request is processed. If you select Finish, the only processing left to perform is that shown on the current page.

This is an unorthodox wizard, but it does allow for a demonstration of dynamic page content.

  1. Open the New wizard selection dialog (File > New > Other...) and select the entry titled Soln: My New Wizards, and then Soln: My New Wizards. This will start the resource creation wizard implemented by the StructureWizard class. The first wizard page is implemented by the StructureInitPage class is shown:

    This is the only wizard page added by the wizard's addPages() method.

  2. Select the Create a folder option and then select Next. This will let the customized getNextPage() method add another page to the wizard.

    This is the page shown for the Create a folder option:

    The new folder wizard page implemented by the StructureNewFolderWizardPage class builds on the org.eclipse.ui.dialogs.WizardNewFolderMainPage class.

  3. Enter a valid folder name and a container (Project or other folder) where you would like to create the folder.

    Then select the Create another file option on the folder creation page. This identifies the page you want to see next.

    When you select Next the folder is created and then you will see the new file project structure page:

    You can even create a file in the folder added by the previous page, as the folder has already been created..

    This process can continue as long as you choose a file or folder page as the next page. You can change your mind if the type of page you have requested and then added by moving forward is not required. Either select Cancel button to quit (resources created on previous page will already have been created) or choose the Select to ignore this resource creation page toggle and choose an alternate page type to continue creating resources.

Roadmap to the Solution

This example includes two resource creation new wizard extensions that demonstrate wizard implementation techniques. The extension definitions can be found in the plugin.xml. The classes that implement these extensions and capabilities are shown below.

Extension / Object Implementation
My Basic Wizard
and Wizard Pages
This resource creation wizard is implemented by the MyBasicWizard class.

There are three wizard pages included in this basic wizard example:

Project Structure Wizard
and Wizard Pages
This resource creation wizard is implemented by the StructureWizard class.

There are three wizard pages included in the project structure wizard:

© Copyright International Business Machines Corporation, 2003.
All rights reserved.