Search in sources :

Example 56 with MessageBusConnection

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

the class PostProjectBuildTasksExecutor method subscribe.

/**
   * This method is used for testing only. For production code, please use
   * {@link AndroidProjectBuildNotifications#subscribe(Project, AndroidProjectBuildNotifications.AndroidProjectBuildListener)}.
   */
@VisibleForTesting
public static void subscribe(@NotNull Project project, @NotNull GradleBuildListener listener) {
    MessageBusConnection connection = project.getMessageBus().connect(project);
    connection.subscribe(GRADLE_BUILD_TOPIC, listener);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 57 with MessageBusConnection

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

the class GradleFacet method initFacet.

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

        @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) ModuleRootAdapter(com.intellij.openapi.roots.ModuleRootAdapter) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent)

Example 58 with MessageBusConnection

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

the class AndroidToolWindowFactory method createLogcatContent.

private static Content createLogcatContent(RunnerLayoutUi layoutUi, final Project project, DeviceContext deviceContext) {
    final AndroidLogcatView logcatView = new AndroidLogcatView(project, deviceContext) {

        @Override
        protected boolean isActive() {
            ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID);
            return window.isVisible();
        }
    };
    ToolWindowManagerEx.getInstanceEx(project).addToolWindowManagerListener(new ToolWindowManagerAdapter() {

        boolean myToolWindowVisible;

        @Override
        public void stateChanged() {
            ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID);
            if (window != null) {
                boolean visible = window.isVisible();
                if (visible != myToolWindowVisible) {
                    myToolWindowVisible = visible;
                    logcatView.activate();
                    if (visible) {
                        ConsoleView console = logcatView.getLogConsole().getConsole();
                        if (console != null) {
                            checkFacetAndSdk(project, console);
                        }
                    }
                }
            }
        }
    });
    final MessageBusConnection connection = project.getMessageBus().connect(project);
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyAndroidPlatformListener(logcatView));
    JPanel logcatContentPanel = logcatView.getContentPanel();
    final Content logcatContent = layoutUi.createContent(ANDROID_LOGCAT_CONTENT_ID, logcatContentPanel, "logcat", AndroidIcons.Ddms.Logcat, null);
    logcatContent.putUserData(AndroidLogcatView.ANDROID_LOGCAT_VIEW_KEY, logcatView);
    logcatContent.setDisposer(logcatView);
    logcatContent.setCloseable(false);
    logcatContent.setPreferredFocusableComponent(logcatContentPanel);
    return logcatContent;
}
Also used : AndroidLogcatView(com.android.tools.idea.logcat.AndroidLogcatView) ToolWindow(com.intellij.openapi.wm.ToolWindow) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ConsoleView(com.intellij.execution.ui.ConsoleView) Content(com.intellij.ui.content.Content) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter)

Example 59 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 60 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)

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