//Allow for clearing entire playlist
private void createRowFactory(){
        //Play selected song from playlist, to skip forward or back
        tableView.setRowFactory( tv -> {
            TableRow<PlaylistSongDisplay> row = new TableRow<>();
            row.setOnMouseClicked(event -> {
                //On double click of song, play it
                if (event.getClickCount() == 2 && (! row.isEmpty()) ) {
                    playlist.playPlaylistSelection(songHashMap.get(row.getItem()));
                }
                //On right click open context menu
                if (event.getButton() == MouseButton.SECONDARY) {
                    ObservableList<PlaylistSongDisplay> selectedItems = tableView.getSelectionModel().getSelectedItems();
                    ArrayList<Song> selectedIDs = new ArrayList<>();
                    for (PlaylistSongDisplay rowSelected : selectedItems) {
                        selectedIDs.add(songHashMap.get(rowSelected));
                    }
                    //Allow for removal of selected songs from playlist
                    removeSelected.setOnAction((actionEvent -> {
                        playlist.removePlaylistSelection(selectedIDs);
                        for (Song s: selectedIDs){
                            playlistList.remove(songHashMapRev.get(s));
                        }
                    }));
                    //Allow for clearing entire playlist
                    clearPlaylist.setOnAction(actionEvent -> {
                        playlist.clearPlaylist();
                        emptyTable();
                    });
                    //Show context menu at location of click
                    playlistContextMenu.show(row, event.getScreenX(), event.getScreenY());
                }
                //Undo selection if user clicks away from focused row
                if (event.getButton() == MouseButton.PRIMARY && (row.isEmpty())){
                    tableView.getSelectionModel().clearSelection();
                }
            });
            return row;
        });
        //TODO: Add drag listener to move songs around as desired
    }
}
}));
//Allow for clearing entire playlist
clearPlaylist.setOnAction(actionEvent -> {
playlist.clearPlaylist();
for (PlaylistSongDisplay rowSelected : selectedItems) {
selectedIDs.add(songHashMap.get(rowSelected));
}
//Allow for removal of selected songs from playlist
removeSelected.setOnAction((actionEvent -> {
playlist.removePlaylistSelection(selectedIDs);
for (Song s: selectedIDs){
playlistList.remove(songHashMapRev.get(s));
}
}));
//Allow for clearing entire playlist
clearPlaylist.setOnAction(actionEvent -> {
playlist.clearPlaylist();
emptyTable();
});
//Show context menu at location of click
playlistContextMenu.show(row, event.getScreenX(), event.getScreenY());
}
//Undo selection if user clicks away from focused row
if (event.getButton() == MouseButton.PRIMARY && (row.isEmpty())){
tableView.getSelectionModel().clearSelection();
TableRow<PlaylistSongDisplay> row = new TableRow<>();
row.setOnMouseClicked(event -> {
//On double click of song, play it
if (event.getClickCount() == 2 && (! row.isEmpty()) ) {
playlist.playPlaylistSelection(songHashMap.get(row.getItem()));
}
//On right click open context menu
if (event.getButton() == MouseButton.SECONDARY) {
ObservableList<PlaylistSongDisplay> selectedItems = tableView.getSelectionModel().getSelectedItems();
ArrayList<Song> selectedIDs = new ArrayList<>();
for (PlaylistSongDisplay rowSelected : selectedItems) {
selectedIDs.add(songHashMap.get(rowSelected));
}
//Allow for removal of selected songs from playlist
removeSelected.setOnAction((actionEvent -> {
playlist.removePlaylistSelection(selectedIDs);
for (Song s: selectedIDs){
playlistList.remove(songHashMapRev.get(s));
}
}));
//Allow for clearing entire playlist
clearPlaylist.setOnAction(actionEvent -> {
playlist.clearPlaylist();
emptyTable();
});
//Show context menu at location of click
playlistContextMenu.show(row, event.getScreenX(), event.getScreenY());
}
//Undo selection if user clicks away from focused row
if (event.getButton() == MouseButton.PRIMARY && (row.isEmpty())){
tableView.getSelectionModel().clearSelection();
}
});
return row;
});
//TODO: Add drag listener to move songs around as desired
}