Search in sources :

Example 21 with Update

use of com.intellij.util.ui.update.Update in project android by JetBrains.

the class NlComponentTree method updateHierarchy.

// ---- Methods for updating hierarchy while attempting to keep expanded nodes expanded ----
private void updateHierarchy() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    setPaintBusy(true);
    myUpdateQueue.queue(new Update("updateComponentStructure") {

        @Override
        public void run() {
            try {
                if (myModel == null) {
                    return;
                }
                mySelectionIsUpdating.set(true);
                Collection<NlComponent> components = getCollapsedComponents();
                setModel(new NlComponentTreeModel(myModel));
                collapseComponents(components);
                invalidateUI();
            } finally {
                setPaintBusy(false);
                mySelectionIsUpdating.set(false);
            }
            updateSelection();
        }
    });
    if (mySkipWait) {
        mySkipWait = false;
        myUpdateQueue.flush();
    }
}
Also used : Collection(java.util.Collection) Update(com.intellij.util.ui.update.Update)

Example 22 with Update

use of com.intellij.util.ui.update.Update in project android by JetBrains.

the class NlPropertiesManager method componentSelectionChanged.

// ---- Implements DesignSurfaceListener ----
@Override
public void componentSelectionChanged(@NotNull DesignSurface surface, @NotNull final List<NlComponent> newSelection) {
    if (surface != mySurface) {
        return;
    }
    MergingUpdateQueue queue = getUpdateQueue();
    if (queue == null) {
        return;
    }
    if (!newSelection.isEmpty() && myFirstLoad) {
        myFirstLoad = false;
        myLoadingPanel.startLoading();
    }
    myLoading = true;
    queue.queue(new Update("updateProperties") {

        @Override
        public void run() {
            setSelectedComponents(newSelection, myLoadingPanel::stopLoading);
        }

        @Override
        public boolean canEat(Update update) {
            return true;
        }
    });
}
Also used : MergingUpdateQueue(com.intellij.util.ui.update.MergingUpdateQueue) Update(com.intellij.util.ui.update.Update)

Example 23 with Update

use of com.intellij.util.ui.update.Update in project intellij-plugins by JetBrains.

the class NotIndexedCucumberExtension method getDataObject.

public Object getDataObject(@NotNull final Project project) {
    final DataObject result = new DataObject();
    result.myUpdateQueue.setPassThrough(false);
    PsiManager.getInstance(project).addPsiTreeChangeListener(result.myCucumberPsiTreeListener);
    PsiManager.getInstance(project).addPsiTreeChangeListener(new PsiTreeChangeAdapter() {

        @Override
        public void childAdded(@NotNull PsiTreeChangeEvent event) {
            final PsiElement parent = event.getParent();
            PsiElement child = event.getChild();
            if (isStepLikeFile(child, parent)) {
                final PsiFile file = (PsiFile) child;
                result.myUpdateQueue.queue(new Update(parent) {

                    public void run() {
                        if (file.isValid()) {
                            reloadAbstractStepDefinitions(file);
                            createWatcher(file);
                        }
                    }
                });
            }
        }

        @Override
        public void childRemoved(@NotNull PsiTreeChangeEvent event) {
            final PsiElement parent = event.getParent();
            final PsiElement child = event.getChild();
            if (isStepLikeFile(child, parent)) {
                result.myUpdateQueue.queue(new Update(parent) {

                    public void run() {
                        removeAbstractStepDefinitionsRelatedTo((PsiFile) child);
                    }
                });
            }
        }
    });
    // clear caches after modules roots were changed
    final MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        final List<VirtualFile> myPreviousStepDefsProviders = new ArrayList<>();

        public void beforeRootsChange(ModuleRootEvent event) {
            myPreviousStepDefsProviders.clear();
            collectAllStepDefsProviders(myPreviousStepDefsProviders, project);
        }

        public void rootsChanged(ModuleRootEvent event) {
            // compare new and previous content roots
            final List<VirtualFile> newStepDefsProviders = new ArrayList<>();
            collectAllStepDefsProviders(newStepDefsProviders, project);
            if (!compareRoots(newStepDefsProviders)) {
                // clear caches on roots changed
                reset(project);
            }
        }

        private boolean compareRoots(final List<VirtualFile> newStepDefsProviders) {
            if (myPreviousStepDefsProviders.size() != newStepDefsProviders.size()) {
                return false;
            }
            for (VirtualFile root : myPreviousStepDefsProviders) {
                if (!newStepDefsProviders.contains(root)) {
                    return false;
                }
            }
            return true;
        }
    });
    Disposer.register(project, connection);
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) Update(com.intellij.util.ui.update.Update) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent)

Example 24 with Update

use of com.intellij.util.ui.update.Update in project android by JetBrains.

the class NlPreviewForm method updateCaret.

private void updateCaret() {
    if (myCaretModel != null && !myIgnoreListener && myUseInteractiveSelector) {
        ScreenView screenView = mySurface.getCurrentScreenView();
        if (screenView != null) {
            int offset = myCaretModel.getOffset();
            if (offset != -1) {
                List<NlComponent> views = screenView.getModel().findByOffset(offset);
                if (views == null || views.isEmpty()) {
                    views = screenView.getModel().getComponents();
                }
                try {
                    myIgnoreListener = true;
                    SelectionModel selectionModel = screenView.getSelectionModel();
                    selectionModel.setSelection(views);
                    myRenderingQueue.queue(new Update("Preview update") {

                        @Override
                        public void run() {
                            mySurface.repaint();
                        }

                        @Override
                        public boolean canEat(Update update) {
                            return true;
                        }
                    });
                } finally {
                    myIgnoreListener = false;
                }
            }
        }
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) SelectionModel(com.android.tools.idea.uibuilder.model.SelectionModel) Update(com.intellij.util.ui.update.Update)

Example 25 with Update

use of com.intellij.util.ui.update.Update in project intellij-community by JetBrains.

the class LightToolWindowManager method bindToDesigner.

private void bindToDesigner(final DesignerEditorPanelFacade designer) {
    myWindowQueue.cancelAllUpdates();
    myWindowQueue.queue(new Update("update") {

        @Override
        public void run() {
            if (myToolWindowDisposed) {
                return;
            }
            if (myToolWindow == null) {
                if (designer == null) {
                    return;
                }
                initToolWindow();
            }
            updateToolWindow(designer);
        }
    });
}
Also used : Update(com.intellij.util.ui.update.Update)

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