private void loadList() {
    final JDialog form = this;
    final ReadOnlyCellTableModel model = (ReadOnlyCellTableModel) subscriptionTable.getModel();

    while (model.getRowCount() > 0) model.removeRow(0);

    form.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    Vector<String> vector = new Vector<String>();
    vector.add("(loading... )");
    vector.add("");
    model.addRow(vector);

    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              @Override
              public void run() {
                try {

                  while (model.getRowCount() > 0) model.removeRow(0);

                  subscriptionList = AzureRestAPIManager.getManager().getSubscriptionList();

                  if (subscriptionList != null && subscriptionList.size() > 0) {
                    for (Subscription subs : subscriptionList) {
                      Vector<String> row = new Vector<String>();
                      row.add(subs.getName());
                      row.add(subs.getId().toString());
                      model.addRow(row);
                    }

                    removeButton.setEnabled(true);
                  } else {
                    removeButton.setEnabled(false);
                  }

                  form.setCursor(Cursor.getDefaultCursor());
                } catch (AzureCmdException e) {
                  form.setCursor(Cursor.getDefaultCursor());
                  UIHelper.showException("Error getting subscription list", e);
                }
              }
            });
  }
  private void fillList() {
    model.setService(null);
    model.getCurrentNavigationState().NEXT.setEnabled(false);
    serviceList = new ArrayList<Service>();
    mobileServices.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    final ReadOnlyCellTableModel messageTableModel = new ReadOnlyCellTableModel();
    messageTableModel.addColumn("Message");
    Vector<String> vector = new Vector<String>();
    vector.add("(loading... )");
    messageTableModel.addRow(vector);

    mobileServices.setModel(messageTableModel);

    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              @Override
              public void run() {
                int selectedIndex = -1;

                try {
                  List<Subscription> subscriptionList =
                      AzureRestAPIManager.getManager().getSubscriptionList();

                  if (subscriptionList != null && subscriptionList.size() > 0) {
                    buttonAddService.setEnabled(true);

                    ReadOnlyCellTableModel serviceTableModel = new ReadOnlyCellTableModel();
                    serviceTableModel.addColumn("Name");
                    serviceTableModel.addColumn("Region");
                    serviceTableModel.addColumn("Type");
                    serviceTableModel.addColumn("Subscription");

                    int rowIndex = 0;

                    for (Subscription s : subscriptionList) {
                      List<Service> currentSubServices =
                          AzureRestAPIManager.getManager().getServiceList(s.getId());

                      for (Service service : currentSubServices) {
                        Vector<String> row = new Vector<String>();
                        row.add(service.getName());
                        row.add(service.getRegion());
                        row.add("Mobile service");
                        row.add(s.getName());

                        serviceTableModel.addRow(row);
                        serviceList.add(service);

                        if (model.getService() != null
                            && model.getService().getName().equals(service.getName())
                            && model
                                .getService()
                                .getSubcriptionId()
                                .toString()
                                .equals(service.getSubcriptionId().toString())) {
                          selectedIndex = rowIndex;
                        }

                        rowIndex++;
                      }
                    }

                    if (rowIndex == 0) {
                      while (messageTableModel.getRowCount() > 0) {
                        messageTableModel.removeRow(0);
                      }

                      Vector<String> vector = new Vector<String>();
                      vector.add(
                          "There are no Azure Mobile Services on the imported subscriptions");
                      messageTableModel.addRow(vector);

                      mobileServices.setModel(messageTableModel);
                    } else {
                      mobileServices.setModel(serviceTableModel);
                    }
                  } else {
                    buttonAddService.setEnabled(false);

                    while (messageTableModel.getRowCount() > 0) {
                      messageTableModel.removeRow(0);
                    }

                    Vector<String> vector = new Vector<String>();
                    vector.add("Please sign in/import your Azure subscriptions.");
                    messageTableModel.addRow(vector);
                    mobileServices.setModel(messageTableModel);

                    buttonEdit.doClick();
                  }
                } catch (Throwable ex) {
                  UIHelper.showException("Error retrieving service list", ex);
                  serviceList.clear();

                  while (messageTableModel.getRowCount() > 0) {
                    messageTableModel.removeRow(0);
                  }

                  Vector<String> vector = new Vector<String>();
                  vector.add(
                      "There has been an error while loading the list of Azure Mobile Services");
                  messageTableModel.addRow(vector);
                  mobileServices.setModel(messageTableModel);
                }

                mobileServices.getSelectionModel().clearSelection();

                if (selectedIndex >= 0) {
                  mobileServices.getSelectionModel().setLeadSelectionIndex(selectedIndex);
                }
              }
            },
            this.modalityState);
  }