run choose by name bg calculation in smart mode (EA-65609 - INRE: FileBasedIndexImpl.handleDumbMode)

This commit is contained in:
peter
2015-07-20 20:18:16 +02:00
parent c91b9950a2
commit ea07addeee
3 changed files with 32 additions and 10 deletions
@@ -49,6 +49,7 @@ import com.intellij.openapi.progress.util.ProgressIndicatorBase;
import com.intellij.openapi.progress.util.ProgressIndicatorUtils;
import com.intellij.openapi.progress.util.ReadTask;
import com.intellij.openapi.progress.util.TooManyUsagesStatus;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.*;
import com.intellij.openapi.util.*;
@@ -1494,7 +1495,7 @@ public abstract class ChooseByNameBase {
return panel;
}
private class CalcElementsThread implements ReadTask {
private class CalcElementsThread extends ReadTask {
private final String myPattern;
private final boolean myCheckboxState;
private final Consumer<Set<?>> myCallback;
@@ -1521,6 +1522,16 @@ public abstract class ChooseByNameBase {
ProgressIndicatorUtils.scheduleWithWriteActionPriority(myProgress, this);
}
@Override
public void runBackgroundProcess(@NotNull final ProgressIndicator indicator) {
DumbService.getInstance(myProject).runReadActionInSmartMode(new Runnable() {
@Override
public void run() {
computeInReadAction(indicator);
}
});
}
@Override
public void computeInReadAction(@NotNull ProgressIndicator indicator) {
if (myProject != null && myProject.isDisposed()) return;
@@ -176,12 +176,7 @@ public class ProgressIndicatorUtils {
@Override
public void run() {
try {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
task.computeInReadAction(progressIndicator);
}
});
task.runBackgroundProcess(progressIndicator);
}
catch (ProcessCanceledException ignore) {
}
@@ -15,6 +15,8 @@
*/
package com.intellij.openapi.progress.util;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import org.jetbrains.annotations.NotNull;
@@ -24,17 +26,31 @@ import org.jetbrains.annotations.NotNull;
* @see com.intellij.openapi.progress.util.ProgressIndicatorUtils#scheduleWithWriteActionPriority(ReadTask)
*
*/
public interface ReadTask {
public abstract class ReadTask {
/**
* Performs the computation.
* Is invoked inside a read action and under a progress indicator that's canceled when a write action is about to occur.
*/
void computeInReadAction(@NotNull ProgressIndicator indicator);
public abstract void computeInReadAction(@NotNull ProgressIndicator indicator) throws ProcessCanceledException;
/**
* Is invoked on Swing thread whenever the computation is canceled by a write action.
* A likely implementation is to restart the computation, maybe based on the new state of the system.
*/
void onCanceled(@NotNull ProgressIndicator indicator);
public abstract void onCanceled(@NotNull ProgressIndicator indicator);
/**
* Is invoked on a background thread. The responsibility of this method is to start a read action and
* call {@link #computeInReadAction(ProgressIndicator)}. Overriders might also do something else.
* For example, use {@link com.intellij.openapi.project.DumbService#runReadActionInSmartMode(Runnable)}.
* @param indicator the progress indicator of the background thread
*/
public void runBackgroundProcess(@NotNull final ProgressIndicator indicator) throws ProcessCanceledException {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
computeInReadAction(indicator);
}
});
}
}