Search in sources :

Example 6 with ModuleListener

use of com.intellij.openapi.project.ModuleListener in project intellij-plugins by JetBrains.

the class DesignerApplicationManager method attachProjectAndModuleListeners.

void attachProjectAndModuleListeners(Disposable parentDisposable) {
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(parentDisposable);
    connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {

        @Override
        public void projectClosed(Project project) {
            if (isApplicationClosed()) {
                return;
            }
            Client client = Client.getInstance();
            if (client.getRegisteredProjects().contains(project)) {
                client.closeProject(project);
            }
        }
    });
    // unregistered module is more complicated - we cannot just remove all document factories which belong to project as in case of close project
    // we must remove all document factories belong to module and all dependents (dependent may be from another module, so, we process moduleRemoved synchronous
    // one by one)
    connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
            Client client = Client.getInstance();
            if (!client.isModuleRegistered(module)) {
                return;
            }
            if (unregisterTaskQueueProcessor == null) {
                unregisterTaskQueueProcessor = new QueueProcessor<>(module1 -> {
                    boolean hasError = true;
                    final ActionCallback callback;
                    initialRenderQueue.suspend();
                    try {
                        callback = Client.getInstance().unregisterModule(module1);
                        hasError = false;
                    } finally {
                        if (hasError) {
                            initialRenderQueue.resume();
                        }
                    }
                    callback.doWhenProcessed(() -> initialRenderQueue.resume());
                });
            }
            unregisterTaskQueueProcessor.add(module);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) ModuleListener(com.intellij.openapi.project.ModuleListener) QueueProcessor(com.intellij.util.concurrency.QueueProcessor) ActionCallback(com.intellij.openapi.util.ActionCallback) Module(com.intellij.openapi.module.Module)

Example 7 with ModuleListener

use of com.intellij.openapi.project.ModuleListener in project android by JetBrains.

the class ImportDependenciesUtil method importDependencies.

public static void importDependencies(@NotNull final Module module, final boolean updateBackwardDependencies) {
    synchronized (LOCK) {
        final Project project = module.getProject();
        module.putUserData(WAIT_FOR_IMPORTING_DEPENDENCIES_KEY, Boolean.TRUE);
        if (project.getUserData(WAIT_FOR_IMPORTING_DEPENDENCIES_KEY) != Boolean.TRUE) {
            project.putUserData(WAIT_FOR_IMPORTING_DEPENDENCIES_KEY, Boolean.TRUE);
            StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {

                @Override
                public void run() {
                    // todo: this doesn't work in module configurator after 'Apply' button pressed
                    if (module.isLoaded()) {
                        importDependenciesForMarkedModules(project, updateBackwardDependencies);
                    } else {
                        final MessageBusConnection connection = module.getMessageBus().connect();
                        connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

                            @Override
                            public void moduleAdded(@NotNull final Project project, @NotNull final Module addedModule) {
                                if (module.equals(addedModule)) {
                                    connection.disconnect();
                                    importDependenciesForMarkedModules(project, updateBackwardDependencies);
                                }
                            }
                        });
                    }
                }
            });
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ModuleListener

use of com.intellij.openapi.project.ModuleListener in project intellij-community by JetBrains.

the class FacetPointersManagerImpl method initComponent.

@Override
public void initComponent() {
    MessageBusConnection connection = myProject.getMessageBus().connect();
    connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleAdded(@NotNull Project project, @NotNull Module module) {
            refreshPointers(module);
        }

        @Override
        public void modulesRenamed(@NotNull Project project, @NotNull List<Module> modules, @NotNull Function<Module, String> oldNameProvider) {
            for (Module module : modules) {
                refreshPointers(module);
            }
        }
    });
    connection.subscribe(FacetManager.FACETS_TOPIC, new FacetManagerAdapter() {

        @Override
        public void facetAdded(@NotNull Facet facet) {
            refreshPointers(facet.getModule());
        }

        @Override
        public void beforeFacetRenamed(@NotNull Facet facet) {
            final FacetPointerImpl pointer = myPointers.get(constructId(facet));
            if (pointer != null) {
                pointer.refresh();
            }
        }

        @Override
        public void facetRenamed(@NotNull final Facet facet, @NotNull final String oldName) {
            refreshPointers(facet.getModule());
        }
    });
    for (Module module : ModuleManager.getInstance(myProject).getModules()) {
        refreshPointers(module);
    }
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) Module(com.intellij.openapi.module.Module) FacetManagerAdapter(com.intellij.facet.FacetManagerAdapter) Facet(com.intellij.facet.Facet)

Aggregations

Module (com.intellij.openapi.module.Module)8 ModuleListener (com.intellij.openapi.project.ModuleListener)8 Project (com.intellij.openapi.project.Project)8 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)8 NotNull (org.jetbrains.annotations.NotNull)3 Document (com.intellij.openapi.editor.Document)2 ReformatCodeProcessor (com.intellij.codeInsight.actions.ReformatCodeProcessor)1 Facet (com.intellij.facet.Facet)1 FacetManagerAdapter (com.intellij.facet.FacetManagerAdapter)1 ModuleDescriptor (com.intellij.ide.util.importProject.ModuleDescriptor)1 ModuleBuilder (com.intellij.ide.util.projectWizard.ModuleBuilder)1 DetectedSourceRoot (com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot)1 Disposable (com.intellij.openapi.Disposable)1 Result (com.intellij.openapi.application.Result)1 WriteAction (com.intellij.openapi.application.WriteAction)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 FileDocumentManagerImpl (com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl)1 FileTypeManagerImpl (com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl)1