我们在开发Eclipse RCP时,有时会想创建打开指定的向导的快捷方式,下面说一下利用Eclipse提供的API实现该功能。
创建向导的处理:
IWizardDescriptor wizardDesc = WorkbenchPlugin.getDefault()
.getNewWizardRegistry().findWizard(wizardId); //$NON-NLS-1$
if (wizardDesc != null) {
NewWizardShortcutAction shortcutAction = new NewWizardShortcutAction(
PlatformUI.getWorkbench().getActiveWorkbenchWindow(),
wizardDesc);
shortcutAction.run();
}
导入向导的处理:
IWizardDescriptor wizardDesc = PlatformUI
.getWorkbench()
.getImportWizardRegistry()
.findWizard("org.eclipse.ui.wizards.import.ExternalProject");
if (wizardDesc != null) {
ImportExportWizard wizard = new ImportExportWizard(
ImportExportWizard.IMPORT);
wizard.init(PlatformUI.getWorkbench(),
StructuredSelection.EMPTY);
IDialogSettings workbenchSettings = WorkbenchPlugin
.getDefault().getDialogSettings();
IDialogSettings wizardSettings = workbenchSettings
.getSection("ImportExportAction"); //$NON-NLS-1$
if (wizardSettings == null) {
wizardSettings = workbenchSettings
.addNewSection("ImportExportAction"); //$NON-NLS-1$
}
wizard.setDialogSettings(wizardSettings);
wizard.setForcePreviousAndNextButtons(true);
final WizardDialog dialog = new WizardDialog(
UIUtils.getActiveShell(), wizard);
try {
dialog.create();
IWorkbenchWizard iwizard = wizardDesc.createWizard();
iwizard.addPages();
dialog.showPage(iwizard.getStartingPage());
dialog.open();
} catch (CoreException e) {
e.printStackTrace();
}
}