use of com.intellij.openapi.progress.PerformInBackgroundOption in project azure-tools-for-java by Microsoft.
the class IntellijAzureTaskManager method doRunInBackgroundableModal.
protected void doRunInBackgroundableModal(final Runnable runnable, final AzureTask<?> task) {
final PerformInBackgroundOption foreground = PerformInBackgroundOption.DEAF;
// refer https://jetbrains.org/intellij/sdk/docs/basics/disposers.html
final Disposable disposable = Disposer.newDisposable();
// refer https://github.com/JetBrains/intellij-community/commit/077c5558993b97cfb6f68ccc3cbe13065ba3cba8
Registry.get("ide.background.tasks").setValue(false, disposable);
final String title = StringUtils.capitalize(Objects.requireNonNull(task.getTitle()).toString());
final Task.Backgroundable modalTask = new Task.Backgroundable((Project) task.getProject(), title, task.isCancellable(), foreground) {
@Override
public void run(@Nonnull final ProgressIndicator progressIndicator) {
task.setMonitor(new IntellijTaskMonitor(progressIndicator));
task.setBackgrounded(false);
runnable.run();
Disposer.dispose(disposable);
}
@Override
public void processSentToBackground() {
task.setBackgrounded(true);
}
};
ProgressManager.getInstance().run(modalTask);
}
use of com.intellij.openapi.progress.PerformInBackgroundOption in project intellij by bazelbuild.
the class ProgressiveTaskWithProgressIndicator method submitTaskWithResult.
/**
* Runs the given task on the specified executor (defaulting to BlazeExecutor's executor) with a
* progress dialog.
*/
public <T> ListenableFuture<T> submitTaskWithResult(ProgressiveWithResult<T> progressive) {
// The progress indicator must be created on the UI thread.
final ProgressWindow indicator = UIUtil.invokeAndWaitIfNeeded(() -> {
if (modality == Modality.MODAL) {
ProgressWindow window = new ProgressWindow(cancelable, project);
window.setTitle(title);
return window;
} else {
PerformInBackgroundOption backgroundOption = modality == Modality.BACKGROUNDABLE ? PerformInBackgroundOption.DEAF : PerformInBackgroundOption.ALWAYS_BACKGROUND;
return new BackgroundableProcessIndicator(project, title, backgroundOption, "Cancel", "Cancel", cancelable);
}
});
indicator.setIndeterminate(true);
indicator.start();
final ListenableFuture<T> future = executor.submit(() -> ProgressManager.getInstance().runProcess(() -> progressive.compute(indicator), indicator));
if (cancelable) {
indicator.addStateDelegate(new AbstractProgressIndicatorExBase() {
@Override
public void cancel() {
super.cancel();
future.cancel(true);
}
});
}
return future;
}
Aggregations