Search in sources :

Example 36 with MessageBusConnection

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

the class ExecutorRegistryImpl method initComponent.

@Override
public void initComponent() {
    ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() {

        @Override
        public void projectOpened(final Project project) {
            final MessageBusConnection connect = project.getMessageBus().connect(project);
            connect.subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() {

                @Override
                public void processStartScheduled(@NotNull String executorId, @NotNull ExecutionEnvironment environment) {
                    myInProgress.add(createExecutionId(executorId, environment));
                }

                @Override
                public void processNotStarted(@NotNull String executorId, @NotNull ExecutionEnvironment environment) {
                    myInProgress.remove(createExecutionId(executorId, environment));
                }

                @Override
                public void processStarted(@NotNull String executorId, @NotNull ExecutionEnvironment environment, @NotNull ProcessHandler handler) {
                    myInProgress.remove(createExecutionId(executorId, environment));
                }
            });
        }

        @Override
        public void projectClosed(final Project project) {
            // perform cleanup
            synchronized (myInProgress) {
                for (Iterator<Trinity<Project, String, String>> it = myInProgress.iterator(); it.hasNext(); ) {
                    final Trinity<Project, String, String> trinity = it.next();
                    if (project.equals(trinity.first)) {
                        it.remove();
                    }
                }
            }
        }
    });
    final Executor[] executors = Extensions.getExtensions(Executor.EXECUTOR_EXTENSION_NAME);
    for (Executor executor : executors) {
        initExecutor(executor);
    }
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Trinity(com.intellij.openapi.util.Trinity) NotNull(org.jetbrains.annotations.NotNull) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 37 with MessageBusConnection

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

the class NavBarListener method subscribeTo.

static void subscribeTo(NavBarPanel panel) {
    if (panel.getClientProperty(LISTENER) != null) {
        unsubscribeFrom(panel);
    }
    final NavBarListener listener = new NavBarListener(panel);
    final Project project = panel.getProject();
    panel.putClientProperty(LISTENER, listener);
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(listener);
    FileStatusManager.getInstance(project).addFileStatusListener(listener);
    PsiManager.getInstance(project).addPsiTreeChangeListener(listener);
    WolfTheProblemSolver.getInstance(project).addProblemListener(listener);
    ActionManager.getInstance().addAnActionListener(listener);
    final MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, listener);
    connection.subscribe(NavBarModelListener.NAV_BAR, listener);
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
    panel.putClientProperty(BUS, connection);
    panel.addKeyListener(listener);
    if (panel.isInFloatingMode()) {
        final Window window = SwingUtilities.windowForComponent(panel);
        if (window != null) {
            window.addWindowFocusListener(listener);
        }
    } else {
        LafManager.getInstance().addLafManagerListener(listener);
    }
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Example 38 with MessageBusConnection

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

the class JarDirectoryWatcherImpl method cleanup.

private void cleanup() {
    if (!myWatchRequests.isEmpty()) {
        LocalFileSystem.getInstance().removeWatchedRoots(myWatchRequests);
        myWatchRequests = Collections.emptySet();
    }
    final MessageBusConnection connection = myBusConnection;
    if (connection != null) {
        myBusConnection = null;
        connection.disconnect();
    }
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Example 39 with MessageBusConnection

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

the class RootsChangedTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    MessageBusConnection connection = myProject.getMessageBus().connect(getTestRootDisposable());
    myModuleRootListener = new MyModuleRootListener();
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, myModuleRootListener);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection)

Example 40 with MessageBusConnection

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

the class MultiModuleEditingTest method testAddTwoModules.

public void testAddTwoModules() throws Exception {
    final MessageBusConnection connection = myProject.getMessageBus().connect();
    final MyModuleListener moduleListener = new MyModuleListener();
    connection.subscribe(ProjectTopics.MODULES, moduleListener);
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    final Module moduleA;
    final Module moduleB;
    {
        final ModifiableModuleModel modifiableModel = moduleManager.getModifiableModel();
        moduleA = modifiableModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
        moduleB = modifiableModel.newModule("b.iml", StdModuleTypes.JAVA.getId());
        assertEquals("Changes are not applied until commit", 0, moduleManager.getModules().length);
        //noinspection SSBasedInspection
        moduleListener.assertCorrectEvents(new String[0][]);
        ApplicationManager.getApplication().runWriteAction(modifiableModel::commit);
    }
    assertEquals(2, moduleManager.getModules().length);
    assertTrue(moduleManager.findModuleByName("a").equals(moduleA));
    assertTrue(moduleManager.findModuleByName("b").equals(moduleB));
    moduleListener.assertCorrectEvents(new String[][] { { "+a", "+b" } });
    {
        final ModifiableModuleModel modifiableModel = moduleManager.getModifiableModel();
        modifiableModel.disposeModule(moduleA);
        modifiableModel.disposeModule(moduleB);
        assertEquals("Changes are not applied until commit", 2, moduleManager.getModules().length);
        moduleListener.assertCorrectEvents(new String[][] { { "+a", "+b" } });
        ApplicationManager.getApplication().runWriteAction(modifiableModel::commit);
    }
    assertEquals(0, moduleManager.getModules().length);
    moduleListener.assertCorrectEvents(new String[][] { { "+a", "+b" }, { "-a", "-b" } });
    connection.disconnect();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

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