Search code examples
javaeclipsepde

Eclipse plugin doesn't work in CDT


i have implemented an eclipse plug-in that runs very well in the test workbench, Eclipse IDE for PHP Developers and Eclipse IDE for JavaDevelopers but doesn't work in Eclipse CDT. There is no error messages, so i dont't know, why.

My plug-in adds a popup menu entry and executes an action. I notices the plug-in stops after this line:

 IFile file = (IFile) ((IStructuredSelection) wbw.getSelectionService().getSelection()).getFirstElement();

All IDEs run on kubuntu 14.04.


Solution

  • The selection returned by the selection service is often a user interface object rather than an IFile. You need to use the IAdapterManager to adapt this object to a file.

    Object selected = ((IStructuredSelection) wbw.getSelectionService().getSelection()).getFirstElement();
    
    IAdapterManager manager = Platform.getAdapterManager();
    
    IFile file = (IFile)manager.getAdapter(selected, IFile.class);