下面列出了怎么用org.eclipse.ui.wizards.IWizardDescriptor的API类实例代码及写法,或者点击链接到github查看源代码。
public void openWizard(String id) {
IWizardDescriptor descriptor = PlatformUI.getWorkbench()
.getNewWizardRegistry().findWizard(id);
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getImportWizardRegistry()
.findWizard(id);
}
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getExportWizardRegistry()
.findWizard(id);
}
try {
if (descriptor != null) {
IWizard wizard = descriptor.createWizard();
WizardDialog wd = new WizardDialog(Display.getDefault()
.getActiveShell(), wizard);
wd.setTitle(wizard.getWindowTitle());
wd.open();
}
} catch (CoreException e) {
e.printStackTrace();
}
}
static void run() {
final List<IWizardCategory> cats = new ArrayList<>();
AbstractExtensionWizardRegistry r =
(AbstractExtensionWizardRegistry) PlatformUI.getWorkbench().getNewWizardRegistry();
cats.addAll(Arrays.asList(r.getRootCategory().getCategories()));
r = (AbstractExtensionWizardRegistry) PlatformUI.getWorkbench().getImportWizardRegistry();
cats.addAll(Arrays.asList(r.getRootCategory().getCategories()));
r = (AbstractExtensionWizardRegistry) PlatformUI.getWorkbench().getExportWizardRegistry();
cats.addAll(Arrays.asList(r.getRootCategory().getCategories()));
for (final IWizardDescriptor wizard : getAllWizards(cats.toArray(new IWizardCategory[0]))) {
final String id = wizard.getCategory().getId();
if (CATEGORIES_TO_REMOVE.contains(id) || IDS_TO_REMOVE.contains(wizard.getId())) {
// DEBUG.LOG("Removing wizard " + wizard.getId() +
// " in category " + id);
final WorkbenchWizardElement element = (WorkbenchWizardElement) wizard;
r.removeExtension(element.getConfigurationElement().getDeclaringExtension(),
new Object[] { element });
}
}
}
public static void openWizard(final String id, final IStructuredSelection selection) {
// 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) {
final IWorkbenchWizard wizard = descriptor.createWizard();
wizard.init(PlatformUI.getWorkbench(), selection);
final WizardDialog wd = new WizardDialog(WorkbenchHelper.getDisplay().getActiveShell(), wizard);
wd.setTitle(wizard.getWindowTitle());
wd.open();
}
} catch (final CoreException e) {
e.printStackTrace();
}
}
/**
* Opens the wizard with the given id and passes it the selection.
*
* @param wizardId
* The wizard id of the eclipse newWizard registry
* @param selection
* The selection
*/
private void openWizardForModule(String wizardId, IStructuredSelection selection, boolean nested) {
// Retrieve wizard from registry
IWizardDescriptor wizardDescriptor = PlatformUI.getWorkbench().getNewWizardRegistry().findWizard(wizardId);
if (wizardDescriptor == null) {
return;
}
try {
IWorkbenchWizard wizard = wizardDescriptor.createWizard();
// Inject wizard members
injector.injectMembers(wizard);
// Create and open a new wizard dialog
WizardDialog wizardDialog = new WizardDialog(UIUtils.getShell(), wizard);
// If the wizard supports it, enable in module option
if (wizard instanceof N4JSNewClassifierWizard<?>) {
((N4JSNewClassifierWizard<?>) wizard).init(PlatformUI.getWorkbench(), selection, nested);
} else {
// Otherwise just pass it the initial selection
wizard.init(PlatformUI.getWorkbench(), selection);
}
// wizardDialog.setTitle(wizard.getWindowTitle());
wizardDialog.open();
} catch (CoreException e) {
/** Failed to create the wizard */
Shell workbenchShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MessageDialog.open(MessageDialog.ERROR, workbenchShell, "Failed to launch wizard",
String.format("Failed to launch wizard %s", wizardId), SWT.SHEET);
return;
}
}
public static void openWizard(String wizardId, Shell parentShell, ISelection selection) {
// First see if this is a "new wizard".
IWizardDescriptor descriptor = PlatformUI.getWorkbench().getNewWizardRegistry().findWizard(wizardId);
// If not check if it is an "import wizard".
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getImportWizardRegistry().findWizard(wizardId);
}
// Or maybe an export wizard
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getExportWizardRegistry().findWizard(wizardId);
}
try {
// Then if we have a wizard, open it.
if (descriptor != null) {
IWizard wizard = descriptor.createWizard();
if (wizard instanceof IWorkbenchWizard) {
IStructuredSelection structuredSelection = selection instanceof IStructuredSelection? (IStructuredSelection)selection : new StructuredSelection();
((IWorkbenchWizard)wizard).init(PlatformUI.getWorkbench(), structuredSelection);
WizardDialog wd = new WizardDialog(parentShell, wizard);
wd.setTitle(wizard.getWindowTitle());
wd.open();
}
else {
Assert.isTrue(false, "Attempt to call not IWorkbenchWizard"); //$NON-NLS-1$
}
}
} catch (CoreException e) {
e.printStackTrace();
}
}
static private IWizardDescriptor[] getAllWizards(final IWizardCategory[] categories) {
final List<IWizardDescriptor> results = new ArrayList<>();
for (final IWizardCategory wizardCategory : categories) {
results.addAll(Arrays.asList(wizardCategory.getWizards()));
results.addAll(Arrays.asList(getAllWizards(wizardCategory.getCategories())));
}
return results.toArray(new IWizardDescriptor[0]);
}
private IWizardDescriptor[] getAllWizards(IWizardCategory... categories) {
List<IWizardDescriptor> results = new ArrayList<IWizardDescriptor>();
for (IWizardCategory wizardCategory : categories) {
results.addAll(Arrays.asList(wizardCategory.getWizards()));
results.addAll(Arrays.asList(getAllWizards(wizardCategory.getCategories())));
}
return results.toArray(new IWizardDescriptor[0]);
}
private IWizardDescriptor[] getAllWizards(IWizardCategory... categories) {
List<IWizardDescriptor> results = new ArrayList<IWizardDescriptor>();
for (IWizardCategory wizardCategory : categories) {
results.addAll(Arrays.asList(wizardCategory.getWizards()));
results.addAll(Arrays.asList(getAllWizards(wizardCategory.getCategories())));
}
return results.toArray(new IWizardDescriptor[0]);
}