Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[Dltk-dev] Possible bug in NewContainerWizardPage ?

Implementing a WizardPage that inherits from NewContainerWizardPage and have run into a bug (I think).

In NewContainerWizardPage#getInitialScriptElement, an attempt is made to retrieve an adapter for the initial IStructuredSelection:

protected IModelElement getInitialScriptElement(IStructuredSelection selection) {
         IModelElement scriptElement =
null ;

        // Check selection
        if (selection != null && !selection.isEmpty()) {
                 Object selectedElement = selection.getFirstElement();
                 // Check for adapters
                 if (selectedElement instanceof IAdaptable) {
                          IAdaptable adaptable = (IAdaptable) selectedElement;
                          scriptElement = (IModelElement) adaptable.getAdapter(IModelElement.
class );
                          ...

If the selection is a PackageFragment, which is certainly reasonable, then that last #getAdapter will always fail, since a PackageFragment is not a IModelElement.  Looks like the inteface was changed from IJavaElement to IModelElement when copied out of the JDT.  IJavaElement works as expected, since PackageFragment is an IJavaElement.

The result is that the scriptElement returned for a PackageFragment selection is wrong.

Afraid I am still not familiar enough with DLTK internals to propose a fix.

Thanks,
Gerald

Back to the top