Eclipse plugin: find the location of the selected project

I am trying to find the location of a selected project in Eclipse via code from my editor plugin and have had some success. I couldn't find a project in one scenario. When a file using an editor is left open from the last session in Eclipse and Eclipse reopens, I cannot find the location of the current project without opening and closing the file, because this method: Eclipse Plugin: How to get the path to the currently selected project is not will work. Any suggestions? Thanks in advance.

+3


source to share


1 answer


Eclipse doesn't really have a "current project" concept. Each view has a current selection, but most views do not preserve the selection between sessions.

In the editor, you probably want the project the current file belongs to. In the editor, you can use something like:



IEditorInput editorInput = getEditorInput();

IFile file = (IFile)editorInput.getAdapter(IFile.class);

IProject project = file.getProject();

      

Note: file

may be empty if you are editing a file that is not in the workspace. You don't need to use the (IFile)

most recent versions of Eclipse.

+1


source







All Articles