Search in sources :

Example 26 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection in project android by JetBrains.

the class JavaFacet method initFacet.

@Override
public void initFacet() {
    MessageBusConnection connection = getModule().getMessageBus().connect(this);
    connection.subscribe(PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            ApplicationManager.getApplication().invokeLater(() -> {
                if (!isDisposed()) {
                    PsiDocumentManager.getInstance(getModule().getProject()).commitAllDocuments();
                    updateConfiguration();
                }
            });
        }
    });
    updateConfiguration();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 27 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection in project android by JetBrains.

the class AndroidProjectComponent method projectOpened.

@Override
public void projectOpened() {
    final CompilerManager manager = CompilerManager.getInstance(myProject);
    manager.addBeforeTask(new AndroidPrecompileTask());
    myDisposable = Disposer.newDisposable(getClass().getName());
    if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
        if (ProjectFacetManager.getInstance(myProject).hasFacets(AndroidFacet.ID)) {
            createAndroidSpecificComponents();
        } else {
            final MessageBusConnection connection = myProject.getMessageBus().connect(myDisposable);
            connection.subscribe(FacetManager.FACETS_TOPIC, new FacetManagerAdapter() {

                @Override
                public void facetAdded(@NotNull Facet facet) {
                    if (facet instanceof AndroidFacet) {
                        createAndroidSpecificComponents();
                        connection.disconnect();
                    }
                }
            });
        }
    }
}
Also used : AndroidPrecompileTask(org.jetbrains.android.compiler.AndroidPrecompileTask) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) CompilerManager(com.intellij.openapi.compiler.CompilerManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) FacetManagerAdapter(com.intellij.facet.FacetManagerAdapter) Facet(com.intellij.facet.Facet) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 28 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection in project android by JetBrains.

the class DeveloperServices method initializeFor.

private static void initializeFor(@NotNull final Module module) {
    if (ourServices.containsKey(module)) {
        return;
    }
    for (DeveloperServiceCreators creators : DeveloperServiceCreators.EP_NAME.getExtensions()) {
        try {
            for (DeveloperServiceCreator creator : creators.getCreators()) {
                DeveloperService service = creator.createService(module);
                if (service != null) {
                    ourServices.put(module, service);
                }
            }
        } catch (Exception e) {
            LOG.warn("Caught exception while initializing services", e);
        }
    }
    getBuildSystemOperations(module.getProject()).initializeServices(module, new Runnable() {

        @Override
        public void run() {
            for (DeveloperService service : ourServices.get(module)) {
                service.updateInstalledState();
            }
        }
    });
    MessageBusConnection connection = module.getMessageBus().connect(module);
    connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleRemoved(@NotNull Project project, @NotNull Module moduleRemoved) {
            if (module == moduleRemoved) {
                ourServices.removeAll(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)

Example 29 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection in project intellij-community by JetBrains.

the class CloudGitChooseAccountStepImpl method updateDataModel.

@Override
public void updateDataModel() {
    super.updateDataModel();
    final MultiMap<CloudGitProjectRoot, DetectedSourceRoot> project2sourceRoots = new MultiMap<>();
    new RootIterator() {

        CloudGitProjectRoot lastProjectRoot = null;

        @Override
        protected void processProjectRoot(CloudGitProjectRoot root) {
            lastProjectRoot = root;
            project2sourceRoots.put(lastProjectRoot, new ArrayList<>());
        }

        @Override
        protected void processJavaSourceRoot(DetectedSourceRoot root) {
            project2sourceRoots.putValue(lastProjectRoot, root);
        }
    }.iterate();
    List<ModuleDescriptor> modules = new ArrayList<>(myProjectDescriptor.getModules());
    for (Map.Entry<CloudGitProjectRoot, Collection<DetectedSourceRoot>> project2sourceRootsEntry : project2sourceRoots.entrySet()) {
        final CloudGitProjectRoot projectRoot = project2sourceRootsEntry.getKey();
        final File directory = projectRoot.getDirectory();
        ModuleDescriptor moduleDescriptor = new ModuleDescriptor(directory, StdModuleTypes.JAVA, project2sourceRootsEntry.getValue());
        final String applicationName = projectRoot.getApplicationName();
        moduleDescriptor.addConfigurationUpdater(new ModuleBuilder.ModuleConfigurationUpdater() {

            @Override
            public void update(@NotNull final Module module, @NotNull ModifiableRootModel rootModel) {
                final MessageBusConnection connection = module.getProject().getMessageBus().connect();
                connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

                    @Override
                    public void moduleAdded(@NotNull Project project, @NotNull Module addedModule) {
                        if (addedModule == module) {
                            StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> onModuleAdded(module));
                            connection.disconnect();
                        }
                    }
                });
            }

            private void onModuleAdded(Module module) {
                createRunConfiguration(module, applicationName);
                GitInit.refreshAndConfigureVcsMappings(module.getProject(), projectRoot.getRepositoryRoot(), directory.getAbsolutePath());
            }
        });
        modules.add(moduleDescriptor);
    }
    myProjectDescriptor.setModules(modules);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) ModuleBuilder(com.intellij.ide.util.projectWizard.ModuleBuilder) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) MultiMap(com.intellij.util.containers.MultiMap) ModuleDescriptor(com.intellij.ide.util.importProject.ModuleDescriptor) Project(com.intellij.openapi.project.Project) Collection(java.util.Collection) Module(com.intellij.openapi.module.Module) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) File(java.io.File)

Example 30 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection in project intellij-community by JetBrains.

the class GitUntrackedFilesHolder method setupVfsListener.

void setupVfsListener(@NotNull Project project) {
    if (!project.isDisposed()) {
        MessageBusConnection connection = project.getMessageBus().connect(this);
        connection.subscribe(VirtualFileManager.VFS_CHANGES, this);
    }
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Aggregations

MessageBusConnection (com.intellij.util.messages.MessageBusConnection)81 Project (com.intellij.openapi.project.Project)16 NotNull (org.jetbrains.annotations.NotNull)15 Module (com.intellij.openapi.module.Module)11 ModuleRootEvent (com.intellij.openapi.roots.ModuleRootEvent)10 ModuleListener (com.intellij.openapi.project.ModuleListener)8 ModuleRootListener (com.intellij.openapi.roots.ModuleRootListener)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 Disposable (com.intellij.openapi.Disposable)6 Document (com.intellij.openapi.editor.Document)6 VFileEvent (com.intellij.openapi.vfs.newvfs.events.VFileEvent)5 Update (com.intellij.util.ui.update.Update)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 StringUtil (com.intellij.openapi.util.text.StringUtil)4 ProcessHandler (com.intellij.execution.process.ProcessHandler)3 Application (com.intellij.openapi.application.Application)3 FileDocumentManagerAdapter (com.intellij.openapi.fileEditor.FileDocumentManagerAdapter)3 ModuleRootAdapter (com.intellij.openapi.roots.ModuleRootAdapter)3 VFileCreateEvent (com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent)3 File (java.io.File)3