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();
}
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);
}
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) {
}
}
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;
}
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();
}
};
}
Aggregations