private void selectDownloadToShowOnDownloadGrid() {
   DownloadWrapper d = null;
   if (table.getSelectedRow() == -1) {
     d = selectDownloadToShowOnDownloadGridIgnoringSelection();
   } else {
     DownloadWrapper dw = rows.get(table.getSelectedRow());
     if (dw != null
         && dw.download != null
         && !dw.download.isComplete()
         && dw.download.isActive()) {
       d = dw;
     } else {
       d = selectDownloadToShowOnDownloadGridIgnoringSelection();
     }
   }
   if (d != null && downloadGrid != null) {
     downloadGrid.setDownload(d.download);
   }
   interestingDownloadWrapper = d;
 }
  public void update() {
    boolean structureChanged = false;

    ArrayList<Download> al =
        new ArrayList<Download>(ui.getCore().getNetworkManager().getDownloadManager().downloads());
    for (Download d : al) {
      DownloadWrapper dw = getWrapperFor(d);
      if (dw == null) {
        structureChanged = true;
        dw = new DownloadWrapper(d);
        rows.add(dw);
      }
      dw.update();
    }

    for (Iterator i = rows.iterator(); i.hasNext(); ) {
      DownloadWrapper w = (DownloadWrapper) i.next();
      if (!ui.getCore().getNetworkManager().getDownloadManager().contains(w.download)) {
        structureChanged = true;
        i.remove();
      }
    }

    if (structureChanged) {
      model.fireTableStructureChanged();
    } else {
      model.fireTableRowsUpdated(0, rows.size());
    }

    showTotalBytesReceived();

    selectDownloadToShowOnDownloadGrid();

    updateDownloadingFromAndUploadingToText();

    downloadGrid.repaint();
  }