1818import java .lang .reflect .InvocationTargetException ;
1919import java .net .URI ;
2020import java .util .ArrayList ;
21- import java .util .Collections ;
22- import java .util .Iterator ;
2321import java .util .List ;
2422
2523import org .eclipse .core .filesystem .IFileInfo ;
2624import org .eclipse .core .filesystem .IFileStore ;
2725import org .eclipse .core .resources .IProject ;
2826import org .eclipse .core .resources .IResource ;
29- import org .eclipse .core .resources .IResourceRuleFactory ;
3027import org .eclipse .core .resources .IWorkspaceRoot ;
3128import org .eclipse .core .resources .ResourcesPlugin ;
3229import org .eclipse .core .resources .WorkspaceJob ;
3734import org .eclipse .core .runtime .Status ;
3835import org .eclipse .core .runtime .SubMonitor ;
3936import org .eclipse .core .runtime .jobs .ISchedulingRule ;
40- import org .eclipse .core .runtime .jobs .Job ;
4137import org .eclipse .core .runtime .jobs .MultiRule ;
4238import org .eclipse .jface .dialogs .IDialogConstants ;
4339import org .eclipse .jface .dialogs .MessageDialog ;
5147import org .eclipse .swt .widgets .Shell ;
5248import org .eclipse .ui .PlatformUI ;
5349import org .eclipse .ui .internal .ide .IDEWorkbenchMessages ;
50+ import org .eclipse .ui .internal .ide .IDEWorkbenchPlugin ;
5451import org .eclipse .ui .internal .ide .IIDEHelpContextIds ;
5552import org .eclipse .ui .internal .ide .StatusUtil ;
5653import org .eclipse .ui .internal .ide .dialogs .IDEResourceInfoUtils ;
@@ -225,19 +222,30 @@ final protected IRunnableWithProgress createOperation(final IStatus[] errorStatu
225222 }
226223 final List <? extends IResource > resources = actionResources ;
227224
228- return new IRunnableWithProgress () {
225+ ISchedulingRule rule = null ;
226+ for (IResource resource : resources ) {
227+ ISchedulingRule newRule = null ;
228+ if (resource .getType () == IResource .ROOT ) {
229+ newRule = resource ;
230+ } else {
231+ newRule = resource .getProject ();
232+ }
233+ rule = MultiRule .combine (rule , newRule );
234+ }
235+
236+ return new WorkspaceModifyOperation (rule ) {
229237 @ Override
230- public void run (IProgressMonitor mon ) {
231- SubMonitor subMonitor = SubMonitor .convert (mon );
238+ public void execute (IProgressMonitor mon ) {
239+ SubMonitor subMonitor = SubMonitor .convert (mon , resources . size () );
232240 subMonitor .setTaskName (getOperationMessage ());
233- List <IStatus > errors = Collections . synchronizedList ( new ArrayList <>() );
234- resources . parallelStream (). forEach ( resource -> {
241+ List <IStatus > errors = new ArrayList <>();
242+ for ( IResource resource : resources ) {
235243 try {
236- refreshResource (resource , null );
244+ refreshResource (resource , subMonitor . split ( 1 ) );
237245 } catch (CoreException e ) {
238246 errors .add (e .getStatus ());
239247 }
240- });
248+ }
241249
242250 if (!errors .isEmpty ()) {
243251 MultiStatus multiStatus = new MultiStatus (IDEWorkbenchPlugin .IDE_WORKBENCH , IStatus .ERROR ,
@@ -287,10 +295,10 @@ public void run() {
287295 final IStatus [] errorStatus = new IStatus [1 ];
288296 errorStatus [0 ] = Status .OK_STATUS ;
289297 final IRunnableWithProgress op = createOperation (errorStatus );
290- Job job = new Job ("refresh" ) { //$NON-NLS-1$
298+ WorkspaceJob job = new WorkspaceJob ("refresh" ) { //$NON-NLS-1$
291299
292300 @ Override
293- public IStatus run (IProgressMonitor monitor ) {
301+ public IStatus runInWorkspace (IProgressMonitor monitor ) throws CoreException {
294302 try {
295303 op .run (monitor );
296304 } catch (InvocationTargetException e ) {
@@ -304,6 +312,9 @@ public IStatus run(IProgressMonitor monitor) {
304312 }
305313
306314 };
315+ if (op instanceof WorkspaceModifyOperation ) {
316+ job .setRule (((WorkspaceModifyOperation ) op ).getRule ());
317+ }
307318 job .setUser (true );
308319 job .schedule ();
309320 }
0 commit comments