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.
To refresh all projects in a workspace, simply enumerate all projects using ResourcesPlugin. getWorkspace(). getRoot(). getProjects() API and refresh each in turn.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With