Skip to content

Commit

Permalink
replace "SearchAll" in web search by "Search Selected"
Browse files Browse the repository at this point in the history
see:JabRef#10556
Implemented "Search Selected".
Enabled configuring the catalogs to be searched.
Updated menu and other corresponding UI
Updated corresponding tests
  • Loading branch information
lisongxuan committed Nov 1, 2023
1 parent dc2b649 commit 778d495
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We moved the location of the 'Open only one instance of JabRef' preference option from "Network" to "General". [#9306](https://github.com/JabRef/jabref/issues/9306)
- The two previews in the change resolver dialog now have their scrollbars synchronized. [#9576](https://github.com/JabRef/jabref/issues/9576).
- We changed the setting of the keyword separator to accept a single character only. [#177](https://github.com/koppor/jabref/issues/177)

- We replaced "SearchAll" in Web Search by "Search Selected" [#10556](https://github.com/JabRef/jabref/issues/10556)
### Fixed

- We fixed an issue where the added protected term has unwanted leading and trailing whitespaces, where the formatted text has unwanted empty brackets and where the word at the cursor in the textbox can be added to the list. [#10415](https://github.com/JabRef/jabref/issues/10415).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.jabref.gui.importer.fetcher;

import java.util.Comparator;
import java.util.Map;
import java.util.Objects;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.Callable;

import javafx.beans.property.ListProperty;
Expand All @@ -22,6 +25,7 @@
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.SearchBasedFetcher;
import org.jabref.logic.importer.WebFetchers;
import org.jabref.logic.importer.fetcher.CompositeSearchBasedFetcher;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.OptionalUtil;
Expand Down Expand Up @@ -57,9 +61,10 @@ public WebSearchPaneViewModel(PreferencesService preferencesService, DialogServi
this.stateManager = stateManager;
this.preferencesService = preferencesService;

SortedSet<SearchBasedFetcher> allFetchers = WebFetchers.getSearchBasedFetchers(
SortedSet<SearchBasedFetcher> allFetchers = new TreeSet<>(new CompositeSearchFirstComparator());
allFetchers.addAll(WebFetchers.getSearchBasedFetchers(
preferencesService.getImportFormatPreferences(),
preferencesService.getImporterPreferences());
preferencesService.getImporterPreferences()));
fetchers.setAll(allFetchers);

// Choose last-selected fetcher as default
Expand Down Expand Up @@ -174,3 +179,14 @@ public ValidationStatus queryValidationStatus() {
return searchQueryValidator.getValidationStatus();
}
}

class CompositeSearchFirstComparator implements Comparator<SearchBasedFetcher> {
@Override
public int compare(SearchBasedFetcher s1, SearchBasedFetcher s2) {
if (Objects.equals(s1.getName(), CompositeSearchBasedFetcher.FETCHER_NAME)) {
return -1;
} else {
return s1.getName().compareTo(s2.getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
Expand All @@ -25,6 +27,25 @@
<CheckBox fx:id="useCustomDOI" text="%Use custom DOI base URI for article access"/>
<TextField fx:id="useCustomDOIName" HBox.hgrow="ALWAYS"/>
</HBox>
<Label styleClass="sectionHeader" text="%Catalogues used for Search Selected"/>
<TableView
fx:id="catalogTable"
HBox.hgrow="ALWAYS"
editable="true">
<columns>
<TableColumn
fx:id="catalogEnabledColumn"
text="%Enabled"
/>
<TableColumn
fx:id="catalogColumn"
text="%Catalog"/>
</columns>
<columnResizePolicy>
<TableView
fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>

<Label styleClass="sectionHeader" text="%Remote services"/>
<CheckBox fx:id="grobidEnabled" text="%Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata. This produces better results."/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.CheckBoxTableCell;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.input.MouseButton;

import org.jabref.gui.preferences.AbstractPreferenceTabView;
import org.jabref.gui.preferences.PreferencesTab;
import org.jabref.gui.slr.StudyCatalogItem;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.gui.util.ViewModelTableRowFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.preferences.FetcherApiKey;

Expand All @@ -38,6 +45,9 @@ public class WebSearchTab extends AbstractPreferenceTabView<WebSearchTabViewMode

@FXML private CheckBox persistApiKeys;
@FXML private SplitPane persistentTooltipWrapper; // The disabled persistApiKeys control does not show tooltips
@FXML private TableView<StudyCatalogItem> catalogTable;
@FXML private TableColumn<StudyCatalogItem, Boolean> catalogEnabledColumn;
@FXML private TableColumn<StudyCatalogItem, String> catalogColumn;

public WebSearchTab() {
ViewLoader.view(this)
Expand Down Expand Up @@ -66,6 +76,26 @@ public void initialize() {
useCustomDOIName.textProperty().bindBidirectional(viewModel.useCustomDOINameProperty());
useCustomDOIName.disableProperty().bind(useCustomDOI.selectedProperty().not());

new ViewModelTableRowFactory<StudyCatalogItem>()
.withOnMouseClickedEvent((entry, event) -> {
if (event.getButton() == MouseButton.PRIMARY) {
entry.setEnabled(!entry.isEnabled());
}
})
.install(catalogTable);

catalogColumn.setReorderable(false);
catalogColumn.setCellFactory(TextFieldTableCell.forTableColumn());

catalogEnabledColumn.setResizable(false);
catalogEnabledColumn.setReorderable(false);
catalogEnabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(catalogEnabledColumn));
catalogEnabledColumn.setCellValueFactory(param -> param.getValue().enabledProperty());

catalogColumn.setEditable(false);
catalogColumn.setCellValueFactory(param -> param.getValue().nameProperty());
catalogTable.setItems(viewModel.getCatalogs());

new ViewModelListCellFactory<FetcherApiKey>()
.withText(FetcherApiKey::getName)
.install(apiKeySelector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
Expand All @@ -18,11 +19,16 @@
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import org.jabref.gui.DialogService;
import org.jabref.gui.preferences.PreferenceTabViewModel;
import org.jabref.gui.slr.StudyCatalogItem;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.importer.SearchBasedFetcher;
import org.jabref.logic.importer.WebFetchers;
import org.jabref.logic.importer.fetcher.CompositeSearchBasedFetcher;
import org.jabref.logic.importer.fetcher.CustomizableKeyFetcher;
import org.jabref.logic.importer.fetcher.GrobidPreferences;
import org.jabref.logic.l10n.Localization;
Expand All @@ -42,6 +48,7 @@ public class WebSearchTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty useCustomDOIProperty = new SimpleBooleanProperty();
private final StringProperty useCustomDOINameProperty = new SimpleStringProperty("");

private final ObservableList<StudyCatalogItem> catalogs = FXCollections.observableArrayList();
private final BooleanProperty grobidEnabledProperty = new SimpleBooleanProperty();
private final StringProperty grobidURLProperty = new SimpleStringProperty("");

Expand All @@ -56,6 +63,7 @@ public class WebSearchTabViewModel implements PreferenceTabViewModel {
private final GrobidPreferences grobidPreferences;
private final ImporterPreferences importerPreferences;
private final FilePreferences filePreferences;
private final ImportFormatPreferences importFormatPreferences;

public WebSearchTabViewModel(PreferencesService preferencesService, DialogService dialogService) {
this.dialogService = dialogService;
Expand All @@ -64,6 +72,7 @@ public WebSearchTabViewModel(PreferencesService preferencesService, DialogServic
this.grobidPreferences = preferencesService.getGrobidPreferences();
this.doiPreferences = preferencesService.getDOIPreferences();
this.filePreferences = preferencesService.getFilePreferences();
this.importFormatPreferences = preferencesService.getImportFormatPreferences();
}

@Override
Expand All @@ -82,6 +91,17 @@ public void setValues() {
apiKeys.setValue(FXCollections.observableArrayList(preferencesService.getImporterPreferences().getApiKeys()));
apikeyPersistAvailableProperty.setValue(OS.isKeyringAvailable());
apikeyPersistProperty.setValue(preferencesService.getImporterPreferences().shouldPersistCustomKeys());
catalogs.addAll(WebFetchers.getSearchBasedFetchers(importFormatPreferences, importerPreferences)
.stream()
.map(SearchBasedFetcher::getName)
// The user wants to select specific fetchers
// The fetcher summarizing ALL fetchers can be emulated by selecting ALL fetchers (which happens rarely when doing an SLR)
.filter(name -> !name.equals(CompositeSearchBasedFetcher.FETCHER_NAME))
.map(name -> {
boolean enabled = importerPreferences.getCatalogs().contains(name);
return new StudyCatalogItem(name, enabled);
})
.toList());
}

@Override
Expand All @@ -94,10 +114,9 @@ public void storeSettings() {
grobidPreferences.setGrobidEnabled(grobidEnabledProperty.getValue());
grobidPreferences.setGrobidOptOut(grobidPreferences.isGrobidOptOut());
grobidPreferences.setGrobidURL(grobidURLProperty.getValue());

doiPreferences.setUseCustom(useCustomDOIProperty.get());
doiPreferences.setDefaultBaseURI(useCustomDOINameProperty.getValue().trim());

importerPreferences.setCatalogs(FXCollections.observableList(catalogs.stream().filter(StudyCatalogItem::isEnabled).map(StudyCatalogItem::getName).collect(Collectors.toList())));
importerPreferences.setPersistCustomKeys(apikeyPersistProperty.get());
preferencesService.getImporterPreferences().getApiKeys().clear();
if (apikeyPersistAvailableProperty.get()) {
Expand All @@ -121,6 +140,10 @@ public StringProperty useCustomDOINameProperty() {
return this.useCustomDOINameProperty;
}

public ObservableList<StudyCatalogItem> getCatalogs() {
return catalogs;
}

public BooleanProperty grobidEnabledProperty() {
return grobidEnabledProperty;
}
Expand Down Expand Up @@ -207,4 +230,9 @@ public void checkCustomApiKey() {
dialogService.showErrorDialogAndWait(Localization.lang("Check %0 API Key Setting", apiKeyName), Localization.lang("Connection failed!"));
}
}

@Override
public boolean validateSettings() {
return !(getCatalogs().stream().noneMatch(fetcher -> fetcher.isEnabled()));
}
}
17 changes: 15 additions & 2 deletions src/main/java/org/jabref/logic/importer/ImporterPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import java.util.Set;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ObservableSet;

import org.jabref.logic.importer.fileformat.CustomImporter;
Expand All @@ -23,21 +26,23 @@ public class ImporterPreferences {
private final ObservableSet<FetcherApiKey> apiKeys;
private final ObservableSet<CustomImporter> customImporters;
private final BooleanProperty persistCustomKeys;

private final ListProperty<String> catalogs = new SimpleListProperty<>();
public ImporterPreferences(boolean importerEnabled,
boolean generateNewKeyOnImport,
Path importWorkingDirectory,
boolean warnAboutDuplicatesOnImport,
Set<CustomImporter> customImporters,
Set<FetcherApiKey> apiKeys,
boolean persistCustomKeys) {
boolean persistCustomKeys,
ObservableList<String> catalogs) {
this.importerEnabled = new SimpleBooleanProperty(importerEnabled);
this.generateNewKeyOnImport = new SimpleBooleanProperty(generateNewKeyOnImport);
this.importWorkingDirectory = new SimpleObjectProperty<>(importWorkingDirectory);
this.warnAboutDuplicatesOnImport = new SimpleBooleanProperty(warnAboutDuplicatesOnImport);
this.customImporters = FXCollections.observableSet(customImporters);
this.apiKeys = FXCollections.observableSet(apiKeys);
this.persistCustomKeys = new SimpleBooleanProperty(persistCustomKeys);
this.setCatalogs(catalogs);
}

public boolean areImporterEnabled() {
Expand Down Expand Up @@ -120,4 +125,12 @@ public Optional<String> getApiKey(String name) {
.findFirst()
.map(FetcherApiKey::getKey);
}

public void setCatalogs(ObservableList<String> catalogs) {
this.catalogs.set(catalogs);
}

public ListProperty<String> getCatalogs() {
return catalogs;
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/importer/WebFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static SortedSet<SearchBasedFetcher> getSearchBasedFetchers(ImportFormatP
set.add(new CiteSeer());
set.add(new DOAJFetcher(importFormatPreferences));
set.add(new IEEE(importFormatPreferences, importerPreferences));
set.add(new CompositeSearchBasedFetcher(set, 30));
set.add(new CompositeSearchBasedFetcher(set, importerPreferences, 30));
// set.add(new CollectionOfComputerScienceBibliographiesFetcher(importFormatPreferences));
set.add(new DOABFetcher());
// set.add(new JstorFetcher(importFormatPreferences));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javafx.beans.property.ListProperty;
import javafx.collections.FXCollections;

import org.jabref.logic.help.HelpFile;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.importer.SearchBasedFetcher;
import org.jabref.model.entry.BibEntry;

Expand All @@ -17,22 +21,29 @@

public class CompositeSearchBasedFetcher implements SearchBasedFetcher {

public static final String FETCHER_NAME = "SearchAll";
public static final String FETCHER_NAME = "SearchSelected";

private static final Logger LOGGER = LoggerFactory.getLogger(CompositeSearchBasedFetcher.class);

private final Set<SearchBasedFetcher> fetchers;
private static Set<SearchBasedFetcher> fetchers;
private final int maximumNumberOfReturnedResults;

public CompositeSearchBasedFetcher(Set<SearchBasedFetcher> searchBasedFetchers, int maximumNumberOfReturnedResults)
public CompositeSearchBasedFetcher(Set<SearchBasedFetcher> searchBasedFetchers, ImporterPreferences importerPreferences, int maximumNumberOfReturnedResults)
throws IllegalArgumentException {
if (searchBasedFetchers == null) {
throw new IllegalArgumentException("The set of searchBasedFetchers must not be null!");
}
// Remove the Composite Fetcher instance from its own fetcher set to prevent a StackOverflow
this.fetchers = searchBasedFetchers.stream()
.filter(searchBasedFetcher -> searchBasedFetcher != this)
.collect(Collectors.toSet());
ListProperty<String> catalogs = importerPreferences.getCatalogs();
if (catalogs != null) {
fetchers = searchBasedFetchers.stream()
.filter(searchBasedFetcher -> importerPreferences.getCatalogs().stream()
.anyMatch((name -> name.equals(searchBasedFetcher.getName()))))
.collect(Collectors.toSet());
} else {
fetchers = FXCollections.emptyObservableSet();
}

this.maximumNumberOfReturnedResults = maximumNumberOfReturnedResults;
}

Expand Down
Loading

0 comments on commit 778d495

Please sign in to comment.