Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JournalAbbreviation search feature #7804

Merged
merged 22 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,18 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(getName(), isPseudoAbbreviation());
}

public boolean containsCaseIndependent(String s) {
btut marked this conversation as resolved.
Show resolved Hide resolved
s = s.toLowerCase();
btut marked this conversation as resolved.
Show resolved Hide resolved
if (this.abbreviation.get().toLowerCase().contains(s)) {
btut marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
if (this.name.get().toLowerCase().contains(s)) {
return true;
}
if (this.shortestUniqueAbbreviation.get().toLowerCase().contains(s)) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import org.controlsfx.control.textfield.CustomTextField?>
<?import javafx.geometry.Insets?>
<fx:root spacing="10.0" type="VBox"
xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"
fx:controller="org.jabref.gui.preferences.journals.JournalAbbreviationsTab">
Expand Down Expand Up @@ -64,4 +66,9 @@
<ProgressIndicator fx:id="progressIndicator" maxHeight="30.0" opacity="0.4"/>
</placeholder>
</TableView>
<CustomTextField fx:id="searchBox" promptText="%Search" VBox.vgrow="NEVER">
<VBox.margin>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0"/>
</VBox.margin>
</CustomTextField>
</fx:root>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.inject.Inject;

import javafx.collections.transformation.FilteredList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
Expand All @@ -20,6 +21,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
Expand All @@ -33,13 +35,16 @@ public class JournalAbbreviationsTab extends AbstractPreferenceTabView<JournalAb
@FXML private TableColumn<AbbreviationViewModel, String> journalTableNameColumn;
@FXML private TableColumn<AbbreviationViewModel, String> journalTableAbbreviationColumn;
@FXML private TableColumn<AbbreviationViewModel, String> journalTableShortestUniqueAbbreviationColumn;
private FilteredList<AbbreviationViewModel> filteredAbbreviations;
@FXML private ComboBox<AbbreviationsFileViewModel> journalFilesBox;
@FXML private Button addAbbreviationButton;
@FXML private Button removeAbbreviationButton;
@FXML private Button openAbbreviationListButton;
@FXML private Button addAbbreviationListButton;
@FXML private Button removeAbbreviationListButton;

@FXML private CustomTextField searchBox;

@Inject private TaskExecutor taskExecutor;
@Inject private JournalAbbreviationRepository abbreviationRepository;

Expand All @@ -53,9 +58,23 @@ public JournalAbbreviationsTab() {
private void initialize() {
viewModel = new JournalAbbreviationsTabViewModel(preferencesService, dialogService, taskExecutor, abbreviationRepository);

filteredAbbreviations = new FilteredList<>(viewModel.abbreviationsProperty(), s -> true);
btut marked this conversation as resolved.
Show resolved Hide resolved

setButtonStyles();
setUpTable();
setBindings();

searchBox.textProperty().addListener((observable, previousText, newText) -> {
btut marked this conversation as resolved.
Show resolved Hide resolved
if (newText.isEmpty()) {
btut marked this conversation as resolved.
Show resolved Hide resolved
filteredAbbreviations.setPredicate(s -> true);
btut marked this conversation as resolved.
Show resolved Hide resolved
} else {
filteredAbbreviations.setPredicate(s -> s.containsCaseIndependent(newText));
}
journalAbbreviationsTable.getSelectionModel().clearSelection();
journalAbbreviationsTable.getSelectionModel().selectFirst();
btut marked this conversation as resolved.
Show resolved Hide resolved
});
searchBox.setPromptText(Localization.lang("Search") + "...");
searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode());
}

private void setButtonStyles() {
Expand All @@ -78,7 +97,7 @@ private void setUpTable() {
}

private void setBindings() {
journalAbbreviationsTable.itemsProperty().bindBidirectional(viewModel.abbreviationsProperty());
journalAbbreviationsTable.setItems(filteredAbbreviations);

EasyBind.subscribe(journalAbbreviationsTable.getSelectionModel().selectedItemProperty(), newValue ->
viewModel.currentAbbreviationProperty().set(newValue));
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/jabref/logic/journals/AbbreviationTest.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -101,4 +105,13 @@ void testDefaultAndShortestUniqueAbbreviationsAreSame() {
Abbreviation abbreviation = new Abbreviation("Long Name", "L N");
assertEquals(abbreviation.getAbbreviation(), abbreviation.getShortestUniqueAbbreviation());
}

@Test
btut marked this conversation as resolved.
Show resolved Hide resolved
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"));
}
}