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

Grobid config panel with check box #9801

Closed
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<fx:root prefWidth="650.0" spacing="10.0" type="VBox"
xmlns="http://javafx.com/javafx/8.0.212" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="org.jabref.gui.commonfxcontrols.RemoteServicesConfigPanel">
<fx:define>
<ToggleGroup fx:id="RemoteServicesToggleGroup"/>
</fx:define>

<RadioButton fx:id="gorbidEnabled" text="%Always enable Grobid"
toggleGroup="$RemoteServicesToggleGroup"/>
<RadioButton fx:id="gorbidDisabled" text="%Always disable Grobid"
toggleGroup="$RemoteServicesToggleGroup"/>
<RadioButton fx:id="gorbidDemanded" text="%Always ask"
toggleGroup="$RemoteServicesToggleGroup"/>
</fx:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.jabref.gui.commonfxcontrols;

import javafx.beans.property.BooleanProperty;
import javafx.fxml.FXML;
import javafx.scene.control.RadioButton;
import javafx.scene.layout.VBox;

import com.airhacks.afterburner.views.ViewLoader;

public class RemoteServicesConfigPanel extends VBox {
@FXML private RadioButton gorbidEnabled;
@FXML private RadioButton gorbidDisabled;
@FXML private RadioButton gorbidDemanded;
private RemoteServicesConfigPanelViewModel viewModel;

public RemoteServicesConfigPanel() {
ViewLoader.view(this)
.root(this)
.load();
}

@FXML
private void initialize() {
viewModel = new RemoteServicesConfigPanelViewModel();
gorbidEnabled.selectedProperty().bindBidirectional(viewModel.gorbidEnabledProperty());
gorbidDisabled.selectedProperty().bindBidirectional(viewModel.gorbidDisabledProperty());
gorbidDemanded.selectedProperty().bindBidirectional(viewModel.gorbidDemandedProperty());
}

public BooleanProperty gorbidEnabledProperty() {
return viewModel.gorbidEnabledProperty();
}

public BooleanProperty gorbidDisabledProperty() {
return viewModel.gorbidDisabledProperty();
}

public BooleanProperty gorbidDemandedProperty() {
return viewModel.gorbidDemandedProperty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jabref.gui.commonfxcontrols;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;

public class RemoteServicesConfigPanelViewModel {
private final BooleanProperty gorbidEnabledProperty = new SimpleBooleanProperty();
private final BooleanProperty gorbidDisabledProperty = new SimpleBooleanProperty();
private final BooleanProperty gorbidDemandedProperty = new SimpleBooleanProperty();

public BooleanProperty gorbidEnabledProperty() {
return gorbidEnabledProperty;
}

public BooleanProperty gorbidDisabledProperty() {
return gorbidDisabledProperty;
}

public BooleanProperty gorbidDemandedProperty() {
return gorbidDemandedProperty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public class GrobidOptInDialogHelper {
* @return if the user enabled Grobid, either in the past or after being asked by the dialog.
*/
public static boolean showAndWaitIfUserIsUndecided(DialogService dialogService, GrobidPreferences preferences) {
if (preferences.isGrobidDemanded()) {
preferences.grobidEnabledProperty().setValue(false);
preferences.grobidOptOutProperty().setValue(false);
}
if (preferences.isGrobidEnabled()) {
return true;
}
Expand All @@ -29,8 +33,10 @@ public static boolean showAndWaitIfUserIsUndecided(DialogService dialogService,
Localization.lang("Remote services"),
Localization.lang("Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata. This produces better results."),
Localization.lang("Do not ask again"),
(optOut) -> preferences.grobidOptOutProperty().setValue(optOut));
(optOut) -> preferences.grobidDemandedProperty().setValue(!optOut));

preferences.grobidEnabledProperty().setValue(grobidEnabled);
preferences.grobidOptOutProperty().setValue(!grobidEnabled);
return grobidEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import org.jabref.gui.commonfxcontrols.SaveOrderConfigPanel?>
<?import org.jabref.gui.commonfxcontrols.RemoteServicesConfigPanel?>

<fx:root spacing="10.0" type="VBox"
xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"
fx:controller="org.jabref.gui.preferences.importexport.ImportExportTab">
Expand All @@ -29,7 +31,8 @@
<SaveOrderConfigPanel fx:id="exportOrderPanel"/>

<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."/>
<RemoteServicesConfigPanel fx:id="RemoteServicesConfigPanel"/>

<HBox alignment="CENTER_LEFT" spacing="10.0">
<Label text="%Grobid URL" />
<TextField fx:id="grobidURL" HBox.hgrow="ALWAYS"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;

import org.jabref.gui.commonfxcontrols.RemoteServicesConfigPanel;
import org.jabref.gui.commonfxcontrols.SaveOrderConfigPanel;
import org.jabref.gui.preferences.AbstractPreferenceTabView;
import org.jabref.gui.preferences.PreferencesTab;
Expand All @@ -23,13 +24,12 @@ public class ImportExportTab extends AbstractPreferenceTabView<ImportExportTabVi
@FXML private TextField useCustomDOIName;

@FXML private SaveOrderConfigPanel exportOrderPanel;

@FXML private RemoteServicesConfigPanel RemoteServicesConfigPanel;
@FXML private ComboBox<FetcherApiKey> apiKeySelector;
@FXML private TextField customApiKey;
@FXML private CheckBox useCustomApiKey;
@FXML private Button testCustomApiKey;

@FXML private CheckBox grobidEnabled;
@FXML private TextField grobidURL;

@FXML private CheckBox warnAboutDuplicatesOnImport;
Expand Down Expand Up @@ -62,9 +62,12 @@ public void initialize() {
exportOrderPanel.sortCriteriaProperty().bindBidirectional(viewModel.sortCriteriaProperty());
exportOrderPanel.setCriteriaLimit(3);

grobidEnabled.selectedProperty().bindBidirectional(viewModel.grobidEnabledProperty());
RemoteServicesConfigPanel.gorbidDemandedProperty().bindBidirectional(viewModel.grobidDemandedProperty());
RemoteServicesConfigPanel.gorbidDisabledProperty().bindBidirectional(viewModel.grobidDisabledProperty());
RemoteServicesConfigPanel.gorbidEnabledProperty().bindBidirectional(viewModel.grobidEnabledProperty());

grobidURL.textProperty().bindBidirectional(viewModel.grobidURLProperty());
grobidURL.disableProperty().bind(grobidEnabled.selectedProperty().not());
grobidURL.disableProperty().bind(viewModel.grobidEnabledProperty().not());

downloadLinkedOnlineFiles.selectedProperty().bindBidirectional(viewModel.shouldDownloadLinkedOnlineFiles());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public class ImportExportTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty exportInSpecifiedOrderProperty = new SimpleBooleanProperty();
private final ListProperty<Field> sortableFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
private final ListProperty<SortCriterionViewModel> sortCriteriaProperty = new SimpleListProperty<>(FXCollections.observableArrayList(new ArrayList<>()));

private final BooleanProperty grobidEnabledProperty = new SimpleBooleanProperty();
private final BooleanProperty grobidDisabledProperty = new SimpleBooleanProperty();
private final BooleanProperty grobidDemandedProperty = new SimpleBooleanProperty();
private final StringProperty grobidURLProperty = new SimpleStringProperty("");
private final BooleanProperty warnAboutDuplicatesOnImportProperty = new SimpleBooleanProperty();
private final BooleanProperty shouldDownloadLinkedOnlineFiles = new SimpleBooleanProperty();
Expand Down Expand Up @@ -105,6 +106,8 @@ public void setValues() {
.toList());

grobidEnabledProperty.setValue(grobidPreferences.isGrobidEnabled());
grobidDisabledProperty.setValue(grobidPreferences.isGrobidOptOut());
grobidDemandedProperty.setValue(grobidPreferences.isGrobidDemanded());
grobidURLProperty.setValue(grobidPreferences.getGrobidURL());

apiKeys.setValue(FXCollections.observableArrayList(preferencesService.getImporterPreferences().getApiKeys()));
Expand All @@ -114,7 +117,9 @@ public void setValues() {
public void storeSettings() {
importerPreferences.setGenerateNewKeyOnImport(generateKeyOnImportProperty.getValue());
grobidPreferences.setGrobidEnabled(grobidEnabledProperty.getValue());
grobidPreferences.setGrobidOptOut(grobidPreferences.isGrobidOptOut());
grobidPreferences.setGrobidDemanded(grobidDemandedProperty.getValue());
grobidPreferences.setGrobidOptOut(grobidDisabledProperty.getValue());

grobidPreferences.setGrobidURL(grobidURLProperty.getValue());

filePreferences.setDownloadLinkedFiles(shouldDownloadLinkedOnlineFiles.getValue());
Expand Down Expand Up @@ -172,6 +177,14 @@ public BooleanProperty grobidEnabledProperty() {
return grobidEnabledProperty;
}

public BooleanProperty grobidDisabledProperty() {
return grobidDisabledProperty;
}

public BooleanProperty grobidDemandedProperty() {
return grobidDemandedProperty;
}

public StringProperty grobidURLProperty() {
return grobidURLProperty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
public class GrobidPreferences {
private final BooleanProperty grobidEnabled;
private final BooleanProperty grobidOptOut;
private final BooleanProperty grobidDemanded;
private final StringProperty grobidURL;

public GrobidPreferences(boolean grobidEnabled,
boolean grobidOptOut,
boolean grobidDemanded,
String grobidURL) {
this.grobidEnabled = new SimpleBooleanProperty(grobidEnabled);
this.grobidOptOut = new SimpleBooleanProperty(grobidOptOut);
this.grobidDemanded = new SimpleBooleanProperty(grobidDemanded);
this.grobidURL = new SimpleStringProperty(grobidURL);
}

Expand Down Expand Up @@ -42,6 +45,18 @@ public void setGrobidOptOut(boolean grobidOptOut) {
this.grobidOptOut.set(grobidOptOut);
}

public boolean isGrobidDemanded() {
return grobidDemanded.get();
}

public BooleanProperty grobidDemandedProperty() {
return grobidDemanded;
}

public void setGrobidDemanded(boolean grobidDemanded) {
this.grobidDemanded.set(grobidDemanded);
}

public String getGrobidURL() {
return grobidURL.get();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ public class JabRefPreferences implements PreferencesService {
public static final String GENERATE_KEY_ON_IMPORT = "generateKeyOnImport";
public static final String GROBID_ENABLED = "grobidEnabled";
public static final String GROBID_OPT_OUT = "grobidOptOut";

public static final String GROBID_DEMANDED = "grobidDemanded";
public static final String GROBID_URL = "grobidURL";

public static final String DEFAULT_CITATION_KEY_PATTERN = "defaultBibtexKeyPattern";
Expand Down Expand Up @@ -494,6 +496,7 @@ private JabRefPreferences() {
defaults.put(GENERATE_KEY_ON_IMPORT, Boolean.TRUE);
defaults.put(GROBID_ENABLED, Boolean.FALSE);
defaults.put(GROBID_OPT_OUT, Boolean.FALSE);
defaults.put(GROBID_DEMANDED, Boolean.TRUE);
defaults.put(GROBID_URL, "http://grobid.jabref.org:8070");

defaults.put(PUSH_TEXMAKER_PATH, JabRefDesktop.getNativeDesktop().detectProgramPath("texmaker", "Texmaker"));
Expand Down Expand Up @@ -2850,10 +2853,12 @@ public GrobidPreferences getGrobidPreferences() {
grobidPreferences = new GrobidPreferences(
getBoolean(GROBID_ENABLED),
getBoolean(GROBID_OPT_OUT),
getBoolean(GROBID_DEMANDED),
get(GROBID_URL));

EasyBind.listen(grobidPreferences.grobidEnabledProperty(), (obs, oldValue, newValue) -> putBoolean(GROBID_ENABLED, newValue));
EasyBind.listen(grobidPreferences.grobidOptOutProperty(), (obs, oldValue, newValue) -> putBoolean(GROBID_OPT_OUT, newValue));
EasyBind.listen(grobidPreferences.grobidDemandedProperty(), (obs, oldValue, newValue) -> putBoolean(GROBID_DEMANDED, newValue));
EasyBind.listen(grobidPreferences.grobidURLProperty(), (obs, oldValue, newValue) -> put(GROBID_URL, newValue));

return grobidPreferences;
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2432,7 +2432,9 @@ Found\ matches\ in\ Annotations\:=Found matches in Annotations:
Grobid\ URL=Grobid URL
Remote\ services=Remote services
Allow\ sending\ PDF\ files\ and\ raw\ citation\ strings\ to\ a\ JabRef\ online\ service\ (Grobid)\ to\ determine\ Metadata.\ This\ produces\ better\ results.=Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata. This produces better results.

Always\ enable\ Grobid=Always enable Grobid
Always\ disable\ Grobid=Always disable Grobid
Always\ ask=Always ask
Fetcher\ cannot\ be\ tested\!=Fetcher cannot be tested!
Fetcher\ unknown\!=Fetcher unknown!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class GrobidCitationFetcherTest {
static GrobidPreferences grobidPreferences = new GrobidPreferences(
true,
false,
false,
"http://grobid.jabref.org:8070");
static GrobidCitationFetcher grobidCitationFetcher = new GrobidCitationFetcher(grobidPreferences, importFormatPreferences);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static void setup() {
GrobidPreferences grobidPreferences = new GrobidPreferences(
true,
false,
false,
"http://grobid.jabref.org:8070");
grobidService = new GrobidService(grobidPreferences);
}
Expand Down Expand Up @@ -85,6 +86,7 @@ public void failsWhenGrobidDisabled() {
GrobidPreferences importSettingsWithGrobidDisabled = new GrobidPreferences(
false,
false,
true,
"http://grobid.jabref.org:8070");
assertThrows(UnsupportedOperationException.class, () -> new GrobidService(importSettingsWithGrobidDisabled));
}
Expand Down