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

replace "SearchAll" in web search by "Search Selected" #10611

Merged
merged 10 commits into from
Nov 9, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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)
- Short DOI formatter now checks, if the value is already formatted. If so, it returns the value instead of calling the ShortDOIService again. [#10589](https://github.com/JabRef/jabref/issues/10589)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jabref.gui.importer.fetcher;

import java.util.Map;
import java.util.SortedSet;
import java.util.concurrent.Callable;

import javafx.beans.property.ListProperty;
Expand Down Expand Up @@ -57,10 +56,9 @@ public WebSearchPaneViewModel(PreferencesService preferencesService, DialogServi
this.stateManager = stateManager;
this.preferencesService = preferencesService;

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

// Choose last-selected fetcher as default
SidePanePreferences sidePanePreferences = preferencesService.getSidePanePreferences();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import javafx.scene.control.TableView;
import javafx.scene.control.cell.CheckBoxTableCell;

import org.jabref.gui.Globals;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.preferences.AbstractPreferenceTabView;
import org.jabref.gui.preferences.PreferencesTab;
import org.jabref.gui.util.BindingsHelper;
Expand All @@ -36,6 +36,7 @@ public class ProtectedTermsTab extends AbstractPreferenceTabView<ProtectedTermsT
@FXML private TableColumn<ProtectedTermsListItemModel, Boolean> filesTableDeleteColumn;

@Inject private ProtectedTermsLoader termsLoader;
@Inject private KeyBindingRepository keyBindingRepository;

public ProtectedTermsTab() {
ViewLoader.view(this)
Expand Down Expand Up @@ -87,7 +88,7 @@ public void initialize() {
}

private ContextMenu createContextMenu(ProtectedTermsListItemModel file) {
ActionFactory factory = new ActionFactory(Globals.getKeyPrefs());
ActionFactory factory = new ActionFactory(keyBindingRepository);
ContextMenu contextMenu = new ContextMenu();
contextMenu.getItems().addAll(
factory.createMenuItem(StandardActions.EDIT_LIST, new ProtectedTermsTab.ContextAction(StandardActions.EDIT_LIST, file)),
Expand Down
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"
VBox.vgrow="ALWAYS"
editable="true">
<columns>
<TableColumn minWidth="90" prefWidth="70"
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 @@ -33,6 +39,8 @@
import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.PreferencesService;

import kong.unirest.UnirestException;

public class WebSearchTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty enableWebSearchProperty = new SimpleBooleanProperty();
private final BooleanProperty generateKeyOnImportProperty = new SimpleBooleanProperty();
Expand All @@ -42,6 +50,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 +65,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 +74,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 +93,15 @@ 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)
.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,13 @@ 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 +144,10 @@ public StringProperty useCustomDOINameProperty() {
return this.useCustomDOINameProperty;
}

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

public BooleanProperty grobidEnabledProperty() {
return grobidEnabledProperty;
}
Expand Down Expand Up @@ -194,7 +221,7 @@ public void checkCustomApiKey() {
keyValid = (statusCode >= 200) && (statusCode < 300);

URLDownload.setSSLVerification(defaultSslSocketFactory, defaultHostnameVerifier);
} catch (IOException | kong.unirest.UnirestException e) {
} catch (IOException | UnirestException e) {
keyValid = false;
}
} else {
Expand All @@ -207,4 +234,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().anyMatch(StudyCatalogItem::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
@@ -1,6 +1,7 @@
package org.jabref.logic.importer;

import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.Set;

Expand All @@ -9,6 +10,7 @@
import javafx.beans.property.SimpleBooleanProperty;
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 +25,23 @@ public class ImporterPreferences {
private final ObservableSet<FetcherApiKey> apiKeys;
private final ObservableSet<CustomImporter> customImporters;
private final BooleanProperty persistCustomKeys;

private final ObservableList<String> catalogs;
public ImporterPreferences(boolean importerEnabled,
boolean generateNewKeyOnImport,
Path importWorkingDirectory,
boolean warnAboutDuplicatesOnImport,
Set<CustomImporter> customImporters,
Set<FetcherApiKey> apiKeys,
boolean persistCustomKeys) {
boolean persistCustomKeys,
List<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.catalogs = FXCollections.observableArrayList(catalogs);
}

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

public void setCatalogs(List<String> catalogs) {
this.catalogs.clear();
this.catalogs.addAll(catalogs);
}

public ObservableList<String> getCatalogs() {
return catalogs;
}
}
19 changes: 17 additions & 2 deletions src/main/java/org/jabref/logic/importer/WebFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Comparator;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.SortedSet;
Expand Down Expand Up @@ -102,7 +103,7 @@ public static Optional<IdFetcher<? extends Identifier>> getIdFetcherForField(Fie
* @return sorted set containing search based fetchers
*/
public static SortedSet<SearchBasedFetcher> getSearchBasedFetchers(ImportFormatPreferences importFormatPreferences, ImporterPreferences importerPreferences) {
SortedSet<SearchBasedFetcher> set = new TreeSet<>(Comparator.comparing(WebFetcher::getName));
SortedSet<SearchBasedFetcher> set = new TreeSet<>(new CompositeSearchFirstComparator());
set.add(new ArXivFetcher(importFormatPreferences));
set.add(new INSPIREFetcher(importFormatPreferences));
set.add(new GvkFetcher(importFormatPreferences));
Expand All @@ -119,7 +120,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 Expand Up @@ -232,3 +233,17 @@ public static Set<CustomizableKeyFetcher> getCustomizableKeyFetchers(ImportForma
return fetchers;
}
}

/**
* Places "Search Selected" to the first of the set
*/
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());
}
}
}
Loading
Loading