Search in sources :

Example 16 with ProgressIndicator

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

the class SvnIntegrateChangesTask method indicatorOnStart.

private static void indicatorOnStart() {
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator != null) {
        indicator.setIndeterminate(true);
        indicator.setText(SvnBundle.message("action.Subversion.integrate.changes.progress.integrating.text"));
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 17 with ProgressIndicator

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

the class HgMergeCommand method mergeWith.

public static void mergeWith(@NotNull final HgRepository repository, @NotNull final String branchName, @NotNull final UpdatedFiles updatedFiles, @Nullable final Runnable onSuccessHandler) {
    final Project project = repository.getProject();
    final VirtualFile repositoryRoot = repository.getRoot();
    final HgMergeCommand hgMergeCommand = new HgMergeCommand(project, repository);
    //there is no difference between branch or revision or bookmark as parameter to merge,
    hgMergeCommand.setRevision(branchName);
    // we need just a string
    new Task.Backgroundable(project, "Merging Changes...") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            try {
                HgCommandResult result = hgMergeCommand.mergeSynchronously();
                if (HgErrorUtil.isAncestorMergeError(result)) {
                    //skip and notify
                    VcsNotifier.getInstance(project).notifyMinorWarning("Merging is skipped for " + repositoryRoot.getPresentableName(), "Merging with a working directory ancestor has no effect");
                    return;
                }
                new HgConflictResolver(project, updatedFiles).resolve(repositoryRoot);
                if (!HgConflictResolver.hasConflicts(project, repositoryRoot) && onSuccessHandler != null) {
                    // for example commit changes
                    onSuccessHandler.run();
                }
            } catch (VcsException exception) {
                if (exception.isWarning()) {
                    VcsNotifier.getInstance(project).notifyWarning("Warning during merge", exception.getMessage());
                } else {
                    VcsNotifier.getInstance(project).notifyError("Exception during merge", exception.getMessage());
                }
            }
        }
    }.queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) HgConflictResolver(org.zmlx.hg4idea.provider.update.HgConflictResolver)

Example 18 with ProgressIndicator

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

the class TaskManagerImpl method testConnection.

@Override
public boolean testConnection(final TaskRepository repository) {
    TestConnectionTask task = new TestConnectionTask("Test connection") {

        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setText("Connecting to " + repository.getUrl() + "...");
            indicator.setFraction(0);
            indicator.setIndeterminate(true);
            try {
                myConnection = repository.createCancellableConnection();
                if (myConnection != null) {
                    Future<Exception> future = ApplicationManager.getApplication().executeOnPooledThread(myConnection);
                    while (true) {
                        try {
                            myException = future.get(100, TimeUnit.MILLISECONDS);
                            return;
                        } catch (TimeoutException ignore) {
                            try {
                                indicator.checkCanceled();
                            } catch (ProcessCanceledException e) {
                                myException = e;
                                myConnection.cancel();
                                return;
                            }
                        } catch (Exception e) {
                            myException = e;
                            return;
                        }
                    }
                } else {
                    try {
                        repository.testConnection();
                    } catch (Exception e) {
                        LOG.info(e);
                        myException = e;
                    }
                }
            } catch (Exception e) {
                myException = e;
            }
        }
    };
    ProgressManager.getInstance().run(task);
    Exception e = task.myException;
    if (e == null) {
        myBadRepositories.remove(repository);
        Messages.showMessageDialog(myProject, "Connection is successful", "Connection", Messages.getInformationIcon());
    } else if (!(e instanceof ProcessCanceledException)) {
        String message = e.getMessage();
        if (e instanceof UnknownHostException) {
            message = "Unknown host: " + message;
        }
        if (message == null) {
            LOG.error(e);
            message = "Unknown error";
        }
        Messages.showErrorDialog(myProject, StringUtil.capitalize(message), "Error");
    }
    return e == null;
}
Also used : UnknownHostException(java.net.UnknownHostException) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) NotNull(org.jetbrains.annotations.NotNull) TimeoutException(java.util.concurrent.TimeoutException) XmlSerializationException(com.intellij.util.xmlb.XmlSerializationException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) SocketTimeoutException(java.net.SocketTimeoutException) UnknownHostException(java.net.UnknownHostException) TimeoutException(java.util.concurrent.TimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 19 with ProgressIndicator

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

the class AssociationsEditor method expandTree.

private void expandTree(DefaultTreeModel newModel) {
    final TreePath rootPath = new TreePath(newModel.getRoot());
    final Object element = myBuilder.getTreeStructure().getRootElement();
    myBuilder.batch(new Progressive() {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            myBuilder.expand(element, null);
            myBuilder.expand(myBuilder.getTreeStructure().getChildElements(element), null);
        }
    });
    myTree.setSelectionPath(rootPath);
    myTree.scrollRectToVisible(new Rectangle(new Point(0, 0)));
}
Also used : Progressive(com.intellij.openapi.progress.Progressive) TreePath(javax.swing.tree.TreePath) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 20 with ProgressIndicator

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

the class MavenBeforeRunTasksProvider method executeTask.

public boolean executeTask(final DataContext context, RunConfiguration configuration, ExecutionEnvironment env, final MavenBeforeRunTask task) {
    final Semaphore targetDone = new Semaphore();
    final boolean[] result = new boolean[] { true };
    try {
        ApplicationManager.getApplication().invokeAndWait(() -> {
            final Project project = CommonDataKeys.PROJECT.getData(context);
            final MavenProject mavenProject = getMavenProject(task);
            if (project == null || project.isDisposed() || mavenProject == null)
                return;
            FileDocumentManager.getInstance().saveAllDocuments();
            final MavenExplicitProfiles explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles();
            final MavenRunner mavenRunner = MavenRunner.getInstance(project);
            targetDone.down();
            new Task.Backgroundable(project, TasksBundle.message("maven.tasks.executing"), true) {

                public void run(@NotNull ProgressIndicator indicator) {
                    try {
                        MavenRunnerParameters params = new MavenRunnerParameters(true, mavenProject.getDirectory(), ParametersListUtil.parse(task.getGoal()), explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
                        result[0] = mavenRunner.runBatch(Collections.singletonList(params), null, null, TasksBundle.message("maven.tasks.executing"), indicator);
                    } finally {
                        targetDone.up();
                    }
                }

                @Override
                public boolean shouldStartInBackground() {
                    return MavenRunner.getInstance(project).getSettings().isRunMavenInBackground();
                }

                @Override
                public void processSentToBackground() {
                    MavenRunner.getInstance(project).getSettings().setRunMavenInBackground(true);
                }
            }.queue();
        }, ModalityState.NON_MODAL);
    } catch (Exception e) {
        MavenLog.LOG.error(e);
        return false;
    }
    targetDone.waitFor();
    return result[0];
}
Also used : Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Task(com.intellij.openapi.progress.Task) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenRunner(org.jetbrains.idea.maven.execution.MavenRunner) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Semaphore(com.intellij.util.concurrency.Semaphore) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)400 Task (com.intellij.openapi.progress.Task)151 VirtualFile (com.intellij.openapi.vfs.VirtualFile)106 NotNull (org.jetbrains.annotations.NotNull)101 Project (com.intellij.openapi.project.Project)88 File (java.io.File)59 IOException (java.io.IOException)58 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)47 Nullable (org.jetbrains.annotations.Nullable)46 ProgressManager (com.intellij.openapi.progress.ProgressManager)39 List (java.util.List)36 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)31 Ref (com.intellij.openapi.util.Ref)27 Module (com.intellij.openapi.module.Module)26 VcsException (com.intellij.openapi.vcs.VcsException)26 ArrayList (java.util.ArrayList)26 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 Logger (com.intellij.openapi.diagnostic.Logger)23 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)22 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)22