use of com.intellij.util.ui.update.Update in project android by JetBrains.
the class NlModel method requestModelUpdate.
/**
* Asynchronously inflates the model and updates the view hierarchy
*/
protected void requestModelUpdate() {
ApplicationManager.getApplication().assertIsDispatchThread();
synchronized (PROGRESS_LOCK) {
if (myCurrentIndicator == null) {
myCurrentIndicator = new AndroidPreviewProgressIndicator();
myCurrentIndicator.start();
}
}
getRenderingQueue().queue(new Update("model.update", HIGH_PRIORITY) {
@Override
public void run() {
DumbService.getInstance(myFacet.getModule().getProject()).waitForSmartMode();
if (!myFacet.isDisposed()) {
try {
if (myFacet.requiresAndroidModel() && myFacet.getAndroidModel() == null) {
// Try again later - model hasn't been synced yet (and for example we won't
// be able to resolve custom views coming from libraries like appcompat,
// resulting in a broken render)
ApplicationManager.getApplication().invokeLater(() -> requestModelUpdate());
return;
}
updateModel();
} catch (Throwable e) {
Logger.getInstance(NlModel.class).error(e);
}
}
synchronized (PROGRESS_LOCK) {
if (myCurrentIndicator != null) {
myCurrentIndicator.stop();
myCurrentIndicator = null;
}
}
}
@Override
public boolean canEat(Update update) {
return equals(update);
}
});
}
use of com.intellij.util.ui.update.Update in project android by JetBrains.
the class IconStep 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 {
if (myAssetGenerator == null) {
// Init not done yet
return;
}
myAssetGenerator.generateImages(myImageMap, true, true);
ApplicationManager.getApplication().invokeLater(IconStep.this::updatePreviewImages);
} catch (final ImageGeneratorException exception) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
setErrorHtml(exception.getMessage());
}
});
}
}
});
}
use of com.intellij.util.ui.update.Update in project intellij-community by JetBrains.
the class GeneratedSourceFileChangeTrackerImpl method projectOpened.
@Override
public void projectOpened() {
final Update check = new Update("check for changes in generated files") {
@Override
public void run() {
checkFiles();
}
};
EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
VirtualFile file = myDocumentManager.getFile(e.getDocument());
if (file != null) {
myFilesToCheck.add(file);
myCheckingQueue.queue(check);
}
}
}, myProject);
MessageBusConnection connection = myProject.getMessageBus().connect();
connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {
@Override
public void fileContentReloaded(@NotNull VirtualFile file, @NotNull Document document) {
myFilesToCheck.remove(file);
if (myEditedGeneratedFiles.remove(file)) {
myEditorNotifications.updateNotifications(file);
}
}
});
connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
myEditedGeneratedFiles.remove(file);
}
});
connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(ModuleRootEvent event) {
myFilesToCheck.addAll(myEditedGeneratedFiles);
myEditedGeneratedFiles.clear();
myCheckingQueue.queue(check);
}
});
myCheckingQueue.activate();
}
use of com.intellij.util.ui.update.Update in project intellij-community by JetBrains.
the class ExternalSystemProjectsWatcher method start.
public synchronized void start() {
if (ExternalSystemUtil.isNoBackgroundMode()) {
return;
}
myUpdatesQueue.activate();
final MessageBusConnection myBusConnection = myProject.getMessageBus().connect(myChangedDocumentsQueue);
myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new MyFileChangeListener(this));
makeUserAware(myChangedDocumentsQueue, myProject);
myChangedDocumentsQueue.activate();
DocumentAdapter myDocumentListener = new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent event) {
Document doc = event.getDocument();
VirtualFile file = FileDocumentManager.getInstance().getFile(doc);
if (file == null)
return;
String externalProjectPath = getRelatedExternalProjectPath(file);
if (externalProjectPath == null)
return;
synchronized (myChangedDocuments) {
myChangedDocuments.add(doc);
}
myChangedDocumentsQueue.queue(new Update(ExternalSystemProjectsWatcher.this) {
@Override
public void run() {
final Document[] copy;
synchronized (myChangedDocuments) {
copy = myChangedDocuments.toArray(new Document[myChangedDocuments.size()]);
myChangedDocuments.clear();
}
ExternalSystemUtil.invokeLater(myProject, () -> new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
for (Document each : copy) {
PsiDocumentManager.getInstance(myProject).commitDocument(each);
((FileDocumentManagerImpl) FileDocumentManager.getInstance()).saveDocument(each, false);
}
}
}.execute());
}
});
}
};
EditorFactory.getInstance().getEventMulticaster().addDocumentListener(myDocumentListener, myBusConnection);
ServiceManager.getService(ExternalSystemProgressNotificationManager.class).addNotificationListener(this);
updateWatchedRoots(true);
Disposer.register(myChangedDocumentsQueue, () -> myFilesPointers.clear());
}
use of com.intellij.util.ui.update.Update in project intellij-community by JetBrains.
the class ScopeTreeViewPanel method queueUpdate.
private void queueUpdate(final VirtualFile fileToRefresh, final Function<PsiFile, DefaultMutableTreeNode> rootToReloadGetter, final String scopeName) {
if (myProject.isDisposed())
return;
AbstractProjectViewPane pane = ProjectView.getInstance(myProject).getCurrentProjectViewPane();
if (pane == null || !ScopeViewPane.ID.equals(pane.getId()) || !scopeName.equals(pane.getSubId())) {
return;
}
myUpdateQueue.queue(new Update(fileToRefresh) {
@Override
public void run() {
if (myProject.isDisposed() || !fileToRefresh.isValid())
return;
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(fileToRefresh);
if (psiFile != null) {
reload(rootToReloadGetter.fun(psiFile));
}
}
@Override
public boolean isExpired() {
return !isTreeShowing();
}
});
}
Aggregations