Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

classes missing in Eclipse package, help

I want to do a small plugin with a single command which prints the current project name. The code fragment is a below:

    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

    IEditorPart editorPart = window.getActivePage().getActiveEditor();
    if (editorPart != null){
        IFileEditorInput input = (IFileEditorInput)editorPart.getEditorInput() ;
        IFile file = input.getFile();
        IProject activeProject = file.getProject();
        String activeProjectName = activeProject.getName();
        //... use activeProjectName 
    }

Problem: IFileEditorInput cannot be found(error msg: cannot be resolved to a type). I have import org.eclipse.ui.*; at the top of the file, but it doesn't work. Seems that IFileEditorInput is missing, but how I can find it?

Thank you very much!

like image 868
xiaolong Avatar asked Dec 28 '22 18:12

xiaolong


1 Answers

You need to add a dependency on the org.eclipse.ui.ide plug-in. IFileEditorInput lives in the org.eclipse.ui package, but not the plug-in of the same name, which is confusing. You can also avoid this type of confusion by using package dependencies rather than depending explicitly on certain plug-ins.

like image 183
Tom Crockett Avatar answered Jan 06 '23 14:01

Tom Crockett