add ProgressIndicatorListener#installToProgress and deprecate ProgressWindowWithNotification

This commit is contained in:
peter
2017-04-06 22:44:30 +02:00
parent cb500983a6
commit f3259b8405
6 changed files with 38 additions and 25 deletions
@@ -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);
@@ -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<DebuggerComma
}
}
@Deprecated
public void startProgress(final DebuggerCommandImpl command, final ProgressWindowWithNotification progressWindow) {
progressWindow.addListener(new ProgressIndicatorListenerAdapter() {
startProgress(command, (ProgressWindow)progressWindow);
}
public void startProgress(DebuggerCommandImpl command, ProgressWindow progressWindow) {
new ProgressIndicatorListenerAdapter() {
@Override
public void cancelled() {
command.release();
}
});
}.installToProgress(progressWindow);
ApplicationManager.getApplication().executeOnPooledThread(
() -> ProgressManager.getInstance().runProcess(() -> invokeAndWait(command), progressWindow));
@@ -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) {
@@ -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<JavaMethodBreakp
debugProcess.getVirtualMachineProxy().clearCaches(); // to force reload classes available so far
}
AtomicReference<ProgressWindowWithNotification> indicatorRef = new AtomicReference<>();
AtomicReference<ProgressWindow> 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<XBreakpoint<?>> listener = new XBreakpointListener<XBreakpoint<?>>() {
@@ -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();
}
});
}
}
@@ -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);
}
}