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 without checkbox #9802

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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="%Enable GROBID"
toggleGroup="$RemoteServicesToggleGroup"/>
<RadioButton fx:id="gorbidDisabled" text="%Disable GROBID"
toggleGroup="$RemoteServicesToggleGroup"/>
</fx:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jabref.gui.commonfxcontrols;

import com.airhacks.afterburner.views.ViewLoader;
import javafx.beans.property.BooleanProperty;
import javafx.fxml.FXML;
import javafx.scene.control.RadioButton;
import javafx.scene.layout.VBox;

public class
RemoteServicesConfigPanel extends VBox {
@FXML private RadioButton gorbidEnabled;
@FXML private RadioButton gorbidDisabled;
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());
}

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

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jabref.gui.commonfxcontrols;

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

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

public BooleanProperty gorbidEnabledProperty() {
return gorbidEnabledProperty;
}

public BooleanProperty gorbidDisabledProperty() {
return gorbidDisabledProperty;
}
}
14 changes: 10 additions & 4 deletions src/main/java/org/jabref/gui/importer/GrobidOptInDialogHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@ 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;
}
if (preferences.isGrobidOptOut()) {
return false;
}
boolean grobidEnabled = dialogService.showConfirmationDialogWithOptOutAndWait(

boolean grobidEnabled = dialogService.showConfirmationDialogAndWait(
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));
Localization.lang("Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata. This produces better results.")
);
preferences.grobidEnabledProperty().setValue(grobidEnabled);
preferences.grobidOptOutProperty().setValue(!grobidEnabled);
preferences.grobidDemandedProperty().setValue(false);
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,11 @@ public void initialize() {
exportOrderPanel.sortCriteriaProperty().bindBidirectional(viewModel.sortCriteriaProperty());
exportOrderPanel.setCriteriaLimit(3);

grobidEnabled.selectedProperty().bindBidirectional(viewModel.grobidEnabledProperty());
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,9 @@ 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 +118,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 @@ -146,8 +152,6 @@ public StringProperty useCustomDOINameProperty() {
return this.useCustomDOINameProperty;
}

// SaveOrderConfigPanel

public BooleanProperty saveInOriginalProperty() {
return exportInOriginalProperty;
}
Expand All @@ -172,6 +176,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
4 changes: 4 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,7 @@ 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 +495,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 +2852,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
3 changes: 2 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,8 @@ 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.

Disable\ GROBID=Disable GROBID
Enable\ GROBID=Enable GROBID
Fetcher\ cannot\ be\ tested\!=Fetcher cannot be tested!
Fetcher\ unknown\!=Fetcher unknown!

Expand Down