No longer unnecessarily storing search value.
This commit is contained in:
parent
a8841b210b
commit
b91729004b
@ -37,7 +37,6 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
|
||||
private final JXTextField librarySearchField = new JXTextField();
|
||||
final JTree libraryTree = new JTree();
|
||||
private final Map<String, Runnable> libraryDisplayVariants = createDisplayVariantMap();
|
||||
private String filterValue = "";
|
||||
|
||||
/**
|
||||
* @return Map of display types for the library paired code to populate the library with data in the correct format.
|
||||
@ -72,10 +71,7 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
|
||||
}
|
||||
});
|
||||
librarySearchField.setPrompt("Search... (Press Enter)");
|
||||
librarySearchField.addActionListener(e ->{
|
||||
filterValue = librarySearchField.getText();
|
||||
refreshLibrary();
|
||||
});
|
||||
librarySearchField.addActionListener(e -> refreshLibrary());
|
||||
|
||||
JPanel otherContainer = new JPanel();
|
||||
otherContainer.setLayout(new BoxLayout(otherContainer, BoxLayout.PAGE_AXIS));
|
||||
@ -117,7 +113,7 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
|
||||
dbQuery.ifPresent(x -> {
|
||||
DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
|
||||
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) model.getRoot();
|
||||
List<Song> x1 = x.parallelStream().filter(song -> song.getTitle().contains(filterValue)).collect(Collectors.toList());
|
||||
List<Song> x1 = x.parallelStream().filter(song -> song.getTitle().contains(librarySearchField.getText())).collect(Collectors.toList());
|
||||
Collections.sort(x1);
|
||||
x1.forEach(y -> addNodeToTreeModel(model, parentNode, new DefaultMutableTreeNode(y)));
|
||||
libraryTree.setModel(model);
|
||||
@ -139,7 +135,7 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
|
||||
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) model.getRoot();
|
||||
Collections.sort(x);
|
||||
x.forEach(y -> {
|
||||
List<Song> filteredSongs = y.getSongs().parallelStream().filter(song -> song.getTitle().contains(filterValue)).collect(Collectors.toList());
|
||||
List<Song> filteredSongs = y.getSongs().parallelStream().filter(song -> song.getTitle().contains(librarySearchField.getText())).collect(Collectors.toList());
|
||||
if(!filteredSongs.isEmpty()) {
|
||||
DefaultMutableTreeNode outerNode = new DefaultMutableTreeNode(y);
|
||||
addNodeToTreeModel(model, parentNode, outerNode);
|
||||
@ -241,7 +237,7 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
|
||||
playlist.addSong((Song) selectedItem);
|
||||
} else if (selectedItem instanceof HasSongs) {
|
||||
((HasSongs) selectedItem).getSongs().stream().filter(song -> song.getTitle().contains
|
||||
(filterValue)).forEach(playlist::addSong);
|
||||
(librarySearchField.getText())).forEach(playlist::addSong);
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
|
Loading…
Reference in New Issue
Block a user