Search in sources :

Example 31 with Task

use of com.intellij.openapi.progress.Task in project android by JetBrains.

the class VfsInstallListener method statusChanged.

@Override
public void statusChanged(@NonNull PackageOperation op, @NonNull ProgressIndicator progress) throws PackageOperation.StatusChangeListenerException {
    if (op.getInstallStatus().equals(PackageOperation.InstallStatus.COMPLETE)) {
        Task refreshTask = new Task.Backgroundable(null, "Refreshing...", false, PerformInBackgroundOption.ALWAYS_BACKGROUND) {

            @Override
            public void run(@NotNull com.intellij.openapi.progress.ProgressIndicator indicator) {
                indicator.setIndeterminate(true);
                doRefresh(op, progress);
            }
        };
        ApplicationManager.getApplication().invokeLater(refreshTask::queue, ModalityState.NON_MODAL);
    }
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.android.repository.api.ProgressIndicator) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with Task

use of com.intellij.openapi.progress.Task in project intellij-plugins by JetBrains.

the class CfmlProjectConfigurable method storeLanguageVersionWithProgress.

public static void storeLanguageVersionWithProgress(final Project project) {
    Task.Backgroundable task = new Task.Backgroundable(project, CfmlBundle.message("applying.new.language.version.task.name"), false) {

        public void run(@NotNull ProgressIndicator indicator) {
            final Collection<VirtualFile> cfmlFiles = new ArrayList<>();
            final VirtualFile baseDir = project.getBaseDir();
            if (baseDir != null) {
                FileBasedIndex.getInstance().iterateIndexableFiles(file -> {
                    if (CfmlFileType.INSTANCE == file.getFileType()) {
                        cfmlFiles.add(file);
                    }
                    return true;
                }, project, indicator);
            }
            ApplicationManager.getApplication().invokeAndWait(() -> FileContentUtil.reparseFiles(project, cfmlFiles, true), ModalityState.NON_MODAL);
        }
    };
    ProgressManager.getInstance().run(task);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with Task

use of com.intellij.openapi.progress.Task in project intellij-plugins by JetBrains.

the class PhoneGapAddPlatformBeforeRun method executeTask.

@Override
public boolean executeTask(DataContext context, final RunConfiguration configuration, ExecutionEnvironment env, PhoneGapAddPlatformTask task) {
    final PhoneGapRunConfiguration phoneGapRunConfiguration = (PhoneGapRunConfiguration) configuration;
    final PhoneGapCommandLine line = phoneGapRunConfiguration.getCommandLine();
    if (!line.needAddPlatform()) {
        return true;
    }
    final Project project = configuration.getProject();
    final Semaphore targetDone = new Semaphore();
    final Ref<Boolean> result = new Ref<>(true);
    final List<Exception> exceptions = new ArrayList<>();
    ApplicationManager.getApplication().invokeAndWait(() -> {
        //Save all opened documents
        FileDocumentManager.getInstance().saveAllDocuments();
        targetDone.down();
        new Task.Backgroundable(project, PhoneGapBundle.message("phonegap.before.task.init.title"), true) {

            public boolean shouldStartInBackground() {
                return true;
            }

            public void run(@NotNull final ProgressIndicator indicator) {
                try {
                    String platform = phoneGapRunConfiguration.getPlatform();
                    assert platform != null;
                    ProcessOutput output = line.platformAdd(platform);
                    if (output.getExitCode() != 0) {
                        ExecutionHelper.showOutput(project, output, PhoneGapBundle.message("phonegap.before.task.init.title"), null, true);
                        result.set(false);
                    }
                } catch (final Exception e) {
                    exceptions.add(e);
                    result.set(false);
                } finally {
                    targetDone.up();
                }
            }
        }.queue();
    }, ModalityState.NON_MODAL);
    if (!targetDone.waitFor(TimeUnit.MINUTES.toMillis(2))) {
        ExecutionHelper.showErrors(project, ContainerUtil.createMaybeSingletonList(new RuntimeException("Timeout")), PhoneGapBundle.message("phonegap.before.task.init.error"), null);
    } else if (!exceptions.isEmpty()) {
        ExecutionHelper.showErrors(project, exceptions, PhoneGapBundle.message("phonegap.before.task.init.error"), null);
    }
    return result.get();
}
Also used : PhoneGapCommandLine(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine) Task(com.intellij.openapi.progress.Task) BeforeRunTask(com.intellij.execution.BeforeRunTask) ArrayList(java.util.ArrayList) Semaphore(com.intellij.util.concurrency.Semaphore) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessOutput(com.intellij.execution.process.ProcessOutput)

Aggregations

Task (com.intellij.openapi.progress.Task)33 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)28 NotNull (org.jetbrains.annotations.NotNull)20 Project (com.intellij.openapi.project.Project)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 File (java.io.File)6 IOException (java.io.IOException)5 Editor (com.intellij.openapi.editor.Editor)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 Ref (com.intellij.openapi.util.Ref)3 Semaphore (com.intellij.util.concurrency.Semaphore)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 Disposable (com.intellij.openapi.Disposable)2 ProgressExecutionMode (com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode)2 BackgroundableProcessIndicator (com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 Installer (com.android.repository.api.Installer)1 InstallerFactory (com.android.repository.api.InstallerFactory)1