Sometimes I find the need to programmatically invoke an Eclipse wizard. I’ve been using various ways of doing so, but have finally ended up with a more generic function. This will search through all the wizard registries and try to find a wizard with the specified identifier. If found the wizard will be opened. The code is shown below:
public void openWizard(String id) {
// First see if this is a "new wizard".
IWizardDescriptor descriptor = PlatformUI.getWorkbench()
.getNewWizardRegistry().findWizard(id);
// If not check if it is an "import wizard".
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getImportWizardRegistry()
.findWizard(id);
}
// Or maybe an export wizard
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getExportWizardRegistry()
.findWizard(id);
}
try {
// Then if we have a wizard, open it.
if (descriptor != null) {
IWizard wizard = descriptor.createWizard();
WizardDialog wd = new WizardDialog(getStandardDisplay()
.getActiveShell(), wizard);
wd.setTitle(wizard.getWindowTitle());
wd.open();
}
} catch (CoreException e) {
e.printStackTrace();
}
}
I hope you’ll find this snippet useful.