diff options
author | Tor Norbye <tnorbye@google.com> | 2014-09-04 13:25:33 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2014-09-04 13:25:33 -0700 |
commit | d245f58efbfc26b13b9b9d5e52e6a83a0d76216c (patch) | |
tree | bca7d49005d81d10c70bc3f547df041c636b4300 /java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java | |
parent | 9cde0e3c015174898df8b8f3672185941fad4786 (diff) | |
parent | c3d3a90f6b4ead083d63e28e6b9fcea93d675678 (diff) | |
download | idea-d245f58efbfc26b13b9b9d5e52e6a83a0d76216c.tar.gz |
Merge remote-tracking branch 'aosp/upstream-master' into merge
Diffstat (limited to 'java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java')
-rw-r--r-- | java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java | 102 |
1 files changed, 58 insertions, 44 deletions
diff --git a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java index f568f2d06364..2f9f023bc52a 100644 --- a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java +++ b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java @@ -22,12 +22,11 @@ package com.intellij.compiler.progress; import com.intellij.compiler.CompilerManagerImpl; -import com.intellij.compiler.CompilerMessageImpl; import com.intellij.compiler.impl.CompilerErrorTreeView; import com.intellij.ide.errorTreeView.NewErrorTreeViewPanel; import com.intellij.ide.errorTreeView.impl.ErrorTreeViewConfiguration; import com.intellij.ide.impl.ProjectUtil; -import com.intellij.openapi.application.Application; +import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.compiler.*; @@ -42,6 +41,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ProjectManagerListener; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; @@ -120,6 +120,26 @@ public class CompilerTask extends Task.Backgroundable { mySessionId = sessionId; } + @NotNull + public Object getContentId() { + return myContentId; + } + + public void registerCloseAction(final Runnable onClose) { + synchronized (myMessageViewLock) { + if (myErrorTreeView != null) { + Disposer.register(myErrorTreeView, new Disposable() { + @Override + public void dispose() { + onClose.run(); + } + }); + return; + } + } + onClose.run(); + } + @Override public String getProcessId() { return "compilation"; @@ -221,13 +241,15 @@ public class CompilerTask extends Task.Backgroundable { private void addIndicatorDelegate() { ProgressIndicator indicator = myIndicator; - if (!(indicator instanceof ProgressIndicatorEx)) return; + if (!(indicator instanceof ProgressIndicatorEx)) { + return; + } ((ProgressIndicatorEx)indicator).addStateDelegate(new ProgressIndicatorBase() { @Override public void cancel() { super.cancel(); - closeUI(); + selectFirstMessage(); stopAppIconProgress(); } @@ -235,11 +257,26 @@ public class CompilerTask extends Task.Backgroundable { public void stop() { super.stop(); if (!isCanceled()) { - closeUI(); + selectFirstMessage(); } stopAppIconProgress(); } + private void selectFirstMessage() { + if (!isHeadlessMode()) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + synchronized (myMessageViewLock) { + if (myErrorTreeView != null) { + myErrorTreeView.selectFirstMessage(); + } + } + } + }); + } + } + private void stopAppIconProgress() { UIUtil.invokeLaterIfNeeded(new Runnable() { @Override @@ -249,7 +286,8 @@ public class CompilerTask extends Task.Backgroundable { if (myErrorCount > 0) { appIcon.setErrorBadge(myProject, String.valueOf(myErrorCount)); appIcon.requestAttention(myProject, true); - } else if (!myCompilationStartedAutomatically) { + } + else if (!myCompilationStartedAutomatically) { appIcon.setOkBadge(myProject, true); appIcon.requestAttention(myProject, false); } @@ -450,18 +488,22 @@ public class CompilerTask extends Task.Backgroundable { public void showCompilerContent() { synchronized (myMessageViewLock) { if (myErrorTreeView != null) { - final MessageView messageView = MessageView.SERVICE.getInstance(myProject); - Content[] contents = messageView.getContentManager().getContents(); - for (Content content : contents) { - if (CONTENT_ID_KEY.get(content) == myContentId) { - messageView.getContentManager().setSelectedContent(content); - return; - } - } + showCompilerContent(myProject, myContentId); } } } + public static boolean showCompilerContent(final Project project, final Object contentId) { + final MessageView messageView = MessageView.SERVICE.getInstance(project); + for (Content content : messageView.getContentManager().getContents()) { + if (CONTENT_ID_KEY.get(content) == contentId) { + messageView.getContentManager().setSelectedContent(content); + return true; + } + } + return false; + } + private void removeAllContents(Project project, Content notRemove) { if (project.isDisposed()) { return; @@ -488,7 +530,7 @@ public class CompilerTask extends Task.Backgroundable { private void activateMessageView() { synchronized (myMessageViewLock) { - if (myErrorTreeView != null) { + if (myErrorTreeView != null && myProject != null) { final ToolWindow tw = ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.MESSAGES_WINDOW); if (tw != null) { tw.activate(null, false); @@ -497,34 +539,6 @@ public class CompilerTask extends Task.Backgroundable { } } - private void closeUI() { - if (isHeadlessMode()) { - return; - } - Window window = getWindow(); - ModalityState modalityState = window != null ? ModalityState.stateForComponent(window) : ModalityState.NON_MODAL; - final Application application = ApplicationManager.getApplication(); - application.invokeLater(new Runnable() { - @Override - public void run() { - synchronized (myMessageViewLock) { - if (myErrorTreeView != null) { - final boolean shouldRetainView = myErrorCount > 0 || myWarningCount > 0 && !myErrorTreeView.isHideWarnings(); - if (shouldRetainView) { - addMessage(new CompilerMessageImpl(myProject, CompilerMessageCategory.STATISTICS, CompilerBundle.message("statistics.error.count", myErrorCount))); - addMessage(new CompilerMessageImpl(myProject, CompilerMessageCategory.STATISTICS, CompilerBundle.message("statistics.warnings.count", myWarningCount))); - //activateMessageView(); - myErrorTreeView.selectFirstMessage(); - } - else { - removeAllContents(myProject, null); - } - } - } - } - }, modalityState); - } - public Window getWindow(){ return null; } @@ -607,7 +621,7 @@ public class CompilerTask extends Task.Backgroundable { if (event.getContent() == myContent) { synchronized (myMessageViewLock) { if (myErrorTreeView != null) { - myErrorTreeView.dispose(); + Disposer.dispose(myErrorTreeView); myErrorTreeView = null; if (myIndicator.isRunning()) { cancel(); |