Search in sources :

Example 1 with ProgressManager

use of com.intellij.openapi.progress.ProgressManager in project buck by facebook.

the class BuckBuildManager method runBuckCommand.

/**
   * Execute simple process asynchronously with progress.
   *
   * @param handler        a handler
   * @param operationTitle an operation title shown in progress dialog
   */
public synchronized void runBuckCommand(final BuckCommandHandler handler, final String operationTitle) {
    if (!(handler instanceof BuckKillCommandHandler)) {
        currentRunningBuckCommandHandler = handler;
        // Save files for anything besides buck kill
        ApplicationManager.getApplication().invokeAndWait(new Runnable() {

            @Override
            public void run() {
                FileDocumentManager.getInstance().saveAllDocuments();
            }
        }, ModalityState.NON_MODAL);
    }
    Project project = handler.project();
    String exec = BuckSettingsProvider.getInstance().getState().buckExecutable;
    if (exec == null) {
        BuckToolWindowFactory.outputConsoleMessage(project, "Please specify the buck executable path!\n", ConsoleViewContentType.ERROR_OUTPUT);
        BuckToolWindowFactory.outputConsoleMessage(project, "Preference -> Tools -> Buck -> Path to Buck executable\n", ConsoleViewContentType.NORMAL_OUTPUT);
        return;
    }
    final ProgressManager manager = ProgressManager.getInstance();
    ApplicationManager.getApplication().invokeLater(new Runnable() {

        @Override
        public void run() {
            manager.run(new Task.Backgroundable(handler.project(), operationTitle, true) {

                public void run(final ProgressIndicator indicator) {
                    runInCurrentThread(handler, indicator, true, operationTitle);
                }
            });
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 2 with ProgressManager

use of com.intellij.openapi.progress.ProgressManager in project buck by facebook.

the class TestExecutionState method showProgress.

private void showProgress(final OSProcessHandler result, final String title) {
    final ProgressManager manager = ProgressManager.getInstance();
    ApplicationManager.getApplication().invokeLater(() -> {
        manager.run(new Task.Backgroundable(mProject, title, true) {

            public void run(@NotNull final ProgressIndicator indicator) {
                try {
                    result.waitFor();
                } finally {
                    indicator.cancel();
                }
            }
        });
    });
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 3 with ProgressManager

use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.

the class SvnConfigureProxiesDialog method execute.

public void execute(final String url) {
    Messages.showInfoMessage(myProject, SvnBundle.message("dialog.edit.http.proxies.settings.test.connection.settings.will.be.stored.text"), SvnBundle.message("dialog.edit.http.proxies.settings.test.connection.settings.will.be.stored.title"));
    if (!applyImpl()) {
        return;
    }
    final Ref<Exception> excRef = new Ref<>();
    final ProgressManager pm = ProgressManager.getInstance();
    pm.runProcessWithProgressSynchronously(() -> {
        final ProgressIndicator pi = pm.getProgressIndicator();
        if (pi != null) {
            pi.setText("Connecting to " + url);
        }
        try {
            SvnVcs.getInstance(myProject).getInfo(SvnUtil.createUrl(url), SVNRevision.HEAD);
        } catch (SvnBindException e) {
            excRef.set(e);
        }
    }, "Test connection", true, myProject);
    if (!excRef.isNull()) {
        Messages.showErrorDialog(myProject, excRef.get().getMessage(), SvnBundle.message("dialog.edit.http.proxies.settings.test.connection.error.title"));
    } else {
        Messages.showInfoMessage(myProject, SvnBundle.message("dialog.edit.http.proxies.settings.test.connection.succes.text"), SvnBundle.message("dialog.edit.http.proxies.settings.test.connection.succes.title"));
    }
}
Also used : Ref(com.intellij.openapi.util.Ref) SvnBindException(org.jetbrains.idea.svn.commandLine.SvnBindException) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SvnBindException(org.jetbrains.idea.svn.commandLine.SvnBindException) ConfigurationException(com.intellij.openapi.options.ConfigurationException)

Example 4 with ProgressManager

use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.

the class GroovyImportOptimizerRefactoringHelper method performOperation.

@Override
public void performOperation(final Project project, final Set<GroovyFile> files) {
    final ProgressManager progressManager = ProgressManager.getInstance();
    final Map<GroovyFile, Pair<List<GrImportStatement>, Set<GrImportStatement>>> redundants = new HashMap<>();
    final Runnable findUnusedImports = () -> {
        final ProgressIndicator progressIndicator = progressManager.getProgressIndicator();
        final int total = files.size();
        int i = 0;
        for (final GroovyFile file : files) {
            if (!file.isValid())
                continue;
            final VirtualFile virtualFile = file.getVirtualFile();
            if (!ProjectRootManager.getInstance(project).getFileIndex().isInSource(virtualFile)) {
                continue;
            }
            if (progressIndicator != null) {
                progressIndicator.setText2(virtualFile.getPresentableUrl());
                progressIndicator.setFraction((double) i++ / total);
            }
            ApplicationManager.getApplication().runReadAction(() -> {
                final Set<GrImportStatement> usedImports = GroovyImportUtil.findUsedImports(file);
                final List<GrImportStatement> validImports = PsiUtil.getValidImportStatements(file);
                redundants.put(file, Pair.create(validImports, usedImports));
            });
        }
    };
    if (!progressManager.runProcessWithProgressSynchronously(findUnusedImports, "Optimizing imports (Groovy) ... ", false, project)) {
        return;
    }
    WriteAction.run(() -> {
        for (GroovyFile groovyFile : redundants.keySet()) {
            if (!groovyFile.isValid())
                continue;
            final Pair<List<GrImportStatement>, Set<GrImportStatement>> pair = redundants.get(groovyFile);
            final List<GrImportStatement> validImports = pair.getFirst();
            final Set<GrImportStatement> usedImports = pair.getSecond();
            for (GrImportStatement importStatement : validImports) {
                if (!usedImports.contains(importStatement)) {
                    groovyFile.removeImport(importStatement);
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Set(java.util.Set) HashSet(com.intellij.util.containers.hash.HashSet) HashMap(java.util.HashMap) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) Pair(com.intellij.openapi.util.Pair)

Example 5 with ProgressManager

use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.

the class InstalledPackagesPanel method doUpdatePackages.

public void doUpdatePackages(@NotNull final PackageManagementService packageManagementService) {
    onUpdateStarted();
    ProgressManager progressManager = ProgressManager.getInstance();
    progressManager.run(new Task.Backgroundable(myProject, LOADING_PACKAGES_LIST_TITLE, true, PerformInBackgroundOption.ALWAYS_BACKGROUND) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            Collection<InstalledPackage> packages = Lists.newArrayList();
            try {
                packages = packageManagementService.getInstalledPackages();
            } catch (IOException e) {
                // do nothing, we already have an empty list
                LOG.warn(e.getMessage());
            } finally {
                final Collection<InstalledPackage> finalPackages = packages;
                final Map<String, RepoPackage> cache = buildNameToPackageMap(packageManagementService.getAllPackagesCached());
                final boolean shouldFetchLatestVersionsForOnlyInstalledPackages = shouldFetchLatestVersionsForOnlyInstalledPackages();
                if (cache.isEmpty()) {
                    if (!shouldFetchLatestVersionsForOnlyInstalledPackages) {
                        refreshLatestVersions(packageManagementService);
                    }
                }
                UIUtil.invokeLaterIfNeeded(() -> {
                    if (packageManagementService == myPackageManagementService) {
                        myPackagesTableModel.getDataVector().clear();
                        for (InstalledPackage pkg : finalPackages) {
                            RepoPackage repoPackage = cache.get(pkg.getName());
                            final String version = repoPackage != null ? repoPackage.getLatestVersion() : null;
                            myPackagesTableModel.addRow(new Object[] { pkg, pkg.getVersion(), version == null ? "" : version });
                        }
                        if (!cache.isEmpty()) {
                            onUpdateFinished();
                        }
                        if (shouldFetchLatestVersionsForOnlyInstalledPackages) {
                            setLatestVersionsForInstalledPackages();
                        }
                    }
                });
            }
        }
    });
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IOException(java.io.IOException)

Aggregations

ProgressManager (com.intellij.openapi.progress.ProgressManager)24 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)13 Task (com.intellij.openapi.progress.Task)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Project (com.intellij.openapi.project.Project)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 VcsException (com.intellij.openapi.vcs.VcsException)3 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2 IdeFrame (com.intellij.openapi.wm.IdeFrame)2 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 PsiSearchHelper (com.intellij.psi.search.PsiSearchHelper)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Robot (org.fest.swing.core.Robot)2 WindowFinder.findFrame (org.fest.swing.finder.WindowFinder.findFrame)2 Condition (org.fest.swing.timing.Condition)2 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 SensitiveProgressWrapper (com.intellij.concurrency.SensitiveProgressWrapper)1 ThreadDumper (com.intellij.diagnostic.ThreadDumper)1