From 90cbc2f66adecf356b1963f84e41e0c20895ceca Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Mon, 7 Jun 2021 16:22:56 +0200 Subject: [PATCH 01/19] 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); + } } From 18a5a3cb703117a76b5c4cc438e1ef9fac254fbb Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Mon, 7 Jun 2021 18:43:56 +0200 Subject: [PATCH 02/19] Changed to FilteredList Changed implementation to use JavaFX's FilteredList. --- .../journals/JournalAbbreviationsTab.java | 20 ++++++++++++-- .../JournalAbbreviationsTabViewModel.java | 27 ------------------- 2 files changed, 18 insertions(+), 29 deletions(-) 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 a59ef7701c4..5d20d2fc18b 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -4,6 +4,10 @@ import javax.inject.Inject; +import javafx.beans.property.SimpleListProperty; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import javafx.collections.transformation.FilteredList; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; @@ -36,6 +40,7 @@ public class JournalAbbreviationsTab extends AbstractPreferenceTabView journalTableNameColumn; @FXML private TableColumn journalTableAbbreviationColumn; @FXML private TableColumn journalTableShortestUniqueAbbreviationColumn; + private FilteredList filteredAbbreviations; @FXML private ComboBox journalFilesBox; @FXML private Button addAbbreviationButton; @FXML private Button removeAbbreviationButton; @@ -58,12 +63,19 @@ public JournalAbbreviationsTab() { private void initialize() { viewModel = new JournalAbbreviationsTabViewModel(preferencesService, dialogService, taskExecutor, abbreviationRepository); + filteredAbbreviations = new FilteredList<>(viewModel.abbreviationsProperty(), s -> true); + setButtonStyles(); setUpTable(); setBindings(); searchBox.textProperty().addListener((observable, previousText, newText) -> { - viewModel.filterAbbreviations(newText.toLowerCase(Locale.ROOT)); + if (newText.isEmpty()) { + filteredAbbreviations.setPredicate(s -> true); + } else { + filteredAbbreviations.setPredicate(s -> s.contains(newText.toLowerCase())); + } + journalAbbreviationsTable.setItems(filteredAbbreviations); journalAbbreviationsTable.getSelectionModel().clearSelection(); journalAbbreviationsTable.getSelectionModel().selectFirst(); }); @@ -91,7 +103,11 @@ private void setUpTable() { } private void setBindings() { - journalAbbreviationsTable.itemsProperty().bindBidirectional(viewModel.filteredAbbreviationsProperty()); + //journalAbbreviationsTable.itemsProperty().bindBidirectional(filteredAbbreviations.predicateProperty()); + journalAbbreviationsTable.setItems(filteredAbbreviations); + filteredAbbreviations.addListener( + (ListChangeListener) c -> journalAbbreviationsTable.setItems(filteredAbbreviations) + ); 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 945049f1466..32d8c826b9a 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTabViewModel.java @@ -40,7 +40,6 @@ 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<>(); @@ -102,8 +101,6 @@ public JournalAbbreviationsTabViewModel(PreferencesService preferences, } } }); - filteredAbbreviations.setAll(abbreviations); - filteredAbbreviations.bindBidirectional(abbreviations); } @Override @@ -376,10 +373,6 @@ public SimpleListProperty abbreviationsProperty() { return abbreviations; } - public SimpleListProperty filteredAbbreviationsProperty() { - return filteredAbbreviations; - } - public SimpleIntegerProperty abbreviationsCountProperty() { return abbreviationsCount; } @@ -403,24 +396,4 @@ 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); - } } From ca95022c1c892322c4e1fd8f76d7b6808492a0a1 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Mon, 7 Jun 2021 18:48:01 +0200 Subject: [PATCH 03/19] Checkstyle --- .../gui/preferences/journals/JournalAbbreviationsTab.java | 5 ----- 1 file changed, 5 deletions(-) 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 5d20d2fc18b..14b36961caf 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -1,12 +1,8 @@ package org.jabref.gui.preferences.journals; -import java.util.Locale; - import javax.inject.Inject; -import javafx.beans.property.SimpleListProperty; import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import javafx.fxml.FXML; import javafx.scene.control.Button; @@ -103,7 +99,6 @@ private void setUpTable() { } private void setBindings() { - //journalAbbreviationsTable.itemsProperty().bindBidirectional(filteredAbbreviations.predicateProperty()); journalAbbreviationsTable.setItems(filteredAbbreviations); filteredAbbreviations.addListener( (ListChangeListener) c -> journalAbbreviationsTable.setItems(filteredAbbreviations) From bdb2f9230b0b8a8aae6d881bdf4f5764f85e7800 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Mon, 7 Jun 2021 20:02:55 +0200 Subject: [PATCH 04/19] Removed unnecessary listeners --- .../gui/preferences/journals/JournalAbbreviationsTab.java | 5 ----- 1 file changed, 5 deletions(-) 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 14b36961caf..abd0bf33aba 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -2,7 +2,6 @@ import javax.inject.Inject; -import javafx.collections.ListChangeListener; import javafx.collections.transformation.FilteredList; import javafx.fxml.FXML; import javafx.scene.control.Button; @@ -71,7 +70,6 @@ private void initialize() { } else { filteredAbbreviations.setPredicate(s -> s.contains(newText.toLowerCase())); } - journalAbbreviationsTable.setItems(filteredAbbreviations); journalAbbreviationsTable.getSelectionModel().clearSelection(); journalAbbreviationsTable.getSelectionModel().selectFirst(); }); @@ -100,9 +98,6 @@ private void setUpTable() { private void setBindings() { journalAbbreviationsTable.setItems(filteredAbbreviations); - filteredAbbreviations.addListener( - (ListChangeListener) c -> journalAbbreviationsTable.setItems(filteredAbbreviations) - ); EasyBind.subscribe(journalAbbreviationsTable.getSelectionModel().selectedItemProperty(), newValue -> viewModel.currentAbbreviationProperty().set(newValue)); From 4f97d036322e9eb3ecf16c927d43a266c36b7e8f Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Tue, 8 Jun 2021 08:37:53 +0200 Subject: [PATCH 05/19] Added changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f346511957..715f774d1a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We added a feature that allows the user to choose whether to trust the target site when unable to find a valid certification path from the file download site. [#7616](https://github.com/JabRef/jabref/issues/7616) - We added a feature that allows the user to open all linked files of multiple selected entries by "Open file" option. [#6966](https://github.com/JabRef/jabref/issues/6966) - We added a keybinding preset for new entries. [#7705](https://github.com/JabRef/jabref/issues/7705) +- We added a search feature for journal abbreviations [#7804](https://github.com/JabRef/jabref/pull/7804). ### Changed From b9c981e29742f95d31692a1ef69cf20cf59decf5 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Tue, 8 Jun 2021 09:00:11 +0200 Subject: [PATCH 06/19] Changed contains to containsLowerCase I think the conversion of the search term to lower-case makes more sense in the contains (now containsLowerCase) method. We already need to convert the terms to compare there, so people expecting contains() to be case-dependent (as it usually is) would be fooled. --- .../jabref/gui/preferences/journals/AbbreviationViewModel.java | 3 ++- .../gui/preferences/journals/JournalAbbreviationsTab.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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 487ac175b2d..e61e8ea9942 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/AbbreviationViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/journals/AbbreviationViewModel.java @@ -95,7 +95,8 @@ public int hashCode() { return Objects.hash(getName(), isPseudoAbbreviation()); } - public boolean contains(String s) { + public boolean containsCaseIndependent(String s) { + s = s.toLowerCase(); if (this.abbreviation.get().toLowerCase().contains(s)) { return true; } 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 abd0bf33aba..57e557898e1 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -68,7 +68,7 @@ private void initialize() { if (newText.isEmpty()) { filteredAbbreviations.setPredicate(s -> true); } else { - filteredAbbreviations.setPredicate(s -> s.contains(newText.toLowerCase())); + filteredAbbreviations.setPredicate(s -> s.containsCaseIndependent(newText)); } journalAbbreviationsTable.getSelectionModel().clearSelection(); journalAbbreviationsTable.getSelectionModel().selectFirst(); From 0e4179bc3484028b7c8b0e030102e12521d7fc47 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Tue, 8 Jun 2021 09:01:36 +0200 Subject: [PATCH 07/19] Added test --- .../org/jabref/logic/journals/AbbreviationTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java index 3931d712c47..0b2ebcc7529 100644 --- a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java +++ b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java @@ -1,8 +1,12 @@ package org.jabref.logic.journals; +import org.jabref.gui.preferences.journals.AbbreviationViewModel; + import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class AbbreviationTest { @@ -101,4 +105,13 @@ void testDefaultAndShortestUniqueAbbreviationsAreSame() { Abbreviation abbreviation = new Abbreviation("Long Name", "L N"); assertEquals(abbreviation.getAbbreviation(), abbreviation.getShortestUniqueAbbreviation()); } + + @Test + void testStringIsFoundInAllAbbreviationFields() { + AbbreviationViewModel abbreviationViewModel = new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")); + assertTrue(abbreviationViewModel.containsCaseIndependent("name")); + assertTrue(abbreviationViewModel.containsCaseIndependent("bBr")); + assertTrue(abbreviationViewModel.containsCaseIndependent("Uniq")); + assertFalse(abbreviationViewModel.containsCaseIndependent("Something else")); + } } From f1606d2d8fb0c1cab2d4bc31c8eb65a8470396ed Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Wed, 9 Jun 2021 08:27:26 +0200 Subject: [PATCH 08/19] Verbose variables and Locale lower-case --- .../preferences/journals/AbbreviationViewModel.java | 11 ++++++----- .../preferences/journals/JournalAbbreviationsTab.java | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) 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 e61e8ea9942..5b8e0d1433d 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/AbbreviationViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/journals/AbbreviationViewModel.java @@ -1,5 +1,6 @@ package org.jabref.gui.preferences.journals; +import java.util.Locale; import java.util.Objects; import javafx.beans.property.BooleanProperty; @@ -95,15 +96,15 @@ public int hashCode() { return Objects.hash(getName(), isPseudoAbbreviation()); } - public boolean containsCaseIndependent(String s) { - s = s.toLowerCase(); - if (this.abbreviation.get().toLowerCase().contains(s)) { + public boolean containsCaseIndependent(String searchTerm) { + searchTerm = searchTerm.toLowerCase(Locale.ROOT); + if (this.abbreviation.get().toLowerCase(Locale.ROOT).contains(searchTerm)) { return true; } - if (this.name.get().toLowerCase().contains(s)) { + if (this.name.get().toLowerCase(Locale.ROOT).contains(searchTerm)) { return true; } - if (this.shortestUniqueAbbreviation.get().toLowerCase().contains(s)) { + if (this.shortestUniqueAbbreviation.get().toLowerCase(Locale.ROOT).contains(searchTerm)) { return true; } return false; 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 57e557898e1..2f3079bf519 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -58,7 +58,7 @@ public JournalAbbreviationsTab() { private void initialize() { viewModel = new JournalAbbreviationsTabViewModel(preferencesService, dialogService, taskExecutor, abbreviationRepository); - filteredAbbreviations = new FilteredList<>(viewModel.abbreviationsProperty(), s -> true); + filteredAbbreviations = new FilteredList<>(viewModel.abbreviationsProperty(), abbreviation -> true); setButtonStyles(); setUpTable(); @@ -66,9 +66,9 @@ private void initialize() { searchBox.textProperty().addListener((observable, previousText, newText) -> { if (newText.isEmpty()) { - filteredAbbreviations.setPredicate(s -> true); + filteredAbbreviations.setPredicate(abbreviation -> true); } else { - filteredAbbreviations.setPredicate(s -> s.containsCaseIndependent(newText)); + filteredAbbreviations.setPredicate(abbreviation -> abbreviation.containsCaseIndependent(newText)); } journalAbbreviationsTable.getSelectionModel().clearSelection(); journalAbbreviationsTable.getSelectionModel().selectFirst(); From 2e7112b27f1d1afd044b4d9308190011db7d357f Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Wed, 9 Jun 2021 08:37:34 +0200 Subject: [PATCH 09/19] Code-style improvements Suggested by @k3KAW8Pnf7mkmdSMPHz27 and @Siedlerchr --- .../journals/JournalAbbreviationsTab.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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 2f3079bf519..3333f82e402 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -58,21 +58,12 @@ public JournalAbbreviationsTab() { private void initialize() { viewModel = new JournalAbbreviationsTabViewModel(preferencesService, dialogService, taskExecutor, abbreviationRepository); - filteredAbbreviations = new FilteredList<>(viewModel.abbreviationsProperty(), abbreviation -> true); + filteredAbbreviations = new FilteredList<>(viewModel.abbreviationsProperty()); setButtonStyles(); setUpTable(); setBindings(); - searchBox.textProperty().addListener((observable, previousText, newText) -> { - if (newText.isEmpty()) { - filteredAbbreviations.setPredicate(abbreviation -> true); - } else { - filteredAbbreviations.setPredicate(abbreviation -> abbreviation.containsCaseIndependent(newText)); - } - journalAbbreviationsTable.getSelectionModel().clearSelection(); - journalAbbreviationsTable.getSelectionModel().selectFirst(); - }); searchBox.setPromptText(Localization.lang("Search") + "..."); searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode()); } @@ -117,6 +108,10 @@ private void setBindings() { loadingLabel.visibleProperty().bind(viewModel.isLoadingProperty()); progressIndicator.visibleProperty().bind(viewModel.isLoadingProperty()); + + searchBox.textProperty().addListener((observable, previousText, searchTerm) -> { + filteredAbbreviations.setPredicate(abbreviation -> searchTerm.isEmpty() ? true : abbreviation.containsCaseIndependent(searchTerm)); + }); } @FXML From 1c4dce328a1509872bbab5fe0d11a08f14fbf535 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Wed, 9 Jun 2021 08:58:37 +0200 Subject: [PATCH 10/19] Parameterized test --- .../logic/journals/AbbreviationTest.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java index 0b2ebcc7529..da153fa583d 100644 --- a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java +++ b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java @@ -1,8 +1,13 @@ package org.jabref.logic.journals; +import java.util.stream.Stream; + import org.jabref.gui.preferences.journals.AbbreviationViewModel; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -106,12 +111,21 @@ void testDefaultAndShortestUniqueAbbreviationsAreSame() { assertEquals(abbreviation.getAbbreviation(), abbreviation.getShortestUniqueAbbreviation()); } - @Test - void testStringIsFoundInAllAbbreviationFields() { - AbbreviationViewModel abbreviationViewModel = new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")); - assertTrue(abbreviationViewModel.containsCaseIndependent("name")); - assertTrue(abbreviationViewModel.containsCaseIndependent("bBr")); - assertTrue(abbreviationViewModel.containsCaseIndependent("Uniq")); - assertFalse(abbreviationViewModel.containsCaseIndependent("Something else")); + @ParameterizedTest + @MethodSource("provideTestStringIsFoundInAllAbbreviationFields") + void testStringIsFoundInAllAbbreviationFields(String searchTerm, AbbreviationViewModel abbreviation, boolean expected) { + assertEquals(expected, abbreviation.containsCaseIndependent(searchTerm)); + } + + private static Stream provideTestStringIsFoundInAllAbbreviationFields() { + return Stream.of( + Arguments.of("name", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")), true), + Arguments.of("bBr", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")), true), + Arguments.of("Uniq", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")), true), + Arguments.of("Something else", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")), false), + Arguments.of("", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")), true), + Arguments.of("", new AbbreviationViewModel(new Abbreviation("", "", "")), true), + Arguments.of("Something", new AbbreviationViewModel(new Abbreviation("", "", "")), false) + ); } } From 8a8f01f75ea485b7770a753d8c0848f7948eebc9 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Wed, 9 Jun 2021 09:00:10 +0200 Subject: [PATCH 11/19] Checkstyle --- src/test/java/org/jabref/logic/journals/AbbreviationTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java index da153fa583d..19198865a4f 100644 --- a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java +++ b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java @@ -10,8 +10,6 @@ import org.junit.jupiter.params.provider.MethodSource; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; class AbbreviationTest { From 4f921255179777fd74a78e2c4dd204b06b5fa2e9 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Wed, 9 Jun 2021 09:04:57 +0200 Subject: [PATCH 12/19] Code-style improvements suggested by @Siedlerchr --- .../preferences/journals/AbbreviationViewModel.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) 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 5b8e0d1433d..b8f294fb06a 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/AbbreviationViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/journals/AbbreviationViewModel.java @@ -98,15 +98,8 @@ public int hashCode() { public boolean containsCaseIndependent(String searchTerm) { searchTerm = searchTerm.toLowerCase(Locale.ROOT); - if (this.abbreviation.get().toLowerCase(Locale.ROOT).contains(searchTerm)) { - return true; - } - if (this.name.get().toLowerCase(Locale.ROOT).contains(searchTerm)) { - return true; - } - if (this.shortestUniqueAbbreviation.get().toLowerCase(Locale.ROOT).contains(searchTerm)) { - return true; - } - return false; + return this.abbreviation.get().toLowerCase(Locale.ROOT).contains(searchTerm) || + this.name.get().toLowerCase(Locale.ROOT).contains(searchTerm) || + this.shortestUniqueAbbreviation.get().toLowerCase(Locale.ROOT).contains(searchTerm); } } From 24846d08bc4d4de8137e187e7d378332f89c4af9 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Wed, 9 Jun 2021 18:45:11 +0200 Subject: [PATCH 13/19] Clear abbrev search when user adds new (empty ) abbrev --- .../jabref/gui/preferences/journals/JournalAbbreviationsTab.java | 1 + 1 file changed, 1 insertion(+) 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 3333f82e402..c2e632fb192 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -132,6 +132,7 @@ private void removeList() { @FXML private void addAbbreviation() { viewModel.addAbbreviation(); + searchBox.textProperty().set(""); selectNewAbbreviation(); editAbbreviation(); } From 94561f0be49c853bf972150b75b1c93ed530564e Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Wed, 9 Jun 2021 21:44:04 +0200 Subject: [PATCH 14/19] Moved and refactored tests --- .../journals/AbbreviationViewModelTest.java | 44 +++++++++++++++++++ .../logic/journals/AbbreviationTest.java | 25 ----------- 2 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 src/test/java/org/jabref/gui/preferences/journals/AbbreviationViewModelTest.java diff --git a/src/test/java/org/jabref/gui/preferences/journals/AbbreviationViewModelTest.java b/src/test/java/org/jabref/gui/preferences/journals/AbbreviationViewModelTest.java new file mode 100644 index 00000000000..87f9ea5aeab --- /dev/null +++ b/src/test/java/org/jabref/gui/preferences/journals/AbbreviationViewModelTest.java @@ -0,0 +1,44 @@ +package org.jabref.gui.preferences.journals; + +import java.util.stream.Stream; + +import org.jabref.logic.journals.Abbreviation; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class AbbreviationViewModelTest { + + @ParameterizedTest + @MethodSource("provideContainsCaseIndependentContains") + void containsCaseIndependentContains(String searchTerm, AbbreviationViewModel abbreviation) { + assertTrue(abbreviation.containsCaseIndependent(searchTerm)); + } + + private static Stream provideContainsCaseIndependentContains() { + return Stream.of( + Arguments.of("name", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique"))), + Arguments.of("bBr", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique"))), + Arguments.of("Uniq", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique"))), + Arguments.of("", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique"))), + Arguments.of("", new AbbreviationViewModel(new Abbreviation("", "", ""))) + ); + } + + @ParameterizedTest + @MethodSource("provideContainsCaseIndependentDoesNotContain") + void containsCaseIndependentDoesNotContain(String searchTerm, AbbreviationViewModel abbreviation) { + assertFalse(abbreviation.containsCaseIndependent(searchTerm)); + } + + private static Stream provideContainsCaseIndependentDoesNotContain() { + return Stream.of( + Arguments.of("Something else", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique"))), + Arguments.of("Something", new AbbreviationViewModel(new Abbreviation("", "", ""))) + ); + } +} diff --git a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java index 19198865a4f..3931d712c47 100644 --- a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java +++ b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java @@ -1,13 +1,6 @@ package org.jabref.logic.journals; -import java.util.stream.Stream; - -import org.jabref.gui.preferences.journals.AbbreviationViewModel; - import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -108,22 +101,4 @@ void testDefaultAndShortestUniqueAbbreviationsAreSame() { Abbreviation abbreviation = new Abbreviation("Long Name", "L N"); assertEquals(abbreviation.getAbbreviation(), abbreviation.getShortestUniqueAbbreviation()); } - - @ParameterizedTest - @MethodSource("provideTestStringIsFoundInAllAbbreviationFields") - void testStringIsFoundInAllAbbreviationFields(String searchTerm, AbbreviationViewModel abbreviation, boolean expected) { - assertEquals(expected, abbreviation.containsCaseIndependent(searchTerm)); - } - - private static Stream provideTestStringIsFoundInAllAbbreviationFields() { - return Stream.of( - Arguments.of("name", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")), true), - Arguments.of("bBr", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")), true), - Arguments.of("Uniq", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")), true), - Arguments.of("Something else", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")), false), - Arguments.of("", new AbbreviationViewModel(new Abbreviation("Long Name", "abbr", "unique")), true), - Arguments.of("", new AbbreviationViewModel(new Abbreviation("", "", "")), true), - Arguments.of("Something", new AbbreviationViewModel(new Abbreviation("", "", "")), false) - ); - } } From 03bbb364e90d2df9471905211bdd2c60a4d50bca Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Fri, 11 Jun 2021 12:47:19 +0200 Subject: [PATCH 15/19] Added visual feedback of invalidated search --- .../journals/JournalAbbreviationsTab.java | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) 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 c2e632fb192..4b1d5ce7aca 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -2,6 +2,14 @@ import javax.inject.Inject; +import javafx.animation.Interpolator; +import javafx.animation.KeyFrame; +import javafx.animation.KeyValue; +import javafx.animation.Timeline; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; import javafx.collections.transformation.FilteredList; import javafx.fxml.FXML; import javafx.scene.control.Button; @@ -11,6 +19,8 @@ import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.TextFieldTableCell; +import javafx.scene.paint.Color; +import javafx.util.Duration; import org.jabref.gui.icon.IconTheme; import org.jabref.gui.preferences.AbstractPreferenceTabView; @@ -48,6 +58,10 @@ public class JournalAbbreviationsTab extends AbstractPreferenceTabView flashingColor; + private StringProperty flashingColorStringProperty; + public JournalAbbreviationsTab() { ViewLoader.view(this) .root(this) @@ -63,6 +77,7 @@ private void initialize() { setButtonStyles(); setUpTable(); setBindings(); + setAnimations(); searchBox.setPromptText(Localization.lang("Search") + "..."); searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode()); @@ -114,6 +129,20 @@ private void setBindings() { }); } + private void setAnimations() { + flashingColor = new SimpleObjectProperty<>(Color.TRANSPARENT); + flashingColorStringProperty = createFlashingColorStringProperty(flashingColor); + searchBox.styleProperty().bind( + new SimpleStringProperty("-fx-background-color: ").concat(flashingColorStringProperty).concat(";") + ); + invalidateSearch = new Timeline( + new KeyFrame(Duration.seconds(0), new KeyValue(flashingColor, Color.TRANSPARENT, Interpolator.LINEAR)), + new KeyFrame(Duration.seconds(0.25), new KeyValue(flashingColor, Color.RED, Interpolator.LINEAR)), + new KeyFrame(Duration.seconds(0.25), new KeyValue(searchBox.textProperty(), "", Interpolator.DISCRETE)), + new KeyFrame(Duration.seconds(0.5), new KeyValue(flashingColor, Color.TRANSPARENT, Interpolator.LINEAR)) + ); + } + @FXML private void addList() { viewModel.addNewFile(); @@ -132,11 +161,31 @@ private void removeList() { @FXML private void addAbbreviation() { viewModel.addAbbreviation(); - searchBox.textProperty().set(""); + if (!searchBox.getText().isEmpty()) { + invalidateSearch.play(); + } selectNewAbbreviation(); editAbbreviation(); } + private static StringProperty createFlashingColorStringProperty(final ObjectProperty flashingColor) { + final StringProperty flashingColorStringProperty = new SimpleStringProperty(); + setColorStringFromColor(flashingColorStringProperty, flashingColor); + flashingColor.addListener((observable, oldValue, newValue) -> setColorStringFromColor(flashingColorStringProperty, flashingColor)); + return flashingColorStringProperty; + } + + private static void setColorStringFromColor(StringProperty colorStringProperty, ObjectProperty color) { + colorStringProperty.set( + "rgba(" + + ((int) (color.get().getRed() * 255)) + "," + + ((int) (color.get().getGreen() * 255)) + "," + + ((int) (color.get().getBlue() * 255)) + "," + + color.get().getOpacity() + + ")" + ); + } + @FXML private void editAbbreviation() { journalAbbreviationsTable.edit( From 15ab6676ed4357dd83254afeae53aa10fa542c9e Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Fri, 11 Jun 2021 17:13:43 +0200 Subject: [PATCH 16/19] Moved rgba-string conversion to ColorUtil Also added UnitTest for new ColorUtil.toRGBAcode. --- .../journals/JournalAbbreviationsTab.java | 10 +---- .../java/org/jabref/gui/util/ColorUtil.java | 8 ++++ .../org/jabref/gui/util/ColorUtilTest.java | 37 ++++++++++++++++--- 3 files changed, 41 insertions(+), 14 deletions(-) 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 4b1d5ce7aca..8a10ac1095d 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -25,6 +25,7 @@ import org.jabref.gui.icon.IconTheme; import org.jabref.gui.preferences.AbstractPreferenceTabView; import org.jabref.gui.preferences.PreferencesTab; +import org.jabref.gui.util.ColorUtil; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; @@ -176,14 +177,7 @@ private static StringProperty createFlashingColorStringProperty(final ObjectProp } private static void setColorStringFromColor(StringProperty colorStringProperty, ObjectProperty color) { - colorStringProperty.set( - "rgba(" + - ((int) (color.get().getRed() * 255)) + "," + - ((int) (color.get().getGreen() * 255)) + "," + - ((int) (color.get().getBlue() * 255)) + "," + - color.get().getOpacity() + - ")" - ); + colorStringProperty.set(ColorUtil.toRGBACode(color.get())); } @FXML diff --git a/src/main/java/org/jabref/gui/util/ColorUtil.java b/src/main/java/org/jabref/gui/util/ColorUtil.java index 19a8be2fd52..326c7f0f27d 100644 --- a/src/main/java/org/jabref/gui/util/ColorUtil.java +++ b/src/main/java/org/jabref/gui/util/ColorUtil.java @@ -11,6 +11,14 @@ public static String toRGBCode(Color color) { (int) (color.getBlue() * 255)); } + public static String toRGBACode(Color color) { + return String.format("rgba(%d,%d,%d,%f)", + (int) (color.getRed() * 255), + (int) (color.getGreen() * 255), + (int) (color.getBlue() * 255), + color.getOpacity()); + } + public static String toHex(Color validFieldBackgroundColor) { return String.format("#%02x%02x%02x", (int) validFieldBackgroundColor.getRed(), (int) validFieldBackgroundColor.getGreen(), (int) validFieldBackgroundColor.getBlue()); } diff --git a/src/test/java/org/jabref/gui/util/ColorUtilTest.java b/src/test/java/org/jabref/gui/util/ColorUtilTest.java index a5f3a552841..a04489ac908 100644 --- a/src/test/java/org/jabref/gui/util/ColorUtilTest.java +++ b/src/test/java/org/jabref/gui/util/ColorUtilTest.java @@ -1,26 +1,51 @@ package org.jabref.gui.util; +import java.util.stream.Stream; + import javafx.scene.paint.Color; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import static org.junit.jupiter.api.Assertions.assertEquals; public class ColorUtilTest { + private static final Color C1 = Color.color(0.2, 0.4, 1); + private static final Color C2 = Color.rgb(255, 255, 255); + private static final Color C3 = Color.color(0, 0, 0, 0); + private static final Color C4 = Color.color(1, 1, 1, 1); + private static final Color C5 = Color.color(0.6, 0.8, 0.5, 0.3); + private ColorUtil colorUtil = new ColorUtil(); - private final Color c1 = Color.color(0.2, 0.4, 1); - private final Color c2 = Color.rgb(255, 255, 255); @Test public void toRGBCodeTest() { - assertEquals("#3366FF", ColorUtil.toRGBCode(c1)); - assertEquals("#FFFFFF", ColorUtil.toRGBCode(c2)); + assertEquals("#3366FF", ColorUtil.toRGBCode(C1)); + assertEquals("#FFFFFF", ColorUtil.toRGBCode(C2)); + } + + @ParameterizedTest + @MethodSource("provideToRGBACodeTest") + public void toRGBACodeTest(Color color, String expected) { + assertEquals(expected, ColorUtil.toRGBACode(color)); + } + + private static Stream provideToRGBACodeTest() { + return Stream.of( + Arguments.of(C1, String.format("rgba(51,102,255,%f)", 1.0)), + Arguments.of(C2, String.format("rgba(255,255,255,%f)", 1.0)), + Arguments.of(C3, String.format("rgba(0,0,0,%f)", 0.0)), + Arguments.of(C4, String.format("rgba(255,255,255,%f)", 1.0)), + Arguments.of(C5, String.format("rgba(153,204,127,%f)", 0.3)) + ); } @Test public void toHexTest() { - assertEquals("#000001", ColorUtil.toHex(c1)); - assertEquals("#010101", ColorUtil.toHex(c2)); + assertEquals("#000001", ColorUtil.toHex(C1)); + assertEquals("#010101", ColorUtil.toHex(C2)); } } From 66c7b127bf4b8a052aac6ea13be837cc028fd00e Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Sat, 12 Jun 2021 13:02:05 +0200 Subject: [PATCH 17/19] Only change background color, not border --- .../gui/preferences/journals/JournalAbbreviationsTab.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8a10ac1095d..e484d218ca4 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -134,7 +134,7 @@ private void setAnimations() { flashingColor = new SimpleObjectProperty<>(Color.TRANSPARENT); flashingColorStringProperty = createFlashingColorStringProperty(flashingColor); searchBox.styleProperty().bind( - new SimpleStringProperty("-fx-background-color: ").concat(flashingColorStringProperty).concat(";") + new SimpleStringProperty("-fx-control-inner-background: ").concat(flashingColorStringProperty).concat(";") ); invalidateSearch = new Timeline( new KeyFrame(Duration.seconds(0), new KeyValue(flashingColor, Color.TRANSPARENT, Interpolator.LINEAR)), From add2d44859e653bd06114f3b1ae18038b36dd90f Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Sat, 12 Jun 2021 13:07:18 +0200 Subject: [PATCH 18/19] Select name column when new abbreviation is added --- .../gui/preferences/journals/JournalAbbreviationsTab.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e484d218ca4..bb73dea5918 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -196,7 +196,7 @@ private void selectNewAbbreviation() { int lastRow = viewModel.abbreviationsCountProperty().get() - 1; journalAbbreviationsTable.scrollTo(lastRow); journalAbbreviationsTable.getSelectionModel().select(lastRow); - journalAbbreviationsTable.getFocusModel().focus(lastRow); + journalAbbreviationsTable.getFocusModel().focus(lastRow, journalTableNameColumn); } @Override From 4cf14b778419d8fdbbc7644b3fbaa6dd25ad43e8 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Sat, 12 Jun 2021 13:21:33 +0200 Subject: [PATCH 19/19] Do abbreviation actions after invalidating search --- .../preferences/journals/JournalAbbreviationsTab.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 bb73dea5918..c89d1c0e11c 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -11,6 +11,7 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.transformation.FilteredList; +import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; @@ -140,6 +141,9 @@ private void setAnimations() { new KeyFrame(Duration.seconds(0), new KeyValue(flashingColor, Color.TRANSPARENT, Interpolator.LINEAR)), new KeyFrame(Duration.seconds(0.25), new KeyValue(flashingColor, Color.RED, Interpolator.LINEAR)), new KeyFrame(Duration.seconds(0.25), new KeyValue(searchBox.textProperty(), "", Interpolator.DISCRETE)), + new KeyFrame(Duration.seconds(0.25), (ActionEvent event) -> { + addAbbreviationActions(); + }), new KeyFrame(Duration.seconds(0.5), new KeyValue(flashingColor, Color.TRANSPARENT, Interpolator.LINEAR)) ); } @@ -161,10 +165,15 @@ private void removeList() { @FXML private void addAbbreviation() { - viewModel.addAbbreviation(); if (!searchBox.getText().isEmpty()) { invalidateSearch.play(); + } else { + addAbbreviationActions(); } + } + + private void addAbbreviationActions() { + viewModel.addAbbreviation(); selectNewAbbreviation(); editAbbreviation(); }