问题: I created a Wizard that when finished, adds two files at the Project Explorer. One of them should be hidden, but when I press the Finish button at my wizard, Eclipse doesn't refresh the view automatically and it keeps showing the file. It just hide it when I press F5. There's a way to force it to refresh the Project Explorer, right after I finish the wizard?
大概就是说,Project Explorer没刷新。
回答: It sounds like you aren't using Eclipse resources API to make file system changes. You have two options:
听起来,哥们你没用Eclipse resources API啊,你有两个选择:
The best option is to use Eclipse resource API instead of java.io when working with contents of Eclipse projects. See org.eclipse.resources plugin. Start with ResourcesPlugin.getWorkspace().getRoot().getProject( "name" ). Use IProject, IFile and IFolder API.
最好的选择,是使用Eclipse resources API,代替java.io。看看org.eclipse.resources插件吧。以 ResourcesPlugin.getWorkspace().getRoot().getProject( "name" )开始,然后使用IProject, IFile and IFolder的API。
Alternatively, especially if your wizard is invoking code that isn't eclipse-aware, you need to invoke refresh after you are sure that all java.io based file system operations have been completed. Use refreshLocal() method, which is available on IProject, IFile and IFolder classes. For instance, the following snippet refreshes all contents of a given project. This is typically an overkill, so you will want to narrow down the scope as much as possible before invoking refresh.
还一个办法,就是确保你的io操作完成后,调用refreshLocal方法,它是IProject, IFile 和 IFolder的方法。 如下面的例子就是刷新指定project下的所有内容的。你也可以调用IFolder或IFile的refreshLocal方法,自己研究吧。
ResourcesPlugin.getWorkspace().getRoot().getProject( "proj" ).refreshLocal( IResource.DEPTH_INFINITE, new NullProgressMonitor() );
|