AbstractExtensionWizardRegistry wizardRegistry = (AbstractExtensionWizardRegistry)WorkbenchPlugin.getDefault().getNewWizardRegistry();
IWizardCategory[] categories = WorkbenchPlugin.getDefault().getNewWizardRegistry().getRootCategory().getCategories();
for(IWizardDescriptor wizard : getAllWizards(categories)){
WorkbenchWizardElement wizardElement = (WorkbenchWizardElement) wizard;
if(!allowedWizard(wizardElement.getId())){
wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(), new Object[]{wizardElement});
}
}
getAllWizards() is a method where you want to collect all the wizards that may reside in any of the categories... categories are hierarhycal so must go down deep recursively after the wizards...
this did the job for me:
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]);
}
includeWizard():
once you have ALL the wizards at hand, you can make the choice to remove or leave them there. Here i remove all the wizards (and their cathegories except the basic and Task wizards)
protected static final List<String> FILE_NEW__ALLOWED_WIZARDS = Collections.unmodifiableList(Arrays.asList(new String[]{
"org.eclipse.mylyn.tasks.ui.wizards.new.category", // Tasks wizards
"org.eclipse.mylyn.tasks.ui.wizards.new.repository.task",// Tasks wizards
"org.eclipse.mylyn.tasks.ui.wizards.new.query",// Tasks wizards
"org.eclipse.ui.editors.wizards.UntitledTextFileWizard", // Basic wizards
"org.eclipse.ui.wizards.new.project",// Basic wizards
"org.eclipse.ui.wizards.new.folder",// Basic wizards
"org.eclipse.ui.wizards.new.file" // Basic wizards
}));
protected boolean allowedWizard(String wizardId) {
return FILE_NEW__ALLOWED_WIZARDS.contains(wizardId);
}