void (@NotNull Runnable runnable, @Nullable Disposable parent) { TreeSelectionListener listener = new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { runnable.run(); } }; addTreeSelectionListener(listener); if (parent != null) Disposer.register(parent, () -> removeTreeSelectionListener(listener)); }