Skip to content

Commit

Permalink
Fix from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
InAnYan committed Oct 6, 2024
1 parent b575c96 commit e55f8d4
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<HBox alignment="BASELINE_LEFT"
spacing="10">
<children>
<Label text="%Parser choice:"/>
<Label text="%Parser choice"/>
<ComboBox
fx:id="parserChoice"
HBox.hgrow="ALWAYS"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void initialize() {
new ViewModelListCellFactory<PlainCitationParserChoice>()
.withText(PlainCitationParserChoice::getLocalizedName)
.install(parserChoice);
parserChoice.getItems().setAll(viewModel.onlinePlainCitationParsers());
parserChoice.getItems().setAll(viewModel.plainCitationParsers());
parserChoice.valueProperty().bindBidirectional(viewModel.parserChoice());

input.textProperty().bindBidirectional(viewModel.inputTextProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PlainCitationParserViewModel {
private final ImportHandler importHandler;

private final StringProperty inputTextProperty = new SimpleStringProperty("");
private final ListProperty<PlainCitationParserChoice> onlinePlainCitationParsers
private final ListProperty<PlainCitationParserChoice> plainCitationParsers
= new SimpleListProperty<>(FXCollections.observableArrayList(List.of(PlainCitationParserChoice.RULE_BASED)));
private final ObjectProperty<PlainCitationParserChoice> parserChoice;

Expand All @@ -69,15 +69,15 @@ public PlainCitationParserViewModel(BibDatabaseContext bibdatabaseContext,
dialogService,
taskExecutor);

this.parserChoice = new SimpleObjectProperty<>(preferences.getImporterPreferences().defaultPlainCitationParserProperty().get());

if (preferences.getGrobidPreferences().isGrobidEnabled()) {
onlinePlainCitationParsers.add(PlainCitationParserChoice.GROBID);
plainCitationParsers.add(PlainCitationParserChoice.GROBID);
}

if (preferences.getAiPreferences().getEnableAi()) {
onlinePlainCitationParsers.add(PlainCitationParserChoice.LLM);
plainCitationParsers.add(PlainCitationParserChoice.LLM);
}

this.parserChoice = new SimpleObjectProperty<>(preferences.getImporterPreferences().defaultPlainCitationParserProperty().get());
}

public void startParsing() {
Expand Down Expand Up @@ -112,8 +112,8 @@ public StringProperty inputTextProperty() {
return this.inputTextProperty;
}

public ListProperty<PlainCitationParserChoice> onlinePlainCitationParsers() {
return this.onlinePlainCitationParsers;
public ListProperty<PlainCitationParserChoice> plainCitationParsers() {
return this.plainCitationParsers;
}

public ObjectProperty<PlainCitationParserChoice> parserChoice() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ public PreferencesDialogViewModel(DialogService dialogService, GuiPreferences pr
this.dialogService = dialogService;
this.preferences = preferences;

// TODO: This is a dirty hack of passing "currently-not-set" preferences values from different preferences tabs.
AiTab aiTab = new AiTab();

preferenceTabs = FXCollections.observableArrayList(
new GeneralTab(),
new KeyBindingsTab(),
new GroupsTab(),
new WebSearchTab(),
new AiTab(),
new WebSearchTab(aiTab.aiEnabledProperty()),
aiTab,
new EntryTab(),
new TableTab(),
new PreviewTab(),
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/preferences/ai/AiTab.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.preferences.ai;

import javafx.application.Platform;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
Expand Down Expand Up @@ -187,4 +188,8 @@ public String getTabName() {
private void onResetExpertSettingsButtonClick() {
viewModel.resetExpertSettings();
}

public ReadOnlyBooleanProperty aiEnabledProperty() {
return enableAi.selectedProperty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<CheckBox fx:id="downloadLinkedOnlineFiles" text="%Download linked online files"/>
<CheckBox fx:id="keepDownloadUrl" text="%Store url for downloaded file" />
<HBox alignment="BASELINE_LEFT" spacing="10">
<Label text="%Default online plain citation parser"/>
<ComboBox fx:id="defaultOnlinePlainCitationParser" HBox.hgrow="ALWAYS"/>
<Label text="%Default plain citation parser"/>
<ComboBox fx:id="defaultPlainCitationParser" HBox.hgrow="ALWAYS"/>
</HBox>

<Label styleClass="sectionHeader" text="%Custom DOI URI"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.preferences.websearch;

import javafx.beans.InvalidationListener;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class WebSearchTab extends AbstractPreferenceTabView<WebSearchTabViewMode
@FXML private CheckBox warnAboutDuplicatesOnImport;
@FXML private CheckBox downloadLinkedOnlineFiles;
@FXML private CheckBox keepDownloadUrl;
@FXML private ComboBox<PlainCitationParserChoice> defaultOnlinePlainCitationParser;
@FXML private ComboBox<PlainCitationParserChoice> defaultPlainCitationParser;

@FXML private CheckBox useCustomDOI;
@FXML private TextField useCustomDOIName;
Expand All @@ -53,7 +54,11 @@ public class WebSearchTab extends AbstractPreferenceTabView<WebSearchTabViewMode
@FXML private TableColumn<StudyCatalogItem, Boolean> catalogEnabledColumn;
@FXML private TableColumn<StudyCatalogItem, String> catalogColumn;

public WebSearchTab() {
private final ReadOnlyBooleanProperty refAiEnabled;

public WebSearchTab(ReadOnlyBooleanProperty refAiEnabled) {
this.refAiEnabled = refAiEnabled;

ViewLoader.view(this)
.root(this)
.load();
Expand All @@ -65,7 +70,7 @@ public String getTabName() {
}

public void initialize() {
this.viewModel = new WebSearchTabViewModel(preferences, dialogService);
this.viewModel = new WebSearchTabViewModel(preferences, dialogService, refAiEnabled);

enableWebSearch.selectedProperty().bindBidirectional(viewModel.enableWebSearchProperty());
generateNewKeyOnImport.selectedProperty().bindBidirectional(viewModel.generateKeyOnImportProperty());
Expand All @@ -75,9 +80,9 @@ public void initialize() {

new ViewModelListCellFactory<PlainCitationParserChoice>()
.withText(PlainCitationParserChoice::getLocalizedName)
.install(defaultOnlinePlainCitationParser);
defaultOnlinePlainCitationParser.itemsProperty().bind(viewModel.onlinePlainCitationParsers());
defaultOnlinePlainCitationParser.valueProperty().bindBidirectional(viewModel.defaultOnlinePlainCitationParserProperty());
.install(defaultPlainCitationParser);
defaultPlainCitationParser.itemsProperty().bind(viewModel.plainCitationParsers());
defaultPlainCitationParser.valueProperty().bindBidirectional(viewModel.defaultPlainCitationParserProperty());

grobidEnabled.selectedProperty().bindBidirectional(viewModel.grobidEnabledProperty());
grobidURL.textProperty().bindBidirectional(viewModel.grobidURLProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public class WebSearchTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty warnAboutDuplicatesOnImportProperty = new SimpleBooleanProperty();
private final BooleanProperty shouldDownloadLinkedOnlineFiles = new SimpleBooleanProperty();
private final BooleanProperty shouldkeepDownloadUrl = new SimpleBooleanProperty();
private final ListProperty<PlainCitationParserChoice> onlinePlainCitationParsers = new SimpleListProperty<>(FXCollections.observableArrayList(PlainCitationParserChoice.values()));
private final ObjectProperty<PlainCitationParserChoice> defaultOnlinePlainCitationParser = new SimpleObjectProperty<>();

private final ListProperty<PlainCitationParserChoice> plainCitationParsers =
new SimpleListProperty<>(FXCollections.observableArrayList(PlainCitationParserChoice.values()));
private final ObjectProperty<PlainCitationParserChoice> defaultPlainCitationParser = new SimpleObjectProperty<>();

private final BooleanProperty useCustomDOIProperty = new SimpleBooleanProperty();
private final StringProperty useCustomDOINameProperty = new SimpleStringProperty("");
Expand All @@ -67,14 +69,58 @@ public class WebSearchTabViewModel implements PreferenceTabViewModel {
private final FilePreferences filePreferences;
private final ImportFormatPreferences importFormatPreferences;

public WebSearchTabViewModel(CliPreferences preferences, DialogService dialogService) {
private final ReadOnlyBooleanProperty refAiEnabled;

public WebSearchTabViewModel(CliPreferences preferences, DialogService dialogService, ReadOnlyBooleanProperty refAiEnabled) {
this.dialogService = dialogService;
this.preferences = preferences;
this.importerPreferences = preferences.getImporterPreferences();
this.grobidPreferences = preferences.getGrobidPreferences();
this.doiPreferences = preferences.getDOIPreferences();
this.filePreferences = preferences.getFilePreferences();
this.importFormatPreferences = preferences.getImportFormatPreferences();

this.refAiEnabled = refAiEnabled;

setupPlainCitationParsers(preferences);
}

private void setupPlainCitationParsers(CliPreferences preferences) {
if (!refAiEnabled.get()) {
plainCitationParsers.remove(PlainCitationParserChoice.LLM);
}

refAiEnabled.addListener((observable, oldValue, newValue) -> {
if (newValue) {
plainCitationParsers.add(PlainCitationParserChoice.LLM);
} else {
PlainCitationParserChoice oldChoice = defaultPlainCitationParser.get();

plainCitationParsers.remove(PlainCitationParserChoice.LLM);

if (oldChoice == PlainCitationParserChoice.LLM) {
defaultPlainCitationParser.set(plainCitationParsers.getFirst());
}
}
});

if (!grobidEnabledProperty().get()) {
plainCitationParsers.remove(PlainCitationParserChoice.GROBID);
}

grobidEnabledProperty.addListener((observable, oldValue, newValue) -> {
if (newValue) {
plainCitationParsers.add(PlainCitationParserChoice.GROBID);
} else {
PlainCitationParserChoice oldChoice = defaultPlainCitationParser.get();

plainCitationParsers.remove(PlainCitationParserChoice.GROBID);

if (oldChoice == PlainCitationParserChoice.GROBID) {
defaultPlainCitationParser.set(plainCitationParsers.getFirst());
}
}
});
}

@Override
Expand All @@ -84,7 +130,7 @@ public void setValues() {
warnAboutDuplicatesOnImportProperty.setValue(importerPreferences.shouldWarnAboutDuplicatesOnImport());
shouldDownloadLinkedOnlineFiles.setValue(filePreferences.shouldDownloadLinkedFiles());
shouldkeepDownloadUrl.setValue(filePreferences.shouldKeepDownloadUrl());
defaultOnlinePlainCitationParser.setValue(importerPreferences.getDefaultPlainCitationParser());
defaultPlainCitationParser.setValue(importerPreferences.getDefaultPlainCitationParser());

useCustomDOIProperty.setValue(doiPreferences.isUseCustom());
useCustomDOINameProperty.setValue(doiPreferences.getDefaultBaseURI());
Expand Down Expand Up @@ -113,7 +159,7 @@ public void storeSettings() {
importerPreferences.setWarnAboutDuplicatesOnImport(warnAboutDuplicatesOnImportProperty.getValue());
filePreferences.setDownloadLinkedFiles(shouldDownloadLinkedOnlineFiles.getValue());
filePreferences.setKeepDownloadUrl(shouldkeepDownloadUrl.getValue());
importerPreferences.setDefaultPlainCitationParser(defaultOnlinePlainCitationParser.getValue());
importerPreferences.setDefaultPlainCitationParser(defaultPlainCitationParser.getValue());
grobidPreferences.setGrobidEnabled(grobidEnabledProperty.getValue());
grobidPreferences.setGrobidOptOut(grobidPreferences.isGrobidOptOut());
grobidPreferences.setGrobidURL(grobidURLProperty.getValue());
Expand All @@ -139,12 +185,12 @@ public BooleanProperty generateKeyOnImportProperty() {
return generateKeyOnImportProperty;
}

public ListProperty<PlainCitationParserChoice> onlinePlainCitationParsers() {
return onlinePlainCitationParsers;
public ListProperty<PlainCitationParserChoice> plainCitationParsers() {
return plainCitationParsers;
}

public ObjectProperty<PlainCitationParserChoice> defaultOnlinePlainCitationParserProperty() {
return defaultOnlinePlainCitationParser;
public ObjectProperty<PlainCitationParserChoice> defaultPlainCitationParserProperty() {
return defaultPlainCitationParser;
}

public BooleanProperty useCustomDOIProperty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public String getLocalizedName() {
case RULE_BASED ->
Localization.lang("Rule-based");
case GROBID ->
Localization.lang("GROBID");
Localization.lang("Grobid");
case LLM ->
Localization.lang("LLM");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public class JabRefCliPreferences implements CliPreferences {
public static final String SEARCH_WINDOW_WIDTH = "searchWindowWidth";
public static final String SEARCH_WINDOW_DIVIDER_POS = "searchWindowDividerPos";
public static final String SEARCH_CATALOGS = "searchCatalogs";
public static final String DEFAULT_PLAIN_CITATION_PARSER = "defaultOnlinePlainCitationParser";
public static final String DEFAULT_PLAIN_CITATION_PARSER = "defaultPlainCitationParser";
public static final String IMPORTERS_ENABLED = "importersEnabled";
public static final String GENERATE_KEY_ON_IMPORT = "generateKeyOnImport";
public static final String GROBID_ENABLED = "grobidEnabled";
Expand Down Expand Up @@ -438,7 +438,7 @@ protected JabRefCliPreferences() {
SpringerFetcher.FETCHER_NAME,
DBLPFetcher.FETCHER_NAME,
IEEE.FETCHER_NAME)));
defaults.put(DEFAULT_PLAIN_CITATION_PARSER, PlainCitationParserChoice.GROBID.name());
defaults.put(DEFAULT_PLAIN_CITATION_PARSER, PlainCitationParserChoice.RULE_BASED.name());
defaults.put(IMPORTERS_ENABLED, Boolean.TRUE);
defaults.put(GENERATE_KEY_ON_IMPORT, Boolean.TRUE);

Expand Down
25 changes: 12 additions & 13 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,18 @@ This\ operation\ requires\ an\ open\ library.=This operation requires an open li
Add\ to\ current\ library=Add to current library
%0\ entries\ were\ parsed\ from\ your\ query.=%0 entries were parsed from your query.
Your\ text\ is\ being\ parsed...=Your text is being parsed...
LLM=LLM
Please\ verify\ any\ information\ provided.=Please verify any information provided.
Warning\:\ plain\ citation\ parsing\ may\ generate\ inaccurate\ or\ inappropriate\ responses.=Warning: plain citation parsing may generate inaccurate or inappropriate responses.
New\ entry\ from\ plain\ text\ (online)=New entry from plain text (online)
Parser\ choice=Parser choice
Plain\ Citations\ Parser=Plain Citations Parser
Please\ enter\ the\ plain\ citations\ to\ parse\ from\ separated\ by\ double\ empty\ lines.=Please enter the plain citations to parse from separated by double empty lines.
Rule-based=Rule-based
Starts\ the\ parsing\ and\ adds\ the\ resulting\ entries\ to\ the\ currently\ opened\ database=Starts the parsing and adds the resulting entries to the currently opened database
Unable\ to\ parse\ plain\ citations.\ Detailed\ information\:\ %0=Unable to parse plain citations. Detailed information: %0
Default\ plain\ citation\ parser=Default plain citation parser
Grobid=Grobid
Citation\ key\ filters=Citation key filters
Field\ filters=Field filters
Expand Down Expand Up @@ -2631,19 +2643,6 @@ RAG\ minimum\ score\ must\ be\ greater\ than\ 0\ and\ less\ than\ 1=RAG minimum
Temperature\ must\ be\ a\ number=Temperature must be a number
If\ you\ have\ chosen\ %0\ as\ an\ AI\ provider,\ the\ privacy\ policy\ of\ %0\ applies.\ You\ find\ it\ at\ %1.=If you have chosen %0 as an AI provider, the privacy policy of %0 applies. You find it at %1.
Default\ online\ plain\ citation\ parser=Default online plain citation parser
GROBID=GROBID
LLM=LLM
Please\ verify\ any\ information\ provided.=Please verify any information provided.
Warning\:\ plain\ citation\ parsing\ may\ generate\ inaccurate\ or\ inappropriate\ responses.=Warning: plain citation parsing may generate inaccurate or inappropriate responses.
New\ entry\ from\ plain\ text\ (online)=New entry from plain text (online)
Parser\ choice\:=Parser choice:
Plain\ Citations\ Parser=Plain Citations Parser
Please\ enter\ the\ plain\ citations\ to\ parse\ from\ separated\ by\ double\ empty\ lines.=Please enter the plain citations to parse from separated by double empty lines.
Rule-based=Rule-based
Starts\ the\ parsing\ and\ adds\ the\ resulting\ entries\ to\ the\ currently\ opened\ database=Starts the parsing and adds the resulting entries to the currently opened database
Unable\ to\ parse\ plain\ citations.\ Detailed\ information\:\ %0=Unable to parse plain citations. Detailed information: %0
Link=Link
Source\ URL=Source URL
Edit\ file\ link=Edit file link
Expand Down

0 comments on commit e55f8d4

Please sign in to comment.