From 48a368e4101fbf23d532fa15f741670f0c4871c5 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Wed, 24 Feb 2016 23:25:34 +0000 Subject: [PATCH] Library can now be recognised as empty. --- src/main/java/musicplayer/PlayerGUI.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java index 2f39c03..63a47c9 100644 --- a/src/main/java/musicplayer/PlayerGUI.java +++ b/src/main/java/musicplayer/PlayerGUI.java @@ -98,9 +98,9 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf * @param libraryData List of songs. */ private void populateLibrary(List libraryData) { - Collections.sort(libraryData); DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode()); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) model.getRoot(); + Collections.sort(libraryData); libraryData.forEach(x -> addNodeToTreeModel(model, parentNode, new DefaultMutableTreeNode(x))); libraryView.setModel(model); } @@ -172,6 +172,9 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf playlistTableModel.removeSong(invalidSong); } + /** + * Refresh the library with songs in the currently selected display format. + */ public void refreshLibrary() { DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode()); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) model.getRoot(); @@ -180,6 +183,14 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf libraryView.setModel(model); Thread populateThread = new Thread(() -> { libraryDisplayVariants.get(libraryDisplayType.getSelectedItem().toString()).run(); + // If we get here and the model hasn't changed, the library must be empty. + if(libraryView.getModel() == model){ + DefaultTreeModel failedModel = new DefaultTreeModel(new DefaultMutableTreeNode()); + DefaultMutableTreeNode failedParentNode = (DefaultMutableTreeNode) failedModel.getRoot(); + DefaultMutableTreeNode failedNode = new DefaultMutableTreeNode("Library is empty!"); + addNodeToTreeModel(failedModel, failedParentNode, failedNode); + libraryView.setModel(failedModel); + } }); populateThread.start(); }