private void refresh() {
    if (accountCursor == null) {
      return;
    }
    if (accountCursor.isClosed()) {
      return;
    }

    Account currentAccount = SessionUtils.getAccount(getActivity());
    if (currentAccount == null) {
      currentAccount = AccountsPreferences.getDefaultAccount(getActivity());
    }

    if (currentAccount == null) {
      return;
    }

    for (int i = 0; i < accountCursor.getCount(); i++) {
      accountCursor.moveToPosition(i);
      if (accountCursor.getLong(AccountSchema.COLUMN_ID_ID) == currentAccount.getId()) {
        accountIndex = accountCursor.getPosition();
        break;
      }
    }

    spinnerAccount.setSelection(accountIndex);
  }
 @Override
 public void onListItemClick(ListView l, View v, int position, long id) {
   super.onListItemClick(l, v, position, id);
   CloudNetwork network = (CloudNetwork) l.getItemAtPosition(position);
   Account currentAccount = SessionUtils.getAccount(getActivity());
   if (currentAccount != null
       && !currentAccount.getRepositoryId().equals(network.getIdentifier())) {
     ActionManager.reloadAccount(getActivity(), currentAccount, network.getIdentifier());
   }
 }
 public void hideWorkflowMenu(Account currentAccount) {
   if (rootView == null || rootView.findViewById(R.id.menu_workflow) == null) {
     return;
   }
   if (currentAccount.getTypeId() == Account.TYPE_ALFRESCO_CLOUD
       || currentAccount.getTypeId() == Account.TYPE_ALFRESCO_TEST_OAUTH) {
     rootView.findViewById(R.id.menu_workflow).setVisibility(View.GONE);
   } else {
     rootView.findViewById(R.id.menu_workflow).setVisibility(View.VISIBLE);
   }
 }
  private void display() {
    Account acc = SessionUtils.getAccount(getActivity());

    rootView.findViewById(R.id.menu_browse_activities).setVisibility(View.VISIBLE);
    rootView.findViewById(R.id.menu_browse_root).setVisibility(View.VISIBLE);
    rootView.findViewById(R.id.menu_browse_my_sites).setVisibility(View.VISIBLE);
    if (acc != null && acc.getTypeId() == Account.TYPE_ALFRESCO_CLOUD) {
      rootView.findViewById(R.id.menu_workflow).setVisibility(View.GONE);
    } else {
      rootView.findViewById(R.id.menu_workflow).setVisibility(View.VISIBLE);
    }
    rootView.findViewById(R.id.menu_favorites).setVisibility(View.VISIBLE);
    rootView.findViewById(R.id.menu_search).setVisibility(View.VISIBLE);
    rootView.findViewById(R.id.menu_downloads).setVisibility(View.VISIBLE);
    rootView.findViewById(R.id.menu_notifications).setVisibility(View.VISIBLE);
    rootView.findViewById(R.id.menu_browse_shared).setVisibility(View.GONE);
    rootView.findViewById(R.id.menu_browse_userhome).setVisibility(View.GONE);
  }
  // ///////////////////////////////////////////////////////////////////////////
  // DROPDOWN EVENTS
  // ///////////////////////////////////////////////////////////////////////////
  @Override
  public void onItemSelected(
      AdapterView<?> parentView, View selectedItemView, int position, long id) {
    Cursor cursor = (Cursor) parentView.getItemAtPosition(position);
    int accountId = cursor.getInt(AccountSchema.COLUMN_ID_ID);

    switch (accountId) {
      case AccountCursorAdapter.NETWORK_ITEM:
        ((MainActivity) getActivity()).displayNetworks();
        hideSlidingMenu(false);
        break;
      case AccountCursorAdapter.MANAGE_ITEM:
        ((MainActivity) getActivity()).displayAccounts();
        hideSlidingMenu(false);
        break;

      default:
        Account currentAccount = SessionUtils.getAccount(getActivity());
        if (currentAccount != null
            && cursor.getCount() > 1
            && currentAccount.getId() != cursor.getLong(AccountSchema.COLUMN_ID_ID)) {
          hideSlidingMenu(true);

          // Request session loading for the selected account.
          LocalBroadcastManager.getInstance(getActivity())
              .sendBroadcast(
                  new Intent(IntentIntegrator.ACTION_LOAD_ACCOUNT)
                      .putExtra(
                          IntentIntegrator.EXTRA_ACCOUNT_ID,
                          cursor.getLong(AccountSchema.COLUMN_ID_ID)));

          // Update dropdown menu (eventual new items to display)
          cursorAdapter.swapCursor(
              AccountCursorAdapter.createMergeCursor(getActivity(), accountCursor));
        }
        break;
    }
  }