Disposable (@NotNull NavBarPanel panel) { Disposable disposable = Disposer.newDisposable(); Disposable old = (Disposable)panel.getClientProperty(LISTENER); if (old != null) { Disposer.dispose(old); panel.putClientProperty(LISTENER, null); } final NavBarListener listener = new NavBarListener(panel); final Project project = panel.getProject(); if (project.isDisposed()) { return disposable; } panel.putClientProperty(LISTENER, disposable); FocusUtil.addFocusOwnerListener(disposable, listener); PsiManager.getInstance(project).addPsiTreeChangeListener(listener, disposable); MessageBusConnection connection = project.getMessageBus().connect(disposable); connection.subscribe(FileStatusListener.TOPIC, listener); connection.subscribe(AnActionListener.TOPIC, listener); connection.subscribe(ModuleRootListener.TOPIC, listener); connection.subscribe(AdditionalLibraryRootsListener.TOPIC, listener); connection.subscribe(NavBarModelListener.NAV_BAR, listener); connection.subscribe(ProblemListener.TOPIC, listener); connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener); connection.subscribe(DynamicPluginListener.TOPIC, listener); connection.subscribe(VirtualFileAppearanceListener.TOPIC, listener); panel.addKeyListener(listener); Disposer.register(disposable, ()->panel.removeKeyListener(listener)); if (panel.isInFloatingMode()) { Window window = SwingUtilities.windowForComponent(panel); if (window != null) { window.addWindowFocusListener(listener); Disposer.register(disposable, ()->window.removeWindowFocusListener(listener)); } } else { ApplicationManager.getApplication().getMessageBus().connect(connection).subscribe(LafManagerListener.TOPIC, listener); } return disposable; }