Search in sources :

Example 1 with Update

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

the class MavenProjectsManagerWatcher method start.

public synchronized void start() {
    final MessageBusConnection myBusConnection = myProject.getMessageBus().connect(myChangedDocumentsQueue);
    myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new MyFileChangeListener());
    myBusConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyRootChangesListener());
    myChangedDocumentsQueue.makeUserAware(myProject);
    myChangedDocumentsQueue.activate();
    myBusConnection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
            MavenProject mavenProject = myManager.findProject(module);
            if (mavenProject != null && !myManager.isIgnored(mavenProject)) {
                VirtualFile file = mavenProject.getFile();
                if (myManager.isManagedFile(file) && myManager.getModules(mavenProject).isEmpty()) {
                    myManager.removeManagedFiles(Collections.singletonList(file));
                } else {
                    myManager.setIgnoredState(Collections.singletonList(mavenProject), true);
                }
            }
        }

        @Override
        public void moduleAdded(@NotNull final Project project, @NotNull final Module module) {
            // this method is needed to return non-ignored status for modules that were deleted (and thus ignored) and then created again with a different module type
            if (myManager.isMavenizedModule(module)) {
                MavenProject mavenProject = myManager.findProject(module);
                if (mavenProject != null)
                    myManager.setIgnoredState(Collections.singletonList(mavenProject), false);
            }
        }
    });
    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 fileName = file.getName();
            boolean isMavenFile = fileName.equals(MavenConstants.POM_XML) || fileName.equals(MavenConstants.PROFILES_XML) || isSettingsFile(file) || fileName.startsWith("pom.");
            if (!isMavenFile)
                return;
            synchronized (myChangedDocuments) {
                myChangedDocuments.add(doc);
            }
            myChangedDocumentsQueue.queue(new Update(MavenProjectsManagerWatcher.this) {

                @Override
                public void run() {
                    final Document[] copy;
                    synchronized (myChangedDocuments) {
                        copy = myChangedDocuments.toArray(new Document[myChangedDocuments.size()]);
                        myChangedDocuments.clear();
                    }
                    MavenUtil.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);
    final MavenGeneralSettings.Listener mySettingsPathsChangesListener = new MavenGeneralSettings.Listener() {

        @Override
        public void changed() {
            updateSettingsFilePointers();
            onSettingsChange();
        }
    };
    myGeneralSettings.addListener(mySettingsPathsChangesListener);
    Disposer.register(myChangedDocumentsQueue, new Disposable() {

        @Override
        public void dispose() {
            myGeneralSettings.removeListener(mySettingsPathsChangesListener);
            mySettingsFilesPointers.clear();
        }
    });
    updateSettingsFilePointers();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener) VirtualFilePointerListener(com.intellij.openapi.vfs.pointers.VirtualFilePointerListener) ModuleListener(com.intellij.openapi.project.ModuleListener) WriteAction(com.intellij.openapi.application.WriteAction) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) Document(com.intellij.openapi.editor.Document) Update(com.intellij.util.ui.update.Update) Result(com.intellij.openapi.application.Result) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module)

Example 2 with Update

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

the class FilteringTreeBuilder method refilter.

public ActionCallback refilter(@Nullable final Object preferredSelection, final boolean adjustSelection, final boolean now) {
    if (myRefilterQueue != null) {
        myRefilterQueue.cancelAllUpdates();
    }
    final ActionCallback callback = new ActionCallback();
    final Runnable afterCancelUpdate = new Runnable() {

        @Override
        public void run() {
            if (myRefilterQueue == null || now) {
                refilterNow(preferredSelection, adjustSelection).doWhenDone(callback.createSetDoneRunnable());
            } else {
                myRefilterQueue.queue(new Update(this) {

                    @Override
                    public void run() {
                        refilterNow(preferredSelection, adjustSelection).notifyWhenDone(callback);
                    }

                    @Override
                    public void setRejected() {
                        super.setRejected();
                        callback.setDone();
                    }
                });
            }
        }
    };
    if (!isDisposed()) {
        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            getUi().cancelUpdate().doWhenProcessed(afterCancelUpdate);
        } else {
            afterCancelUpdate.run();
        }
    }
    return callback;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) Update(com.intellij.util.ui.update.Update)

Example 3 with Update

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

the class ServerConnectionEventDispatcher method queueDeploymentsChanged.

public void queueDeploymentsChanged(final ServerConnectionImpl<?> connection) {
    myEventsQueue.activate();
    myEventsQueue.queue(new Update(connection) {

        @Override
        public void run() {
            myMessageBus.syncPublisher(ServerConnectionListener.TOPIC).onDeploymentsChanged(connection);
        }
    });
}
Also used : Update(com.intellij.util.ui.update.Update)

Example 4 with Update

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

the class ProjectStructureDaemonAnalyzer method reset.

public void reset() {
    LOG.debug("analyzer started");
    myAnalyzerQueue.activate();
    myResultsUpdateQueue.activate();
    myAnalyzerQueue.queue(new Update("reset") {

        @Override
        public void run() {
            myStopped.set(false);
        }
    });
}
Also used : Update(com.intellij.util.ui.update.Update)

Example 5 with Update

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

the class ExternalSystemProjectsWatcher method scheduleUpdate.

private void scheduleUpdate(String projectPath) {
    Pair<ExternalSystemManager, ExternalProjectSettings> linkedProject = findLinkedProjectSettings(projectPath);
    if (linkedProject == null)
        return;
    ExternalSystemManager<?, ?, ?, ?, ?> manager = linkedProject.first;
    ProjectSystemId systemId = manager.getSystemId();
    boolean useAutoImport = linkedProject.second.isUseAutoImport();
    if (useAutoImport) {
        final ExternalSystemTask resolveTask = ServiceManager.getService(ExternalSystemProcessingManager.class).findTask(ExternalSystemTaskType.RESOLVE_PROJECT, systemId, projectPath);
        final ExternalSystemTaskState taskState = resolveTask == null ? null : resolveTask.getState();
        if (taskState == null || taskState.isStopped()) {
            scheduleRefresh(myProject, projectPath, systemId, false);
        } else if (taskState != ExternalSystemTaskState.NOT_STARTED) {
        // TODO re-schedule to wait for the project import task end
        }
    } else {
        myUpdatesQueue.queue(new Update(Pair.create(systemId, projectPath)) {

            public void run() {
                doUpdateNotifications(false, systemId, projectPath);
            }
        });
    }
}
Also used : ExternalSystemManager(com.intellij.openapi.externalSystem.ExternalSystemManager) ExternalSystemProcessingManager(com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) Update(com.intellij.util.ui.update.Update) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)

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