Search in sources :

Example 76 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection 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 77 with MessageBusConnection

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

the class MxmlPreviewToolWindowManager method initToolWindow.

private void initToolWindow() {
    toolWindowForm = new MxmlPreviewToolWindowForm();
    String toolWindowId = FlashUIDesignerBundle.message("mxml.preview.tool.window.title");
    toolWindow = ToolWindowManager.getInstance(project).registerToolWindow(toolWindowId, false, ToolWindowAnchor.RIGHT, project, false);
    toolWindow.setIcon(PlatformIcons.UI_FORM_ICON);
    PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(project);
    toolWindowVisible = propertiesComponent.getBoolean(SETTINGS_TOOL_WINDOW_VISIBLE);
    if (toolWindowVisible) {
        toolWindow.show(null);
    } else {
        toolWindow.hide(null);
    }
    ((ToolWindowManagerEx) ToolWindowManager.getInstance(project)).addToolWindowManagerListener(new ToolWindowManagerAdapter() {

        @Override
        public void stateChanged() {
            if (project.isDisposed() || toolWindow == null || !toolWindow.isAvailable()) {
                return;
            }
            final boolean currentVisible = toolWindow.isVisible();
            if (currentVisible == toolWindowVisible) {
                return;
            }
            toolWindowVisible = currentVisible;
            PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(project);
            if (currentVisible) {
                propertiesComponent.setValue(SETTINGS_TOOL_WINDOW_VISIBLE, true);
                if (!lastPreviewChecked) {
                    lastPreviewChecked = true;
                    if (checkLastImage()) {
                        return;
                    }
                }
                render(true, false);
            } else {
                propertiesComponent.unsetValue(SETTINGS_TOOL_WINDOW_VISIBLE);
            }
        }
    });
    JPanel contentPanel = toolWindowForm.getContentPanel();
    ContentManager contentManager = toolWindow.getContentManager();
    Content content = contentManager.getFactory().createContent(contentPanel, null, false);
    content.setCloseable(false);
    content.setPreferredFocusableComponent(contentPanel);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content, true);
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(project);
    connection.subscribe(DesignerApplicationManager.MESSAGE_TOPIC, new DocumentRenderedListener() {

        private boolean isApplicable(DocumentFactoryManager.DocumentInfo info) {
            return toolWindowVisible && toolWindowForm.getFile() != null && info.equals(DocumentFactoryManager.getInstance().getNullableInfo(toolWindowForm.getFile()));
        }

        @Override
        public void documentRendered(DocumentFactoryManager.DocumentInfo info) {
            if (isApplicable(info) && !toolWindowForm.waitingForGetDocument) {
                UIUtil.invokeLaterIfNeeded(() -> render(false, false));
            }
        }

        @Override
        public void errorOccurred() {
        }
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ContentManager(com.intellij.ui.content.ContentManager) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) Content(com.intellij.ui.content.Content) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 78 with MessageBusConnection

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

the class AppTest method applicationLaunchedAndInitialized.

@Override
protected void applicationLaunchedAndInitialized() {
    ((MySocketInputHandler) SocketInputHandler.getInstance()).fail = fail;
    ((MySocketInputHandler) SocketInputHandler.getInstance()).semaphore = semaphore;
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(myModule);
    connection.subscribe(DesignerApplicationManager.MESSAGE_TOPIC, new DocumentRenderedListener() {

        @Override
        public void documentRendered(DocumentInfo info) {
            semaphore.up();
        }

        @Override
        public void errorOccurred() {
            fail.set(true);
            semaphore.up();
        }
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) DocumentInfo(com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)

Example 79 with MessageBusConnection

use of com.intellij.util.messages.MessageBusConnection 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 80 with MessageBusConnection

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

the class BndLaunchState method startProcess.

@NotNull
@Override
protected OSProcessHandler startProcess() throws ExecutionException {
    OSProcessHandler handler = super.startProcess();
    MessageBusConnection connection = myProject.getMessageBus().connect();
    connection.subscribe(CompilerTopics.COMPILATION_STATUS, this);
    HotSwapUI hotSwapManager = HotSwapUI.getInstance(myProject);
    hotSwapManager.addListener(this);
    handler.addProcessListener(new ProcessAdapter() {

        @Override
        public void processTerminated(ProcessEvent event) {
            connection.disconnect();
            hotSwapManager.removeListener(BndLaunchState.this);
            myLauncher.cleanup();
        }
    });
    return handler;
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) HotSwapUI(com.intellij.debugger.ui.HotSwapUI) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

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