@Override
 public boolean onContextItemSelected(MenuItem item) {
   AdapterView.AdapterContextMenuInfo menuInfo =
       (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
   long id = menuInfo.id;
   if (item.getItemId() == R.id.context_menu_collapse) {
     mTreeStateManager.collapseChildren(id);
     return true;
   } else if (item.getItemId() == R.id.context_menu_expand_all) {
     mTreeStateManager.expandEverythingBelow(id);
     return true;
   } else if (item.getItemId() == R.id.context_menu_expand_item) {
     mTreeStateManager.expandDirectChildren(id);
     return true;
   } else if (item.getItemId() == R.id.context_menu_delete) {
     mTreeStateManager.removeNodeRecursively(id);
     return true;
   } else {
     return super.onContextItemSelected(item);
   }
 }
 private void collapseAll() {
   if (mTreeStateManager != null) mTreeStateManager.collapseChildren(null);
 }