Skip to content

Commit 0b91b67

Browse files
committed
SwingSearchBar: inline results lookup
We want to be very clear about exactly where allResults is used: only from the EDT.
1 parent 02eaab9 commit 0b91b67

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/main/java/org/scijava/ui/swing/search/SwingSearchBar.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,14 @@ private void rebuild() {
429429
// Build the new list model.
430430
DefaultListModel<SearchResult> listModel = new DefaultListModel<>();
431431
for (final Searcher searcher : searchers) {
432-
final List<SearchResult> results = results(searcher);
433-
if (results.isEmpty()) continue;
432+
// Look up the results list.
433+
final List<SearchResult> completeResults = //
434+
allResults.get(searcher.getClass()).results();
435+
if (completeResults.isEmpty()) continue;
436+
437+
// Limit to the top MAX_RESULTS matches only.
438+
final List<SearchResult> results = completeResults.stream() //
439+
.limit(MAX_RESULTS).collect(Collectors.toList());
434440

435441
// Add section header.
436442
listModel.addElement(new SearchResultHeader(searcher.title()));
@@ -447,12 +453,6 @@ private void rebuild() {
447453
else resultsList.setSelectedValue(previous, true);
448454
}
449455

450-
private List<SearchResult> results(final Searcher searcher) {
451-
assertDispatchThread();
452-
return allResults.get(searcher.getClass()).results().stream().limit(
453-
MAX_RESULTS).collect(Collectors.toList());
454-
}
455-
456456
private Component icon(final String iconPath) {
457457
// TODO make icon() return URL, not String.
458458
if (iconPath == null || iconPath.isEmpty()) return emptyIcon();

0 commit comments

Comments
 (0)