private void rememberScrollbarsOnMediators(String key) {
    AbstractLibraryTableMediator<?, ?, ?> tableMediator = null;
    AbstractLibraryListPanel listPanel = null;

    if (key.equals(FILES_TABLE_KEY)) {
      tableMediator = LibraryFilesTableMediator.instance();
      listPanel = getLibraryExplorer();
    } else if (key.equals(PLAYLISTS_TABLE_KEY)) {
      tableMediator = LibraryPlaylistsTableMediator.instance();
      listPanel = getLibraryPlaylists();
    } else if (key.equals(DEVICE_TABLE_KEY)) {
      tableMediator = LibraryDeviceTableMediator.instance();
      listPanel = getLibraryExplorer();
    }

    if (tableMediator == null || listPanel == null) {
      // nice antipattern here.
      return;
    }

    if (lastSelectedMediator != null && lastSelectedKey != null) {
      scrollbarValues.put(lastSelectedKey, lastSelectedMediator.getScrollbarValue());
    }

    lastSelectedMediator = tableMediator;
    lastSelectedKey = getSelectedKey();

    if (listPanel.getPendingRunnables().size() == 0) {
      int lastScrollValue =
          scrollbarValues.containsKey(lastSelectedKey) ? scrollbarValues.get(lastSelectedKey) : 0;

      tableMediator.scrollTo(lastScrollValue);
    }
  }
  /**
   * If a file has been selected on the right hand side, this method will select such file.
   *
   * <p>If there's a radio station, or if there's more than one file selected, or none, it will
   * return null.
   *
   * @return
   */
  public File getSelectedFile() {
    File toExplore = null;

    DirectoryHolder selectedDirectoryHolder =
        LibraryMediator.instance().getLibraryExplorer().getSelectedDirectoryHolder();
    boolean fileBasedDirectoryHolderSelected =
        selectedDirectoryHolder instanceof SavedFilesDirectoryHolder
            || selectedDirectoryHolder instanceof MediaTypeSavedFilesDirectoryHolder
            || selectedDirectoryHolder instanceof TorrentDirectoryHolder;

    if (fileBasedDirectoryHolderSelected
        && LibraryFilesTableMediator.instance().getSelectedLines().size() == 1) {
      toExplore = LibraryFilesTableMediator.instance().getSelectedLines().get(0).getFile();

    } else if (LibraryPlaylistsTableMediator.instance().getSelectedLines() != null
        && LibraryPlaylistsTableMediator.instance().getSelectedLines().size() == 1) {
      toExplore = LibraryPlaylistsTableMediator.instance().getSelectedLines().get(0).getFile();
    }
    return toExplore;
  }
  public void showView(String key) {
    rememberScrollbarsOnMediators(key);
    _tablesViewLayout.show(_tablesPanel, key);

    if (key.equals(FILES_TABLE_KEY)) {
      currentMediator = LibraryFilesTableMediator.instance();
    } else if (key.equals(PLAYLISTS_TABLE_KEY)) {
      currentMediator = LibraryPlaylistsTableMediator.instance();
    } else if (key.equals(INTERNET_RADIO_TABLE_KEY)) {
      currentMediator = LibraryInternetRadioTableMediator.instance();
    } else if (key.equals(DEVICE_TABLE_KEY)) {
      currentMediator = LibraryDeviceTableMediator.instance();
    } else {
      currentMediator = null;
    }
  }
  private JComponent getLibraryRightPanel() {
    JPanel panel = new JPanel(new BorderLayout());

    _tablesViewLayout = new CardLayout();
    _tablesPanel = new JPanel(_tablesViewLayout);

    _tablesPanel.add(LibraryFilesTableMediator.instance().getComponent(), FILES_TABLE_KEY);
    _tablesPanel.add(LibraryPlaylistsTableMediator.instance().getComponent(), PLAYLISTS_TABLE_KEY);
    _tablesPanel.add(
        LibraryInternetRadioTableMediator.instance().getComponent(), INTERNET_RADIO_TABLE_KEY);
    _tablesPanel.add(LibraryDeviceTableMediator.instance().getComponent(), DEVICE_TABLE_KEY);

    panel.add(getLibrarySearch(), BorderLayout.PAGE_START);
    panel.add(_tablesPanel, BorderLayout.CENTER);

    return panel;
  }
 public void setSelectedFile(File file) {
   getLibraryExplorer().selectFinishedDownloads();
   LibraryFilesTableMediator.instance().setFileSelected(file);
 }
 public void addFilesToLibraryTable(List<File> files) {
   for (File file : files) {
     LibraryFilesTableMediator.instance().add(file);
   }
   getLibrarySearch().addResults(files.size());
 }
 public void clearLibraryTable() {
   LibraryFilesTableMediator.instance().clearTable();
   LibraryPlaylistsTableMediator.instance().clearTable();
   LibraryDeviceTableMediator.instance().clearTable();
   getLibrarySearch().clear();
 }
 public void updateTableFiles(DirectoryHolder dirHolder) {
   clearLibraryTable();
   showView(FILES_TABLE_KEY);
   LibraryFilesTableMediator.instance().updateTableFiles(dirHolder);
 }