From fba5ecde71a72612a225c4f66f9b2e8ce8f8a9ab Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 7 Jan 2014 17:25:33 +0100 Subject: [PATCH] Cleanup (more common code extracted; dispose condition; wording) --- .../openapi/vfs/newvfs/RefreshProgress.java | 60 ++++++++----------- .../openapi/vfs/newvfs/RefreshQueueImpl.java | 11 ++-- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshProgress.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshProgress.java index cfe227d69d62..2400415f60d3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshProgress.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshProgress.java @@ -24,10 +24,9 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.wm.WindowManager; import com.intellij.openapi.wm.ex.StatusBarEx; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; -import javax.swing.*; - /** * @author max */ @@ -50,45 +49,38 @@ public class RefreshProgress extends ProgressIndicatorBase { @Override public void start() { super.start(); - //noinspection SSBasedInspection - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - multiplex(true); - } - }); + updateIndicators(true); } @Override public void stop() { super.stop(); - //noinspection SSBasedInspection - SwingUtilities.invokeLater(new Runnable() { - @Override + updateIndicators(false); + } + + private void updateIndicators(final boolean start) { + // wrapping in invokeLater here reduces the number of events posted to EDT in case of multiple IDE frames + UIUtil.invokeLaterIfNeeded(new Runnable() { public void run() { - multiplex(false); + if (ApplicationManager.getApplication().isDisposed()) return; + + WindowManager windowManager = WindowManager.getInstance(); + if (windowManager == null) return; + + Project[] projects = ProjectManager.getInstance().getOpenProjects(); + if (projects.length == 0) projects = NULL_ARRAY; + for (Project project : projects) { + StatusBarEx statusBar = (StatusBarEx)windowManager.getStatusBar(project); + if (statusBar != null) { + if (start) { + statusBar.startRefreshIndication(myMessage); + } + else { + statusBar.stopRefreshIndication(); + } + } + } } }); } - - private void multiplex(boolean start) { - if (ApplicationManager.getApplication().isDisposed()) return; - - WindowManager windowManager = WindowManager.getInstance(); - if (windowManager == null) return; - - Project[] projects = ProjectManager.getInstance().getOpenProjects(); - if (projects.length == 0) projects = NULL_ARRAY; - for (Project project : projects) { - StatusBarEx statusBar = (StatusBarEx)windowManager.getStatusBar(project); - if (statusBar != null) { - if (start) { - statusBar.startRefreshIndication(myMessage); - } - else { - statusBar.stopRefreshIndication(); - } - } - } - } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java index 1a49ff2b1bda..0b9cd8824067 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshQueueImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,8 +56,8 @@ public class RefreshQueueImpl extends RefreshQueue { } else { if (((ApplicationEx)app).holdsReadLock()) { - LOG.error("Do not call synchronous refresh from inside read action except for event dispatch thread. " + - "This will eventually cause deadlock if there are any events to fire"); + LOG.error("Do not call synchronous refresh under read lock (except from EDT) - " + + "this will cause a deadlock if there are any events to fire."); return; } queueSession(session, ModalityState.defaultModalityState()); @@ -82,14 +82,13 @@ public class RefreshQueueImpl extends RefreshQueue { } } finally { - final Application app = ApplicationManager.getApplication(); + Application app = ApplicationManager.getApplication(); app.invokeLater(new DumbAwareRunnable() { @Override public void run() { - if (app.isDisposed()) return; session.fireEvents(false); } - }, modality); + }, modality, app.getDisposed()); } } });