Search in sources :

Example 21 with ProgressManager

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

the class GitUnstashDialog method doOKAction.

@Override
protected void doOKAction() {
    VirtualFile root = getGitRoot();
    final GitLineHandler h = handler();
    final AtomicBoolean conflict = new AtomicBoolean();
    h.addLineListener(new GitLineHandlerAdapter() {

        public void onLineAvailable(String line, Key outputType) {
            if (line.contains("Merge conflict")) {
                conflict.set(true);
            }
        }
    });
    GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(root);
    GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(root, MERGE);
    h.addLineListener(untrackedFilesDetector);
    h.addLineListener(localChangesDetector);
    AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
    try {
        final Ref<GitCommandResult> result = Ref.create();
        final ProgressManager progressManager = ProgressManager.getInstance();
        boolean completed = progressManager.runProcessWithProgressSynchronously(new Runnable() {

            @Override
            public void run() {
                h.addLineListener(new GitHandlerUtil.GitLineHandlerListenerProgress(progressManager.getProgressIndicator(), h, "stash", false));
                Git git = Git.getInstance();
                result.set(git.runCommand(new Computable.PredefinedValueComputable<>(h)));
            }
        }, GitBundle.getString("unstash.unstashing"), true, myProject);
        if (!completed)
            return;
        VfsUtil.markDirtyAndRefresh(false, true, false, root);
        GitCommandResult res = result.get();
        if (conflict.get()) {
            boolean conflictsResolved = new UnstashConflictResolver(myProject, root, getSelectedStash()).merge();
            LOG.info("loadRoot " + root + ", conflictsResolved: " + conflictsResolved);
        } else if (untrackedFilesDetector.wasMessageDetected()) {
            GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(myProject, root, untrackedFilesDetector.getRelativeFilePaths(), "unstash", null);
        } else if (localChangesDetector.wasMessageDetected()) {
            LocalChangesWouldBeOverwrittenHelper.showErrorDialog(myProject, root, "unstash", localChangesDetector.getRelativeFilePaths());
        } else if (!res.success()) {
            GitUIUtil.showOperationErrors(myProject, h.errors(), h.printableCommandLine());
        }
    } finally {
        token.finish();
    }
    super.doOKAction();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AccessToken(com.intellij.openapi.application.AccessToken) ProgressManager(com.intellij.openapi.progress.ProgressManager) Key(com.intellij.openapi.util.Key) Computable(com.intellij.openapi.util.Computable)

Example 22 with ProgressManager

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

the class GitAbstractRebaseAction method actionPerformed.

@Override
public final void actionPerformed(AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    ProgressManager progressManager = ProgressManager.getInstance();
    String progressTitle = getProgressTitle();
    if (getRepositoryManager(project).hasOngoingRebase()) {
        progressManager.run(new Task.Backgroundable(project, progressTitle) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                performActionForProject(project, indicator);
            }
        });
    } else {
        final GitRepository repositoryToOperate = chooseRepository(project, GitRebaseUtils.getRebasingRepositories(project));
        if (repositoryToOperate != null) {
            progressManager.run(new Task.Backgroundable(project, progressTitle) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    performActionForRepository(project, repositoryToOperate, indicator);
                }
            });
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) Task(com.intellij.openapi.progress.Task) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 23 with ProgressManager

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

the class GitVFSListener method executeAdd.

@Override
protected void executeAdd(final List<VirtualFile> addedFiles, final Map<VirtualFile, VirtualFile> copiedFiles) {
    // Filter added files before further processing
    Map<VirtualFile, List<VirtualFile>> sortedFiles;
    try {
        sortedFiles = GitUtil.sortFilesByGitRoot(addedFiles, true);
    } catch (VcsException e) {
        throw new RuntimeException("The exception is not expected here", e);
    }
    final HashSet<VirtualFile> retainedFiles = new HashSet<>();
    final ProgressManager progressManager = ProgressManager.getInstance();
    progressManager.run(new Task.Backgroundable(myProject, GitBundle.getString("vfs.listener.checking.ignored"), true) {

        @Override
        public void run(@NotNull ProgressIndicator pi) {
            for (Map.Entry<VirtualFile, List<VirtualFile>> e : sortedFiles.entrySet()) {
                VirtualFile root = e.getKey();
                List<VirtualFile> files = e.getValue();
                pi.setText(root.getPresentableUrl());
                try {
                    retainedFiles.addAll(myGit.untrackedFiles(myProject, root, files));
                } catch (VcsException ex) {
                    ApplicationManager.getApplication().invokeLater(() -> gitVcs().showMessages(ex.getMessage()));
                }
            }
            addedFiles.retainAll(retainedFiles);
            AppUIUtil.invokeLaterIfProjectAlive(myProject, () -> originalExecuteAdd(addedFiles, copiedFiles));
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) ContainerUtil.newHashSet(com.intellij.util.containers.ContainerUtil.newHashSet)

Example 24 with ProgressManager

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

the class AbstractCreateVirtualEnvDialog method createVirtualEnv.

public void createVirtualEnv(final VirtualEnvCallback callback) {
    final ProgressManager progman = ProgressManager.getInstance();
    final Sdk basicSdk = getSdk();
    final Task.Modal createTask = new Task.Modal(myProject, PyBundle.message("sdk.create.venv.dialog.creating.venv"), false) {

        String myPath;

        public void run(@NotNull final ProgressIndicator indicator) {
            try {
                indicator.setText(PyBundle.message("sdk.create.venv.dialog.creating.venv"));
                myPath = createEnvironment(basicSdk);
            } catch (final ExecutionException e) {
                ApplicationManager.getApplication().invokeLater(() -> {
                    final PackageManagementService.ErrorDescription description = PyPackageManagementService.toErrorDescription(Collections.singletonList(e), basicSdk);
                    if (description != null) {
                        PackagesNotificationPanel.showError(PyBundle.message("sdk.create.venv.dialog.error.failed.to.create.venv"), description);
                    }
                }, ModalityState.any());
            }
        }

        @Override
        public void onSuccess() {
            if (myPath != null) {
                ApplicationManager.getApplication().invokeLater(() -> setupVirtualEnvSdk(myPath, associateWithProject(), callback));
            }
        }
    };
    progman.run(createTask);
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

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