Search in sources :

Example 1 with PerformInBackgroundOption

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);
}
Also used : Disposable(com.intellij.openapi.Disposable) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Task(com.intellij.openapi.progress.Task) Nonnull(javax.annotation.Nonnull) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PerformInBackgroundOption(com.intellij.openapi.progress.PerformInBackgroundOption)

Example 2 with PerformInBackgroundOption

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;
}
Also used : AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) ProgressWindow(com.intellij.openapi.progress.util.ProgressWindow) PerformInBackgroundOption(com.intellij.openapi.progress.PerformInBackgroundOption) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)

Aggregations

PerformInBackgroundOption (com.intellij.openapi.progress.PerformInBackgroundOption)2 Disposable (com.intellij.openapi.Disposable)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 BackgroundableProcessIndicator (com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)1 AbstractProgressIndicatorExBase (com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase)1 ProgressWindow (com.intellij.openapi.progress.util.ProgressWindow)1 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)1 Nonnull (javax.annotation.Nonnull)1