Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: how to refresh the current project programmatically

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.

like image 561
Maverik Avatar asked Mar 07 '12 14:03

Maverik


People also ask

How do you refresh a project programmatically in eclipse?

To refresh all projects in a workspace, simply enumerate all projects using ResourcesPlugin. getWorkspace(). getRoot(). getProjects() API and refresh each in turn.


2 Answers

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.

like image 56
Gilbert Le Blanc Avatar answered Sep 27 '22 18:09

Gilbert Le Blanc


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

like image 23
Tom Seidel Avatar answered Sep 27 '22 20:09

Tom Seidel