Eclipse Plugins Exposed, Part 3: Customizing a Wizard
Pages: 1, 2, 3, 4, 5, 6
Lifecycle Methods
These methods should be overridden to insert initialization and destruction code into our wizard.
- Constructor: Called when the wizard is instantiated, but before Eclipse passes it any information. Implement for general initialization of the wizard. Usually you want to call the "beautification methods" (see below) and to set the dialog's defaults.
init(IWorkbench workbench, IStructuredSelection editorSelection): Called by Eclipse to provide the wizard with information about the workbench. Override to keep a handle toIWorkbenchand object for later. If this were an editor wizard instead of a new wizard, we'd receive as the second parameter the current editor selection, as well.dispose(): Called by Eclipse to clean up. Override to clean up resources used by the wizard.finalize(): For cleanup code, prefer usingdispose()instead.
Beautification Methods
These methods are used to decorate the wizard window.
setWindowTitle(String title): Call to provide the string that appears in title bar.setDefaultPageImageDescriptor(ImageDescriptor image): Call to provide the graphic that appears in the top right of the wizard on all pages.setTitleBarColor(RGB color): Call to specify what color to use in the title bar.
Button Methods
These methods control the availability and behavior of the wizard's buttons.
boolean canFinish(): Override to indicate if the Finish button should be enabled or not, according to the wizard's state.boolean performFinish(): Override to implement the wizard's ultimate business logic. Return false if the wizard can't finish (error condition).boolean performCancel(): Override to clean up after a user clicks on the Cancel button. Return false if the wizard can't cancel.boolean isHelpAvailable(): Override to indicate if the Help button should be visible or not.boolean needsPreviousAndNextButtons(): Override to specify if the Previous and Next buttons should be visible or not.boolean needsProgressMonitor(): Override to indicate if a progress monitor widget should be visible. This appears when clicking the Finish button while theperformFinish()method is called.
Page Methods
These methods control the appearance of pages.
addPages(): Called when the wizard appears. Override to insert new pages into the wizard.createPageControls(Composite pageContainer): Called by Eclipse to instantiate all of the wizard's pages (already added byaddPages()above). Override to add always-visible widgets (other than the pages) to the wizard.IWizardPage getStartingPage(): Override to determine what should be the first page of the wizard.IWizardPage getNextPage(IWizardPage nextPage): By default, clicking Next goes to the next page in the array provided inaddPages(). You may want to go to a different page based on the user's selection. Override to calculate the next page.IWizardPage getPreviousPage(IWizardPage previousPage): Similar togetNextPage(), used to calculate the previous page.int getPageCount(): Retrieves the number of pages that were added inaddPages(). You typically don't need to override this, except when you want to display the page count, and it varies.
Other Useful Methods
These are useful helper methods:
setDialogSettings(IDialogSettings settings): You can load the state of the dialog and publish this data by calling this method ininit(). Typically, the settings in question are the default values for the wizard's fields. See the classDialogSettingsfor more information.IDialogSettings getDialogSettings(): Once the data is needed, call this method to retrieve it. At the end of the dialog inperformFinish(), you can save the data to file again.IWizardContainer getContainer(): Useful to retrieve theShell, running background threads, refreshing the window, etc.