Bug 53532

Summary: [Wizards] WizardsRegistryReader has Class Cast Exception in findWizard(String id)
Product: [Eclipse Project] Platform Reporter: Michael D. Elder <mdelder>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P4 CC: francisu
Version: 3.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Michael D. Elder CLA 2004-03-02 16:15:12 EST
We would like to request that
org.eclipse.ui.internal.registry.WizardsRegistryReader be made API (removed from
an internal package) and also that the Class Cast Exception which results
whenever you call findWizard(String id) be fixed. WizardsRegistryReader has only
one subclass in the base Platform,
org.eclipse.ui.internal.registry.NewWizardsRegistryReader, which overrides the
findWizard(String id), so it is not susceptible to the Class Cast Exception defect.

In our case, we are building a custom Navigator, and would like to provide ways
to re-use the Import/Export wizards specified through the standard Eclipse
extension points, but add these in a selective way to the context menus. If we
could re-use the above class (WizardsRegistryReader), it would provide a clean
implementation. We were able to do this with the NewWizardsRegistryReader. 

The problem we're running across is with the following method:

/**
 *	Returns the first wizard with a given id.
 */
public WorkbenchWizardElement findWizard(String id) {
	Object [] wizards = getWizardCollectionElements();
	for (int nX = 0; nX < wizards.length; nX ++) {
		WizardCollectionElement collection = (WizardCollectionElement)wizards[nX];
		WorkbenchWizardElement element = collection.findWizard(id,true);
		if (element != null)
			return element;
	}
	return null;
}

On "WizardCollectionElement collection = (WizardCollectionElement)wizards[nX];",
there is a Class Cast Exception because all of the elements in the array are
WorkbenchWizardElements. We corrected this in a subclass, by overriding the
method as follows:

	public WorkbenchWizardElement findWizard(String id) {
		if(id == null || id.length() == 0)
			return null;
		
		Object[] wizards = getWizardCollectionElements();
		for (int nX = 0; nX < wizards.length; nX++) {
//					WizardCollectionElement collection = (WizardCollectionElement) wizards[nX];
//					WorkbenchWizardElement element = collection.findWizard(id, true);
			WorkbenchWizardElement element = (WorkbenchWizardElement)wizards[nX];
			if(element != null && element.getID().equals(id)) 
				return element;
		}
		return null;
	}

Is there another way we should be reading these extension points? Any guidance
would be appreciated.  

Additionally, we would like to request a standard WizardShortcutAction like the
NewWizardShortcutAction. The NewWizardShortcutAction fails because it tries to
cast to INewWizard, which does not work (clearly) for Import/Export wizards.
Incidentally, changing the creation and cast of the INewWizard variable in the
NewWizardShortcutAction.run() to org.eclipse.ui.IWorkbenchWizard works fine, as
there are no actual dependencies on the INewWizard interface (given that the
interface defines no methods ;).
Comment 1 Debbie Wilson CLA 2004-03-03 10:08:21 EST
Which build of 3.0 are you referencing this code against?
Comment 2 Michael D. Elder CLA 2004-03-03 10:11:27 EST
Sorry for the oversite. We are currently building on 3.0 M7.
Comment 3 Tod Creasey CLA 2004-03-29 10:51:13 EST
Not for 3.0
Comment 4 Tod Creasey CLA 2004-06-28 11:27:27 EDT
Reopening now that 3.0 has shipped
Comment 5 Boris Bokowski CLA 2009-11-26 16:19:25 EST
Prakash is now responsible for watching bugs in the [Wizards] component area.
Comment 6 Eclipse Webmaster CLA 2019-09-06 15:37:37 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.