public void refreshSelection() { LibraryPlaylistsListCell cell = (LibraryPlaylistsListCell) _list.getSelectedValue(); if (cell == null) { // handle special case if (_model.getSize() == 2 && MediaPlayer.instance().getCurrentPlaylist() == null) { _list.setSelectedIndex(1); } return; } Playlist playlist = cell.getPlaylist(); if (playlist != null) { playlist.refresh(); LibraryMediator.instance().updateTableItems(playlist); String status = LibraryUtils.getPlaylistDurationInDDHHMMSS(playlist) + ", " + playlist.getItems().size() + " " + I18n.tr("tracks"); LibraryMediator.instance().getLibrarySearch().setStatus(status); } executePendingRunnables(); }
public void actionPerformed(ActionEvent e) { Playlist playlist = getSelectedPlaylist(); if (playlist != null) { List<File> files = new ArrayList<File>(); for (PlaylistItem item : playlist.getItems()) { File file = new File(item.getFilePath()); files.add(file); } iTunesMediator.instance().addSongsiTunes(playlist.getName(), files.toArray(new File[0])); } }
/** * Updates the Table based on the selection of the given table. Perform lookups to remove any * store files from the shared folder view and to only display store files in the store view */ void updateTableItems(Playlist playlist) { if (playlist == null) { return; } currentPlaylist = playlist; List<PlaylistItem> items = currentPlaylist.getItems(); clearTable(); for (final PlaylistItem item : items) { GUIMediator.safeInvokeLater( new Runnable() { @Override public void run() { addUnsorted(item); } }); } forceResort(); }
private void copyPlaylistFilesToFolder(Playlist playlist) { if (playlist == null || playlist.getItems().isEmpty()) { return; } File suggestedDirectory = FileChooserHandler.getLastInputDirectory(); if (suggestedDirectory.equals(CommonUtils.getCurrentDirectory())) { suggestedDirectory = new File(CommonUtils.getUserHomeDir(), "Desktop"); } final File selFolder = FileChooserHandler.getSaveAsDir( GUIMediator.getAppFrame(), I18nMarker.marktr("Where do you want the playlist files copied to?"), suggestedDirectory); if (selFolder == null) { return; } // let's make a copy of the list in case the playlist will be modified during the copying. final List<PlaylistItem> playlistItems = new ArrayList<>(playlist.getItems()); BackgroundExecutorService.schedule( new Thread("Library-copy-playlist-files") { @Override public void run() { int n = 0; int total = playlistItems.size(); String targetName = selFolder.getName(); for (PlaylistItem item : playlistItems) { File f = new File(item.getFilePath()); if (f.isFile() && f.exists() && f.canRead()) { try { Path source = f.toPath(); Path target = FileSystems.getDefault().getPath(selFolder.getAbsolutePath(), f.getName()); Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); n++; // invoked on UI thread later String status = String.format("Copied %d of %d to %s", n, total, targetName); LibraryMediator.instance().getLibrarySearch().pushStatus(status); } catch (IOException e) { e.printStackTrace(); } } } GUIMediator.launchExplorer(selFolder); // and clear the output try { Thread.sleep(2000); LibraryMediator.instance().getLibrarySearch().pushStatus(""); } catch (InterruptedException e) { } } }); }