Search in sources :

Example 11 with Update

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);
        }
    });
}
Also used : Update(com.intellij.util.ui.update.Update)

Example 12 with 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());
                    }
                });
            }
        }
    });
}
Also used : Update(com.intellij.util.ui.update.Update)

Example 13 with Update

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileDocumentManagerAdapter(com.intellij.openapi.fileEditor.FileDocumentManagerAdapter) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Update(com.intellij.util.ui.update.Update) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) Document(com.intellij.openapi.editor.Document) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 14 with Update

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());
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) Document(com.intellij.openapi.editor.Document) Update(com.intellij.util.ui.update.Update) ExternalSystemProgressNotificationManager(com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager)

Example 15 with Update

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();
        }
    });
}
Also used : Update(com.intellij.util.ui.update.Update) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane)

Aggregations

Update (com.intellij.util.ui.update.Update)35 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)4 Document (com.intellij.openapi.editor.Document)3 ModuleRootListener (com.intellij.openapi.roots.ModuleRootListener)3 MergingUpdateQueue (com.intellij.util.ui.update.MergingUpdateQueue)3 RenderResult (com.android.tools.idea.rendering.RenderResult)2 Editor (com.intellij.openapi.editor.Editor)2 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)2 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)2 Project (com.intellij.openapi.project.Project)2 ActionCallback (com.intellij.openapi.util.ActionCallback)2 AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)1 RenderErrorModel (com.android.tools.idea.rendering.errors.ui.RenderErrorModel)1 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 SelectionModel (com.android.tools.idea.uibuilder.model.SelectionModel)1 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)1 FileHyperlinkInfo (com.intellij.execution.filters.FileHyperlinkInfo)1 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)1