Choose Collapse All from the File menu to close an expanded namespace. You can also double click on the root directory to close an expanded directory.