From f3259b8405b95ee3a3b951df2707b471561d808d Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 6 Apr 2017 22:33:12 +0200 Subject: [PATCH] add ProgressIndicatorListener#installToProgress and deprecate ProgressWindowWithNotification --- .../JavaWithRuntimeCastSurrounder.java | 4 ++-- .../engine/DebuggerManagerThreadImpl.java | 10 ++++++++-- .../debugger/engine/JavaValueModifier.java | 4 ++-- .../ui/breakpoints/MethodBreakpoint.java | 10 +++++----- .../util/ProgressIndicatorListener.java | 18 ++++++++++++++++++ .../util/ProgressWindowWithNotification.java | 17 +++-------------- 6 files changed, 38 insertions(+), 25 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/codeinsight/JavaWithRuntimeCastSurrounder.java b/java/debugger/impl/src/com/intellij/debugger/codeinsight/JavaWithRuntimeCastSurrounder.java index 730a0d7241bd..06312d385d56 100644 --- a/java/debugger/impl/src/com/intellij/debugger/codeinsight/JavaWithRuntimeCastSurrounder.java +++ b/java/debugger/impl/src/com/intellij/debugger/codeinsight/JavaWithRuntimeCastSurrounder.java @@ -28,7 +28,7 @@ import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.util.ProgressWindowWithNotification; +import com.intellij.openapi.progress.util.ProgressWindow; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; @@ -63,7 +63,7 @@ public class JavaWithRuntimeCastSurrounder extends JavaExpressionSurrounder { DebuggerContextImpl debuggerContext = (DebuggerManagerEx.getInstanceEx(project)).getContext(); DebuggerSession debuggerSession = debuggerContext.getDebuggerSession(); if (debuggerSession != null) { - final ProgressWindowWithNotification progressWindow = new ProgressWindowWithNotification(true, expr.getProject()); + final ProgressWindow progressWindow = new ProgressWindow(true, expr.getProject()); SurroundWithCastWorker worker = new SurroundWithCastWorker(editor, expr, debuggerContext, progressWindow); progressWindow.setTitle(DebuggerBundle.message("title.evaluating")); debuggerContext.getDebugProcess().getManagerThread().startProgress(worker, progressWindow); diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebuggerManagerThreadImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebuggerManagerThreadImpl.java index 514f2622316a..55b308317020 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebuggerManagerThreadImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebuggerManagerThreadImpl.java @@ -26,6 +26,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.util.ProgressIndicatorListenerAdapter; +import com.intellij.openapi.progress.util.ProgressWindow; import com.intellij.openapi.progress.util.ProgressWindowWithNotification; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; @@ -160,13 +161,18 @@ public class DebuggerManagerThreadImpl extends InvokeAndWaitThread ProgressManager.getInstance().runProcess(() -> invokeAndWait(command), progressWindow)); diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/JavaValueModifier.java b/java/debugger/impl/src/com/intellij/debugger/engine/JavaValueModifier.java index dc1cbdd76922..fd37398eed70 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/JavaValueModifier.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/JavaValueModifier.java @@ -27,7 +27,7 @@ import com.intellij.debugger.impl.DebuggerContextImpl; import com.intellij.debugger.impl.DebuggerSession; import com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl; import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl; -import com.intellij.openapi.progress.util.ProgressWindowWithNotification; +import com.intellij.openapi.progress.util.ProgressWindow; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; @@ -197,7 +197,7 @@ public abstract class JavaValueModifier extends XValueModifier { } protected void set(@NotNull final String expression, final XModificationCallback callback, final DebuggerContextImpl debuggerContext, final SetValueRunnable setValueRunnable) { - final ProgressWindowWithNotification progressWindow = new ProgressWindowWithNotification(true, debuggerContext.getProject()); + final ProgressWindow progressWindow = new ProgressWindow(true, debuggerContext.getProject()); final EvaluationContextImpl evaluationContext = myJavaValue.getEvaluationContext(); SuspendContextCommandImpl askSetAction = new DebuggerContextCommandImpl(debuggerContext) { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java index da776d39b2bf..4c9e8cb5a2d4 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java @@ -40,7 +40,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.util.ProgressWindowWithNotification; +import com.intellij.openapi.progress.util.ProgressWindow; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.*; @@ -135,15 +135,15 @@ public class MethodBreakpoint extends BreakpointWithHighlighter indicatorRef = new AtomicReference<>(); + AtomicReference indicatorRef = new AtomicReference<>(); ApplicationManager.getApplication().invokeAndWait( () -> { - ProgressWindowWithNotification progress = - new ProgressWindowWithNotification(true, false, debugProcess.getProject(), "Cancel emulation"); + ProgressWindow progress = + new ProgressWindow(true, false, debugProcess.getProject(), "Cancel emulation"); progress.setDelayInMillis(2000); indicatorRef.set(progress); }); - ProgressWindowWithNotification indicator = indicatorRef.get(); + ProgressWindow indicator = indicatorRef.get(); AtomicBoolean changed = new AtomicBoolean(); XBreakpointListener> listener = new XBreakpointListener>() { diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorListener.java b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorListener.java index b82961fbe4e0..2c6e71d94810 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorListener.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorListener.java @@ -15,6 +15,8 @@ */ package com.intellij.openapi.progress.util; +import com.intellij.openapi.wm.ex.ProgressIndicatorEx; + /** * @author lex */ @@ -22,4 +24,20 @@ public interface ProgressIndicatorListener { void cancelled(); void stopped(); + + default void installToProgress(ProgressIndicatorEx progress) { + progress.addStateDelegate(new AbstractProgressIndicatorExBase(){ + @Override + public void cancel() { + super.cancel(); + cancelled(); + } + + @Override + public void stop() { + super.stop(); + stopped(); + } + }); + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWindowWithNotification.java b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWindowWithNotification.java index 8d5be53460d1..adeeef9dbcba 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWindowWithNotification.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWindowWithNotification.java @@ -16,11 +16,12 @@ package com.intellij.openapi.progress.util; import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.ex.ProgressIndicatorEx; import javax.swing.*; /** - * @author lex + * @deprecated use {@link ProgressWindow} and {@link ProgressIndicatorListener#installToProgress(ProgressIndicatorEx)} */ public class ProgressWindowWithNotification extends ProgressWindow { public ProgressWindowWithNotification(boolean shouldShowCancel, Project project) { @@ -40,19 +41,7 @@ public class ProgressWindowWithNotification extends ProgressWindow { } public void addListener(final ProgressIndicatorListener listener) { - addStateDelegate(new AbstractProgressIndicatorExBase(){ - @Override - public void cancel() { - super.cancel(); - listener.cancelled(); - } - - @Override - public void stop() { - super.stop(); - listener.stopped(); - } - }); + listener.installToProgress(this); } }