From 90cbc2f66adecf356b1963f84e41e0c20895ceca Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Mon, 7 Jun 2021 16:22:56 +0200 Subject: [PATCH] Initial draf of abbreviation search feature Implemented a string filter for the journal abbreviations tab. Not working. Performing a search currently cleares a list of filtered abbreviations and fills it back up with abbreviations that contain the search string. Right now the clearing not only cleares the filtered list but also the list of all abbreviations and I don't unterstand why. Issue #7751 --- .../journals/AbbreviationViewModel.java | 13 +++++++++ .../journals/JournalAbbreviationsTab.fxml | 7 +++++ .../journals/JournalAbbreviationsTab.java | 15 ++++++++++- .../JournalAbbreviationsTabViewModel.java | 27 +++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/preferences/journals/AbbreviationViewModel.java b/src/main/java/org/jabref/gui/preferences/journals/AbbreviationViewModel.java index 26bf67cb1ec..487ac175b2d 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/AbbreviationViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/journals/AbbreviationViewModel.java @@ -94,4 +94,17 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(getName(), isPseudoAbbreviation()); } + + public boolean contains(String s) { + if (this.abbreviation.get().toLowerCase().contains(s)) { + return true; + } + if (this.name.get().toLowerCase().contains(s)) { + return true; + } + if (this.shortestUniqueAbbreviation.get().toLowerCase().contains(s)) { + return true; + } + return false; + } } diff --git a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml index 3f4a342f534..0dc1c91d3f0 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml @@ -10,6 +10,8 @@ + + @@ -64,4 +66,9 @@ + + + + + diff --git a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java index 0db240a26e9..a59ef7701c4 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -1,5 +1,7 @@ package org.jabref.gui.preferences.journals; +import java.util.Locale; + import javax.inject.Inject; import javafx.fxml.FXML; @@ -20,6 +22,7 @@ import com.airhacks.afterburner.views.ViewLoader; import com.tobiasdiez.easybind.EasyBind; +import org.controlsfx.control.textfield.CustomTextField; /** * This class controls the user interface of the journal abbreviations dialog. The UI elements and their layout are @@ -40,6 +43,8 @@ public class JournalAbbreviationsTab extends AbstractPreferenceTabView { + viewModel.filterAbbreviations(newText.toLowerCase(Locale.ROOT)); + journalAbbreviationsTable.getSelectionModel().clearSelection(); + journalAbbreviationsTable.getSelectionModel().selectFirst(); + }); + searchBox.setPromptText(Localization.lang("Search") + "..."); + searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode()); } private void setButtonStyles() { @@ -78,7 +91,7 @@ private void setUpTable() { } private void setBindings() { - journalAbbreviationsTable.itemsProperty().bindBidirectional(viewModel.abbreviationsProperty()); + journalAbbreviationsTable.itemsProperty().bindBidirectional(viewModel.filteredAbbreviationsProperty()); EasyBind.subscribe(journalAbbreviationsTable.getSelectionModel().selectedItemProperty(), newValue -> viewModel.currentAbbreviationProperty().set(newValue)); diff --git a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTabViewModel.java b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTabViewModel.java index 32d8c826b9a..945049f1466 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTabViewModel.java @@ -40,6 +40,7 @@ public class JournalAbbreviationsTabViewModel implements PreferenceTabViewModel private final Logger logger = LoggerFactory.getLogger(JournalAbbreviationsTabViewModel.class); private final SimpleListProperty journalFiles = new SimpleListProperty<>(FXCollections.observableArrayList()); private final SimpleListProperty abbreviations = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final SimpleListProperty filteredAbbreviations = new SimpleListProperty<>(FXCollections.observableArrayList()); private final SimpleIntegerProperty abbreviationsCount = new SimpleIntegerProperty(); private final SimpleObjectProperty currentFile = new SimpleObjectProperty<>(); private final SimpleObjectProperty currentAbbreviation = new SimpleObjectProperty<>(); @@ -101,6 +102,8 @@ public JournalAbbreviationsTabViewModel(PreferencesService preferences, } } }); + filteredAbbreviations.setAll(abbreviations); + filteredAbbreviations.bindBidirectional(abbreviations); } @Override @@ -373,6 +376,10 @@ public SimpleListProperty abbreviationsProperty() { return abbreviations; } + public SimpleListProperty filteredAbbreviationsProperty() { + return filteredAbbreviations; + } + public SimpleIntegerProperty abbreviationsCountProperty() { return abbreviationsCount; } @@ -396,4 +403,24 @@ public SimpleBooleanProperty isAbbreviationEditableAndRemovable() { public SimpleBooleanProperty isFileRemovableProperty() { return isFileRemovable; } + + public void filterAbbreviations(String text) { + if (text.isEmpty()) { + clearSearch(); + return; + } + + this.filteredAbbreviations.unbindBidirectional(this.abbreviations); + this.filteredAbbreviations.clear(); + for (AbbreviationViewModel abbreviation : abbreviations) { + if (abbreviation.contains(text)) { + filteredAbbreviations.add(abbreviation); + } + } + } + + private void clearSearch() { + filteredAbbreviations.setAll(this.abbreviations); + filteredAbbreviations.bindBidirectional(this.abbreviations); + } }