From 2bb96e2fde748326e32bb9312a158df3734cbfc5 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 20 Apr 2019 10:31:26 +0200 Subject: [PATCH] remove obsolete search worker --- .../jabref/gui/search/GlobalSearchBar.java | 12 --- .../org/jabref/gui/search/SearchWorker.java | 74 ------------------- 2 files changed, 86 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/search/SearchWorker.java diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 27f5d1d9c4a..a90b8cdc979 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -73,8 +73,6 @@ public class GlobalSearchBar extends HBox { private final Button searchModeButton = new Button(); private final Label currentResults = new Label(""); private final SearchQueryHighlightObservable searchQueryHighlightObservable = new SearchQueryHighlightObservable(); - private SearchWorker searchWorker; - private SearchDisplayMode searchDisplayMode; public GlobalSearchBar(JabRefFrame frame) { @@ -171,7 +169,6 @@ public void endSearch() { clearSearch(); MainTable mainTable = frame.getCurrentBasePanel().getMainTable(); mainTable.requestFocus(); - //SwingUtilities.invokeLater(() -> mainTable.ensureVisible(mainTable.getSelectedRow())); } } @@ -198,11 +195,6 @@ public void performSearch() { if (currentBasePanel == null) { return; } - - if (searchWorker != null) { - searchWorker.cancel(true); - } - // An empty search field should cause the search to be cleared. if (searchField.getText().isEmpty()) { clearSearch(); @@ -216,10 +208,6 @@ public void performSearch() { } Globals.stateManager.setSearchQuery(searchQuery); - - // TODO: Remove search worker as this is doing the work twice now - searchWorker = new SearchWorker(currentBasePanel, searchQuery, searchDisplayMode); - Globals.TASK_EXECUTOR.execute(searchWorker); } private void informUserAboutInvalidSearchQuery() { diff --git a/src/main/java/org/jabref/gui/search/SearchWorker.java b/src/main/java/org/jabref/gui/search/SearchWorker.java deleted file mode 100644 index 5a49ac889a9..00000000000 --- a/src/main/java/org/jabref/gui/search/SearchWorker.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.jabref.gui.search; - -import java.util.List; -import java.util.Objects; -import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; - -import javafx.concurrent.Task; - -import org.jabref.JabRefGUI; -import org.jabref.gui.BasePanel; -import org.jabref.gui.search.rules.describer.SearchDescribers; -import org.jabref.logic.search.SearchQuery; -import org.jabref.model.database.BibDatabase; -import org.jabref.model.entry.BibEntry; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Not reusable. Always create a new instance for each search! - */ -class SearchWorker extends Task> { - - private static final Logger LOGGER = LoggerFactory.getLogger(SearchWorker.class); - - private final BasePanel basePanel; - private final BibDatabase database; - - private final SearchQuery searchQuery; - private final SearchDisplayMode searchDisplayMode; - - public SearchWorker(BasePanel basePanel, SearchQuery searchQuery, SearchDisplayMode searchDisplayMode) { - this.basePanel = Objects.requireNonNull(basePanel); - this.database = Objects.requireNonNull(basePanel.getDatabase()); - this.searchQuery = Objects.requireNonNull(searchQuery); - this.searchDisplayMode = Objects.requireNonNull(searchDisplayMode); - LOGGER.debug("Search (" + this.searchDisplayMode.getDisplayName() + "): " + this.searchQuery); - } - - @Override - protected List call() throws Exception { - return database.getEntries().parallelStream() - .filter(searchQuery::isMatch) - .collect(Collectors.toList()); - } - - @Override - protected void done() { - if (isCancelled()) { - return; - } - } - - @Override - protected void succeeded() { - super.succeeded(); - try { - updateUIWithSearchResult(get()); - } catch (InterruptedException | ExecutionException e) { - LOGGER.error("something went wrong during the search", e); - } - } - - private void updateUIWithSearchResult(List matchedEntries) { - GlobalSearchBar globalSearchBar = JabRefGUI.getMainFrame().getGlobalSearchBar(); - - globalSearchBar.updateResults(matchedEntries.size(), - SearchDescribers.getSearchDescriberFor(searchQuery).getDescription(), - searchQuery.isGrammarBasedSearch()); - globalSearchBar.getSearchQueryHighlightObservable().fireSearchlistenerEvent(searchQuery); - } - -}