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); } } }
static void unsubscribeFrom(NavBarPanel panel) { final NavBarListener listener = (NavBarListener) panel.getClientProperty(LISTENER); panel.putClientProperty(LISTENER, null); if (listener != null) { final Project project = panel.getProject(); KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(listener); FileStatusManager.getInstance(project).removeFileStatusListener(listener); PsiManager.getInstance(project).removePsiTreeChangeListener(listener); WolfTheProblemSolver.getInstance(project).removeProblemListener(listener); ActionManager.getInstance().removeAnActionListener(listener); final MessageBusConnection connection = (MessageBusConnection) panel.getClientProperty(BUS); panel.putClientProperty(BUS, null); if (connection != null) { connection.disconnect(); } } }