use of com.intellij.util.ui.update.Update in project intellij-community by JetBrains.
the class AnnotateStackTraceAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
myIsLoading = true;
ProgressManager.getInstance().run(new Task.Backgroundable(myEditor.getProject(), "Getting File History", true) {
private final Object LOCK = new Object();
private final MergingUpdateQueue myUpdateQueue = new MergingUpdateQueue("AnnotateStackTraceAction", 200, true, null);
private MyActiveAnnotationGutter myGutter;
@Override
public void onCancel() {
myEditor.getGutter().closeAllAnnotations();
}
@Override
public void onFinished() {
myIsLoading = false;
Disposer.dispose(myUpdateQueue);
}
@Override
public void run(@NotNull ProgressIndicator indicator) {
MultiMap<VirtualFile, Integer> files2lines = new MultiMap<>();
Map<Integer, LastRevision> revisions = ContainerUtil.newHashMap();
ApplicationManager.getApplication().runReadAction(() -> {
for (int line = 0; line < myEditor.getDocument().getLineCount(); line++) {
indicator.checkCanceled();
VirtualFile file = getHyperlinkVirtualFile(myHyperlinks.findAllHyperlinksOnLine(line));
if (file == null)
continue;
files2lines.putValue(file, line);
}
});
files2lines.entrySet().forEach(entry -> {
indicator.checkCanceled();
VirtualFile file = entry.getKey();
Collection<Integer> lines = entry.getValue();
LastRevision revision = getLastRevision(file);
if (revision == null)
return;
synchronized (LOCK) {
for (Integer line : lines) {
revisions.put(line, revision);
}
}
myUpdateQueue.queue(new Update("update") {
@Override
public void run() {
updateGutter(indicator, revisions);
}
});
});
// myUpdateQueue can be disposed before the last revisions are passed to the gutter
ApplicationManager.getApplication().invokeLater(() -> updateGutter(indicator, revisions));
}
@CalledInAwt
private void updateGutter(@NotNull ProgressIndicator indicator, @NotNull Map<Integer, LastRevision> revisions) {
if (indicator.isCanceled())
return;
if (myGutter == null) {
myGutter = new MyActiveAnnotationGutter(getProject(), myHyperlinks, indicator);
myEditor.getGutter().registerTextAnnotation(myGutter, myGutter);
}
Map<Integer, LastRevision> revisionsCopy;
synchronized (LOCK) {
revisionsCopy = ContainerUtil.newHashMap(revisions);
}
myGutter.updateData(revisionsCopy);
((EditorGutterComponentEx) myEditor.getGutter()).revalidateMarkup();
}
@Nullable
private LastRevision getLastRevision(@NotNull VirtualFile file) {
try {
AbstractVcs vcs = VcsUtil.getVcsFor(myEditor.getProject(), file);
if (vcs == null)
return null;
VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
if (historyProvider == null)
return null;
FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
if (historyProvider instanceof VcsHistoryProviderEx) {
VcsFileRevision revision = ((VcsHistoryProviderEx) historyProvider).getLastRevision(filePath);
if (revision == null)
return null;
return LastRevision.create(revision);
} else {
VcsHistorySession session = historyProvider.createSessionFor(filePath);
if (session == null)
return null;
List<VcsFileRevision> list = session.getRevisionList();
if (list == null || list.isEmpty())
return null;
return LastRevision.create(list.get(0));
}
} catch (VcsException ignored) {
LOG.warn(ignored);
return null;
}
}
});
}
use of com.intellij.util.ui.update.Update in project android by JetBrains.
the class PsDaemon method reset.
public void reset() {
MergingUpdateQueue mainQueue = getMainQueue();
reset(mainQueue, getResultsUpdaterQueue());
mainQueue.queue(new Update("reset") {
@Override
public void run() {
myStopped.set(false);
}
});
}
use of com.intellij.util.ui.update.Update in project android by JetBrains.
the class DesignSurface method updateErrors.
/**
* When we have render errors for a given result, kick off a background computation
* of the error panel HTML, which when done will update the UI thread
*/
private void updateErrors(@Nullable final RenderResult result) {
assert result != null && result.getLogger().hasProblems();
getErrorQueue().cancelAllUpdates();
getErrorQueue().queue(new Update("errors") {
@Override
public void run() {
// Look up *current* result; a newer one could be available
final RenderResult result = myScreenView != null ? myScreenView.getResult() : null;
if (result == null) {
return;
}
RenderErrorModel model = BuildSettings.getInstance(myProject).getBuildMode() != null && result.getLogger().hasErrors() ? STILL_BUILDING_ERROR_MODEL : RenderErrorModelFactory.createErrorModel(result, DataManager.getInstance().getDataContext(myErrorPanel));
myErrorPanel.setModel(model);
setShowErrorPanel(model.getSize() != 0);
}
@Override
public boolean canEat(Update update) {
return true;
}
});
}
use of com.intellij.util.ui.update.Update in project android by JetBrains.
the class AndroidProcessChooserDialog method updateTree.
private void updateTree() {
final boolean showAllProcesses = myShowAllProcessesCheckBox.isSelected();
myUpdatesQueue.queue(new Update(AndroidProcessChooserDialog.this) {
@Override
public void run() {
final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(myProject);
if (debugBridge != null && AdbService.isDdmsCorrupted(debugBridge)) {
ApplicationManager.getApplication().invokeLater(() -> {
Messages.showErrorDialog(myContentPanel, AndroidBundle.message("ddms.corrupted.error"));
AndroidProcessChooserDialog.this.close(1);
});
return;
}
doUpdateTree(showAllProcesses);
}
@Override
public boolean canEat(Update update) {
return true;
}
});
}
use of com.intellij.util.ui.update.Update in project android by JetBrains.
the class CommonAssetSetStep method requestPreviewUpdate.
/**
* (Re)schedule the background task which updates the preview images.
*/
private void requestPreviewUpdate() {
myUpdateQueue.cancelAllUpdates();
myUpdateQueue.queue(new Update("update") {
@Override
public void run() {
try {
myAssetGenerator.generateImages(myImageMap, true, true);
SwingUtilities.invokeLater(CommonAssetSetStep.this::updatePreviewImages);
} catch (final ImageGeneratorException e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setErrorHtml(e.getMessage());
}
});
}
}
});
}
Aggregations