I am writing a simple Eclipse-plugin that displays a UI after right-mouse click on a specific element, located inside an xml file. In the handler, i need to get first the file path, which contains the selected object. I tried the following posts unfortunately did not work for me.
How to get the Path of current selected file in Eclipse?
IFile file = (IFile) Platform.getAdapterManager().getAdapter(obj,
IFile.class);
Eclipse Plugin Get Code from Current Open File
IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor().getEditorInput().getAdapter(IFile.class);
note: the file need not be opened in active editor.