Maybe a command (/treeview or whatever) could do the expanding/collapsing and whatever the interface allows you to do, and the connection switching triggers could be simply scripted then. A /switchbar could be nice in the same way.