Search in sources :

Example 66 with ProgressIndicator

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

the class CloudRuntimeTask method perform.

private T perform(boolean modal, final Disposable disposable) {
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    final AtomicReference<T> result = new AtomicReference<>();
    final Progressive progressive = new Progressive() {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            while (!indicator.isCanceled()) {
                if (semaphore.waitFor(500)) {
                    if (mySuccess.get()) {
                        UIUtil.invokeLaterIfNeeded(() -> {
                            if (disposable == null || !Disposer.isDisposed(disposable)) {
                                postPerform(result.get());
                            }
                        });
                    }
                    break;
                }
            }
        }
    };
    Task task;
    boolean cancellable = isCancellable(modal);
    if (modal) {
        task = new Task.Modal(myProject, myTitle, cancellable) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                progressive.run(indicator);
            }
        };
    } else {
        task = new Task.Backgroundable(myProject, myTitle, cancellable) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                progressive.run(indicator);
            }

            @Override
            public boolean shouldStartInBackground() {
                return CloudRuntimeTask.this.shouldStartInBackground();
            }
        };
    }
    mySuccess.set(false);
    myErrorMessage.set(null);
    run(semaphore, result);
    task.queue();
    return result.get();
}
Also used : Progressive(com.intellij.openapi.progress.Progressive) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(com.intellij.util.concurrency.Semaphore) NotNull(org.jetbrains.annotations.NotNull)

Example 67 with ProgressIndicator

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

the class AnnotateLocalFileAction method doAnnotate.

private static void doAnnotate(@NotNull final Editor editor, @NotNull final Project project) {
    final VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
    if (file == null)
        return;
    final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
    if (vcs == null)
        return;
    final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
    assert annotationProvider != null;
    final Ref<FileAnnotation> fileAnnotationRef = new Ref<>();
    final Ref<VcsException> exceptionRef = new Ref<>();
    VcsAnnotateUtil.getBackgroundableLock(project, file).lock();
    final Task.Backgroundable annotateTask = new Task.Backgroundable(project, VcsBundle.message("retrieving.annotations"), true) {

        @Override
        public void run(@NotNull final ProgressIndicator indicator) {
            try {
                fileAnnotationRef.set(annotationProvider.annotate(file));
            } catch (VcsException e) {
                exceptionRef.set(e);
            } catch (ProcessCanceledException pce) {
                throw pce;
            } catch (Throwable t) {
                exceptionRef.set(new VcsException(t));
            }
        }

        @Override
        public void onCancel() {
            onSuccess();
        }

        @Override
        public void onSuccess() {
            VcsAnnotateUtil.getBackgroundableLock(project, file).unlock();
            if (!exceptionRef.isNull()) {
                LOG.warn(exceptionRef.get());
                AbstractVcsHelper.getInstance(project).showErrors(Collections.singletonList(exceptionRef.get()), VcsBundle.message("message.title.annotate"));
            }
            if (!fileAnnotationRef.isNull()) {
                AnnotateToggleAction.doAnnotate(editor, project, file, fileAnnotationRef.get(), vcs);
            }
        }
    };
    ProgressManager.getInstance().run(annotateTask);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) AnnotationProvider(com.intellij.openapi.vcs.annotate.AnnotationProvider) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 68 with ProgressIndicator

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

the class AnnotateRevisionActionBase method annotate.

public static void annotate(@NotNull VirtualFile file, @NotNull VcsFileRevision fileRevision, @NotNull AbstractVcs vcs, @Nullable Editor editor, int annotatedLine) {
    final CharSequence oldContent = editor == null ? null : editor.getDocument().getImmutableCharSequence();
    final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
    assert annotationProvider != null;
    final Ref<FileAnnotation> fileAnnotationRef = new Ref<>();
    final Ref<Integer> newLineRef = new Ref<>();
    final Ref<VcsException> exceptionRef = new Ref<>();
    VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).lock();
    Semaphore semaphore = new Semaphore(0);
    AtomicBoolean shouldOpenEditorInSync = new AtomicBoolean(true);
    ProgressManager.getInstance().run(new Task.Backgroundable(vcs.getProject(), VcsBundle.message("retrieving.annotations"), true) {

        public void run(@NotNull ProgressIndicator indicator) {
            try {
                FileAnnotation fileAnnotation = annotationProvider.annotate(file, fileRevision);
                int newLine = translateLine(oldContent, fileAnnotation.getAnnotatedContent(), annotatedLine);
                fileAnnotationRef.set(fileAnnotation);
                newLineRef.set(newLine);
                shouldOpenEditorInSync.set(false);
                semaphore.release();
            } catch (VcsException e) {
                exceptionRef.set(e);
            }
        }

        @Override
        public void onFinished() {
            VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).unlock();
        }

        @Override
        public void onSuccess() {
            if (!exceptionRef.isNull()) {
                AbstractVcsHelper.getInstance(myProject).showError(exceptionRef.get(), VcsBundle.message("operation.name.annotate"));
            }
            if (fileAnnotationRef.isNull())
                return;
            AbstractVcsHelper.getInstance(myProject).showAnnotation(fileAnnotationRef.get(), file, vcs, newLineRef.get());
        }
    });
    try {
        semaphore.tryAcquire(ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS, TimeUnit.MILLISECONDS);
        // This will remove blinking on editor opening (step 1 - editor opens, step 2 - annotations are shown).
        if (shouldOpenEditorInSync.get()) {
            CharSequence content = LoadTextUtil.loadText(file);
            int newLine = translateLine(oldContent, content, annotatedLine);
            OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(vcs.getProject(), file, newLine, 0);
            FileEditorManager.getInstance(vcs.getProject()).openTextEditor(openFileDescriptor, true);
        }
    } catch (InterruptedException ignore) {
    }
}
Also used : Task(com.intellij.openapi.progress.Task) AnnotationProvider(com.intellij.openapi.vcs.annotate.AnnotationProvider) Semaphore(java.util.concurrent.Semaphore) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation)

Example 69 with ProgressIndicator

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

the class ShelveChangesManager method shelveChanges.

public ShelvedChangeList shelveChanges(final Collection<Change> changes, final String commitMessage, final boolean rollback, boolean markToBeDeleted) throws IOException, VcsException {
    final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
    if (progressIndicator != null) {
        progressIndicator.setText(VcsBundle.message("shelve.changes.progress.title"));
    }
    File schemePatchDir = generateUniqueSchemePatchDir(commitMessage, true);
    final List<Change> textChanges = new ArrayList<>();
    final List<ShelvedBinaryFile> binaryFiles = new ArrayList<>();
    for (Change change : changes) {
        if (ChangesUtil.getFilePath(change).isDirectory()) {
            continue;
        }
        if (change.getBeforeRevision() instanceof BinaryContentRevision || change.getAfterRevision() instanceof BinaryContentRevision) {
            binaryFiles.add(shelveBinaryFile(schemePatchDir, change));
        } else {
            textChanges.add(change);
        }
    }
    final ShelvedChangeList changeList;
    try {
        File patchFile = getPatchFileInConfigDir(schemePatchDir);
        ProgressManager.checkCanceled();
        final List<FilePatch> patches = IdeaTextPatchBuilder.buildPatch(myProject, textChanges, myProject.getBaseDir().getPresentableUrl(), false);
        ProgressManager.checkCanceled();
        CommitContext commitContext = new CommitContext();
        baseRevisionsOfDvcsIntoContext(textChanges, commitContext);
        ShelfFileProcessorUtil.savePatchFile(myProject, patchFile, patches, null, commitContext);
        changeList = new ShelvedChangeList(patchFile.toString(), commitMessage.replace('\n', ' '), binaryFiles);
        changeList.markToDelete(markToBeDeleted);
        changeList.setName(schemePatchDir.getName());
        ProgressManager.checkCanceled();
        mySchemeManager.addNewScheme(changeList, false);
        if (rollback) {
            final String operationName = UIUtil.removeMnemonic(RollbackChangesDialog.operationNameByChanges(myProject, changes));
            boolean modalContext = ApplicationManager.getApplication().isDispatchThread() && LaterInvocator.isInModalContext();
            if (progressIndicator != null) {
                progressIndicator.startNonCancelableSection();
            }
            new RollbackWorker(myProject, operationName, modalContext).doRollback(changes, true, null, VcsBundle.message("shelve.changes.action"));
        }
    } finally {
        notifyStateChanged();
    }
    return changeList;
}
Also used : RollbackWorker(com.intellij.openapi.vcs.changes.ui.RollbackWorker) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 70 with ProgressIndicator

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

the class TextFilePatchInProgress method getDiffRequestProducers.

@NotNull
@Override
public DiffRequestProducer getDiffRequestProducers(final Project project, final PatchReader patchReader) {
    final PatchChange change = getChange();
    final FilePatch patch = getPatch();
    final String path = patch.getBeforeName() == null ? patch.getAfterName() : patch.getBeforeName();
    final Getter<CharSequence> baseContentGetter = new Getter<CharSequence>() {

        @Override
        public CharSequence get() {
            return patchReader.getBaseRevision(project, path);
        }
    };
    return new DiffRequestProducer() {

        @NotNull
        @Override
        public DiffRequest process(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException {
            if (myCurrentBase != null && myCurrentBase.getFileType() == UnknownFileType.INSTANCE) {
                return new UnknownFileTypeDiffRequest(myCurrentBase, getName());
            }
            if (isConflictingChange()) {
                final VirtualFile file = getCurrentBase();
                Getter<ApplyPatchForBaseRevisionTexts> getter = new Getter<ApplyPatchForBaseRevisionTexts>() {

                    @Override
                    public ApplyPatchForBaseRevisionTexts get() {
                        return ApplyPatchForBaseRevisionTexts.create(project, file, VcsUtil.getFilePath(file), getPatch(), baseContentGetter);
                    }
                };
                String afterTitle = getPatch().getAfterVersionId();
                if (afterTitle == null)
                    afterTitle = "Patched Version";
                return PatchDiffRequestFactory.createConflictDiffRequest(project, file, getPatch(), afterTitle, getter, getName(), context, indicator);
            } else {
                return PatchDiffRequestFactory.createDiffRequest(project, change, getName(), context, indicator);
            }
        }

        @NotNull
        @Override
        public String getName() {
            final File ioCurrentBase = getIoCurrentBase();
            return ioCurrentBase == null ? getCurrentPath() : ioCurrentBase.getPath();
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Getter(com.intellij.openapi.util.Getter) DiffRequestProducer(com.intellij.diff.chains.DiffRequestProducer) UnknownFileTypeDiffRequest(com.intellij.diff.requests.UnknownFileTypeDiffRequest) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) NotNull(org.jetbrains.annotations.NotNull) UserDataHolder(com.intellij.openapi.util.UserDataHolder) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)352 Task (com.intellij.openapi.progress.Task)139 NotNull (org.jetbrains.annotations.NotNull)98 VirtualFile (com.intellij.openapi.vfs.VirtualFile)96 Project (com.intellij.openapi.project.Project)78 File (java.io.File)52 IOException (java.io.IOException)48 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)44 Nullable (org.jetbrains.annotations.Nullable)43 ProgressManager (com.intellij.openapi.progress.ProgressManager)35 List (java.util.List)30 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)28 Ref (com.intellij.openapi.util.Ref)27 VcsException (com.intellij.openapi.vcs.VcsException)25 ArrayList (java.util.ArrayList)23 ApplicationManager (com.intellij.openapi.application.ApplicationManager)22 Module (com.intellij.openapi.module.Module)21 Logger (com.intellij.openapi.diagnostic.Logger)20 java.util (java.util)20 Processor (com.intellij.util.Processor)18