I’m trying to develop a plugin that will render the elements of an XML file in a tree view and (on double-click) is supposed to open the file in an editor. The file in question is a plugin resource.
Most of the examples I’ve seen get the file as an IFile from selection (the selected element); my problem is I can’t find a way to provide that input otherwise.
Here is a couple of example of what I’ve already tried:
IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject("the plugin project");
IFile file = testProject.getFile("test.xml");
and
IWorkspace workspace= ResourcesPlugin.getWorkspace();
IPath location= new Path(relative path); // local to the project directory
IFile file= workspace.getRoot().getFileForLocation(location);
Somehow the file I’m looking for is not found.
I’ve managed to render the tree by reading the file from a stream provided by:
MyClass.class.getResourceAsStream(relativePath);
I could get the Url to the file (using getResource()) but I don’t know if I can use it to get the IFile I need.
Please advise.
You say
locationis relative to the project directory, however you are trying to resolve it using workspace.getRoot().getFileForLocation(), whose JavaDoc says,