How to find which file is open in eclipse editor without using IEditorPart?

Posted by Destructor on Stack Overflow See other posts from Stack Overflow or by Destructor
Published on 2014-08-25T12:24:52Z Indexed on 2014/08/25 16:20 UTC
Read the original article Hit count: 211

Filed under:
|
|
|

I want to know which file (or even project is enough) is opened in eclipse editor? I know we can do this once we get IEditorPart from doSetInput method,

IFile file = ((IFileEditorInput) iEditorPart).getFile();

But I want the name of file without using IEditorPart, how can I do the same?
Checking which is the selected file in project explorer is not of much help because, user can select multiple files at once and open all simultaneously and I did not way to distinguish which file opened at what time.
Adding more info:
I have an editor specified for a particular type of file, now every time it opens, during intializing editor I have some operation to do based on project properties.
While initializing editor, I need the file handle (of the one which user opened/double clicked) or the corresponding project handle. I have my editor something this way:

public class MyEditor extends TextEditor{
    @Override
    protected void initializeEditor() {
        setSourceViewerConfiguration(new MySourceViewerConfiguration(
            CDTUITools.getColorManager(), store,
            "MyPartitions", this));
    }

    //other required methods

    @Override
    protected void doSetInput(IEditorInput input) throws CoreException {
        if(input instanceof IFileEditorInput)
        {
            IFile file = ((IFileEditorInput) input).getFile();
        }
    }
}

as I have done in the doSetInput() method , I want the file handle(even project handle is sufficient). But the problem is in initializeEditor() function there is no reference to editorInput, hence I am unable to get the file handle.
In the source viewer configuration file, I set the code scanners and this needs some project specific information that will set the corresponding rules.

© Stack Overflow or respective owner

Related posts about java

Related posts about eclipse