use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class TextFieldWithAutoCompletionListProvider method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull String prefix, @NotNull CompletionResultSet result) {
Collection<T> items = getItems(prefix, true, parameters);
addCompletionElements(result, this, items, -10000);
final ProgressManager progressManager = ProgressManager.getInstance();
ProgressIndicator mainIndicator = progressManager.getProgressIndicator();
final ProgressIndicator indicator = mainIndicator != null ? new SensitiveProgressWrapper(mainIndicator) : new EmptyProgressIndicator();
Future<Collection<T>> future = ApplicationManager.getApplication().executeOnPooledThread(() -> progressManager.runProcess(() -> getItems(prefix, false, parameters), indicator));
while (true) {
try {
Collection<T> tasks = future.get(100, TimeUnit.MILLISECONDS);
if (tasks != null) {
addCompletionElements(result, this, tasks, 0);
return;
}
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception ignore) {
}
ProgressManager.checkCanceled();
}
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class Preloader method initComponent.
@Override
public void initComponent() {
if (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment()) {
return;
}
ProgressManager progressManager = ProgressManager.getInstance();
for (final PreloadingActivity activity : PreloadingActivity.EP_NAME.getExtensions()) {
myExecutor.execute(() -> {
if (myIndicator.isCanceled())
return;
checkHeavyProcessRunning();
if (myIndicator.isCanceled())
return;
progressManager.runProcess(() -> {
try {
activity.preload(myWrappingIndicator);
} catch (ProcessCanceledException ignore) {
}
LOG.info("Finished preloading " + activity);
}, myIndicator);
});
}
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class IdeFrameFixture method waitForBackgroundTasksToFinish.
//@NotNull
//public IdeFrameFixture waitForGradleProjectSyncToFail() {
// try {
// waitForGradleProjectSyncToFinish(true);
// fail("Expecting project sync to fail");
// }
// catch (RuntimeException expected) {
// // expected failure.
// }
// return waitForBackgroundTasksToFinish();
//}
//@NotNull
//public IdeFrameFixture waitForGradleProjectSyncToStart() {
// Project project = getProject();
// final GradleSyncState syncState = GradleSyncState.getInstance(project);
// if (!syncState.isSyncInProgress()) {
// pause(new Condition("Syncing project " + quote(project.getName()) + " to finish") {
// @Override
// public boolean test() {
// return myGradleProjectEventListener.isSyncStarted();
// }
// }, SHORT_TIMEOUT);
// }
// return this;
//}
//@NotNull
//public IdeFrameFixture waitForGradleProjectSyncToFinish() {
// waitForGradleProjectSyncToFinish(false);
// return this;
//}
//private void waitForGradleProjectSyncToFinish(final boolean expectSyncFailure) {
// final Project project = getProject();
//
// // ensure GradleInvoker (in-process build) is always enabled.
// AndroidGradleBuildConfiguration buildConfiguration = AndroidGradleBuildConfiguration.getInstance(project);
// buildConfiguration.USE_EXPERIMENTAL_FASTER_BUILD = true;
//
// pause(new Condition("Syncing project " + quote(project.getName()) + " to finish") {
// @Override
// public boolean test() {
// GradleSyncState syncState = GradleSyncState.getInstance(project);
// boolean syncFinished =
// (myGradleProjectEventListener.isSyncFinished() || syncState.isSyncNeeded() != ThreeState.YES) && !syncState.isSyncInProgress();
// if (expectSyncFailure) {
// syncFinished = syncFinished && myGradleProjectEventListener.hasSyncError();
// }
// return syncFinished;
// }
// }, LONG_TIMEOUT);
//
// findGradleSyncAction().waitUntilEnabledAndShowing();
//
// if (myGradleProjectEventListener.hasSyncError()) {
// RuntimeException syncError = myGradleProjectEventListener.getSyncError();
// myGradleProjectEventListener.reset();
// throw syncError;
// }
//
// if (!myGradleProjectEventListener.isSyncSkipped()) {
// waitForBuildToFinish(SOURCE_GEN);
// }
//
// waitForBackgroundTasksToFinish();
//}
@NotNull
public IdeFrameFixture waitForBackgroundTasksToFinish() {
Pause.pause(new Condition("Background tasks to finish") {
@Override
public boolean test() {
ProgressManager progressManager = ProgressManager.getInstance();
return !progressManager.hasModalProgressIndicator() && !progressManager.hasProgressIndicator() && !progressManager.hasUnsafeProgressIndicator();
}
}, GuiTestUtil.LONG_TIMEOUT);
robot().waitForIdle();
return this;
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class RollbackAction method rollbackModifiedWithoutEditing.
private static void rollbackModifiedWithoutEditing(final Project project, final LinkedHashSet<VirtualFile> modifiedWithoutEditing) {
final String operationName = StringUtil.decapitalize(UIUtil.removeMnemonic(RollbackUtil.getRollbackOperationName(project)));
String message = (modifiedWithoutEditing.size() == 1) ? VcsBundle.message("rollback.modified.without.editing.confirm.single", operationName, modifiedWithoutEditing.iterator().next().getPresentableUrl()) : VcsBundle.message("rollback.modified.without.editing.confirm.multiple", operationName, modifiedWithoutEditing.size());
int rc = showYesNoDialog(project, message, VcsBundle.message("changes.action.rollback.title", operationName), getQuestionIcon());
if (rc != Messages.YES) {
return;
}
final List<VcsException> exceptions = new ArrayList<>();
final ProgressManager progressManager = ProgressManager.getInstance();
final Runnable action = new Runnable() {
public void run() {
final ProgressIndicator indicator = progressManager.getProgressIndicator();
try {
ChangesUtil.processVirtualFilesByVcs(project, modifiedWithoutEditing, (vcs, items) -> {
final RollbackEnvironment rollbackEnvironment = vcs.getRollbackEnvironment();
if (rollbackEnvironment != null) {
if (indicator != null) {
indicator.setText(vcs.getDisplayName() + ": performing " + UIUtil.removeMnemonic(rollbackEnvironment.getRollbackOperationName()).toLowerCase() + "...");
indicator.setIndeterminate(false);
}
rollbackEnvironment.rollbackModifiedWithoutCheckout(items, exceptions, new RollbackProgressModifier(items.size(), indicator));
if (indicator != null) {
indicator.setText2("");
}
}
});
} catch (ProcessCanceledException e) {
// for files refresh
}
if (!exceptions.isEmpty()) {
AbstractVcsHelper.getInstance(project).showErrors(exceptions, VcsBundle.message("rollback.modified.without.checkout.error.tab", operationName));
}
VfsUtil.markDirty(true, false, VfsUtilCore.toVirtualFileArray(modifiedWithoutEditing));
VirtualFileManager.getInstance().asyncRefresh(new Runnable() {
public void run() {
for (VirtualFile virtualFile : modifiedWithoutEditing) {
VcsDirtyScopeManager.getInstance(project).fileDirty(virtualFile);
}
}
});
}
};
progressManager.runProcessWithProgressSynchronously(action, operationName, true, project);
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class JobUtilTest method testProcessorReturningFalseDoesNotCrashTheOtherThread.
public void testProcessorReturningFalseDoesNotCrashTheOtherThread() {
final AtomicInteger delay = new AtomicInteger(0);
final Runnable checkCanceled = ProgressManager::checkCanceled;
Processor<String> processor = s -> {
busySleep(delay.incrementAndGet() % 10 + 10, checkCanceled);
return delay.get() % 100 != 0;
};
for (int i = 0; i < 100; i++) {
ProgressIndicator indicator = new EmptyProgressIndicator();
boolean result = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(10000, ""), indicator, false, false, processor);
assertFalse(indicator.isCanceled());
assertFalse(result);
}
}
Aggregations