// inherit doc comment
  protected JPopupMenu createPopupMenu() {
    if (TABLE.getSelectionModel().isSelectionEmpty()) {
      return null;
    }

    JPopupMenu menu = new SkinPopupMenu();

    menu.add(new SkinMenuItem(LAUNCH_ACTION));
    if (getMediaType().equals(MediaType.getAudioMediaType())) {
      menu.add(new SkinMenuItem(LAUNCH_OS_ACTION));
    }
    if (hasExploreAction()) {
      menu.add(new SkinMenuItem(OPEN_IN_FOLDER_ACTION));
    }

    if (areAllSelectedFilesMP4s()) {
      menu.add(DEMUX_MP4_AUDIO_ACTION);
      DEMUX_MP4_AUDIO_ACTION.setEnabled(
          !((DemuxMP4AudioAction) DEMUX_MP4_AUDIO_ACTION).isDemuxing());
    }

    menu.add(new SkinMenuItem(CREATE_TORRENT_ACTION));

    if (areAllSelectedFilesPlayable()) {
      menu.add(createAddToPlaylistSubMenu());
    }

    menu.add(new SkinMenuItem(SEND_TO_FRIEND_ACTION));
    menu.add(new SkinMenuItem(SEND_TO_ITUNES_ACTION));

    menu.addSeparator();
    menu.add(new SkinMenuItem(DELETE_ACTION));
    menu.addSeparator();

    int[] rows = TABLE.getSelectedRows();
    boolean dirSelected = false;
    boolean fileSelected = false;

    for (int i = 0; i < rows.length; i++) {
      File f = DATA_MODEL.get(rows[i]).getFile();
      if (f.isDirectory()) {
        dirSelected = true;
        //				if (IncompleteFileManager.isTorrentFolder(f))
        //					torrentSelected = true;
      } else fileSelected = true;

      if (dirSelected && fileSelected) break;
    }

    DELETE_ACTION.setEnabled(true);
    LibraryFilesTableDataLine line = DATA_MODEL.get(rows[0]);
    menu.add(createSearchSubMenu(line));
    return menu;
  }
  /**
   * Handles the selection rows in the library window, enabling or disabling buttons and chat menu
   * items depending on the values in the selected rows.
   *
   * @param row the index of the first row that is selected
   */
  public void handleSelection(int row) {
    int[] sel = TABLE.getSelectedRows();
    if (sel.length == 0) {
      handleNoSelection();
      return;
    }

    File selectedFile = getFile(sel[0]);

    //  always turn on Launch, Delete, Magnet Lookup, Bitzi Lookup
    LAUNCH_ACTION.setEnabled(true);
    LAUNCH_OS_ACTION.setEnabled(true);
    DELETE_ACTION.setEnabled(true);

    if (selectedFile != null && !selectedFile.getName().endsWith(".torrent")) {
      CREATE_TORRENT_ACTION.setEnabled(sel.length == 1);
    }

    if (selectedFile != null) {
      SEND_TO_FRIEND_ACTION.setEnabled(sel.length == 1);

      if (getMediaType().equals(MediaType.getAnyTypeMediaType())) {
        boolean atLeastOneIsPlayable = false;

        for (int i : sel) {
          File f = getFile(i);
          if (MediaPlayer.isPlayableFile(f) || hasExtension(f.getAbsolutePath(), "mp4")) {
            atLeastOneIsPlayable = true;
            break;
          }
        }

        SEND_TO_ITUNES_ACTION.setEnabled(atLeastOneIsPlayable);
      } else {
        SEND_TO_ITUNES_ACTION.setEnabled(
            getMediaType().equals(MediaType.getAudioMediaType())
                || hasExtension(selectedFile.getAbsolutePath(), "mp4"));
      }
    }

    if (sel.length == 1 && selectedFile.isFile() && selectedFile.getParentFile() != null) {
      OPEN_IN_FOLDER_ACTION.setEnabled(true);
    } else {
      OPEN_IN_FOLDER_ACTION.setEnabled(false);
    }

    if (sel.length == 1) {
      LibraryMediator.instance().getLibraryCoverArt().setFile(selectedFile);
    }

    //        boolean anyBeingShared = isAnyBeingShared();
    //        WIFI_SHARE_ACTION.setEnabled(!anyBeingShared);
    //        WIFI_UNSHARE_ACTION.setEnabled(!anyBeingShared);
  }
 /**
  * Handles the deselection of all rows in the library table, disabling all necessary buttons and
  * menu items.
  */
 public void handleNoSelection() {
   LAUNCH_ACTION.setEnabled(false);
   LAUNCH_OS_ACTION.setEnabled(false);
   OPEN_IN_FOLDER_ACTION.setEnabled(false);
   SEND_TO_FRIEND_ACTION.setEnabled(false);
   CREATE_TORRENT_ACTION.setEnabled(false);
   DELETE_ACTION.setEnabled(false);
   SEND_TO_ITUNES_ACTION.setEnabled(false);
 }