Reputation: 2408
I'm building an eclipse plugin in which I'm going to create a new file in my project. Is there a way to refresh the current project?
I know that I can have a reference to all the project by calling
ResourcesPlugin.getWorkspace().getRoot().getProjects()
And the iterate among them and use
IResource.refreshLocal()
However this approach is not the best one, especially if the user have a lot of projects.
An alternative would be explore the project for checking if the new file is present or not but I would avoid it.
Upvotes: 5
Views: 6590
Reputation: 9535
It's not neccessary to call refreshLocal
if you create the file with the workspace API, see org.eclipse.core.resources.IFile.create(InputStream, boolean, IProgressMonitor)
How to create a file, see the snippet in the Eclipse plugin: create a new file
Upvotes: 2
Reputation: 51565
It's a whole lot easier to refresh at the project level.
IProject project = root.getProject(currentProjectName);
project.refreshLocal(IResource.DEPTH_INFINITE, null);
True, this might be inefficient, but you're sure that the whole project is refreshed.
Upvotes: 4