diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index d5443bf343b..a58245a07c8 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -677,8 +677,7 @@ private boolean showDeleteConfirmationDialog(int numberOfEntries) { */ private void saveDividerLocation(Number position) { if (mode == BasePanelMode.SHOWING_EDITOR) { - preferencesService.storeEntryEditorPreferences( - preferencesService.getEntryEditorPreferences().withDividerPosition(position.doubleValue())); + preferencesService.getEntryEditorPreferences().setDividerPosition(position.doubleValue()); } } diff --git a/src/main/java/org/jabref/gui/actions/StandardActions.java b/src/main/java/org/jabref/gui/actions/StandardActions.java index d8748ea19c2..cbe51b9db9e 100644 --- a/src/main/java/org/jabref/gui/actions/StandardActions.java +++ b/src/main/java/org/jabref/gui/actions/StandardActions.java @@ -173,7 +173,12 @@ public enum StandardActions implements Action { OPEN_FORUM(Localization.lang("Online help forum"), Localization.lang("Online help forum"), IconTheme.JabRefIcons.FORUM), ERROR_CONSOLE(Localization.lang("View event log"), Localization.lang("Display all error messages")), SEARCH_FOR_UPDATES(Localization.lang("Check for updates")), - ABOUT(Localization.lang("About JabRef"), Localization.lang("About JabRef")); + ABOUT(Localization.lang("About JabRef"), Localization.lang("About JabRef")), + + EDIT_LIST(Localization.lang("Edit"), IconTheme.JabRefIcons.EDIT), + VIEW_LIST(Localization.lang("View"), IconTheme.JabRefIcons.FILE), + REMOVE_LIST(Localization.lang("Remove"), IconTheme.JabRefIcons.REMOVE), + RELOAD_LIST(Localization.lang("Reload"), IconTheme.JabRefIcons.REFRESH); private final String text; private final String description; diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java index 19260ded844..8e8a5b0a76d 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java @@ -3,19 +3,28 @@ import java.util.Map; import java.util.Set; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.MapProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleMapProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableMap; + import org.jabref.model.entry.field.Field; public class EntryEditorPreferences { - private final Map> entryEditorTabList; - private final boolean shouldOpenOnNewEntry; - private final boolean shouldShowRecommendationsTab; - private final boolean isMrdlibAccepted; - private final boolean shouldShowLatexCitationsTab; - private final boolean showSourceTabByDefault; - private final boolean enableValidation; - private final boolean allowIntegerEditionBibtex; - private double dividerPosition; + private final MapProperty> entryEditorTabList; + private final BooleanProperty shouldOpenOnNewEntry; + private final BooleanProperty shouldShowRecommendationsTab; + private final BooleanProperty isMrdlibAccepted; + private final BooleanProperty shouldShowLatexCitationsTab; + private final BooleanProperty showSourceTabByDefault; + private final BooleanProperty enableValidation; + private final BooleanProperty allowIntegerEditionBibtex; + private final DoubleProperty dividerPosition; public EntryEditorPreferences(Map> entryEditorTabList, boolean shouldOpenOnNewEntry, @@ -27,55 +36,122 @@ public EntryEditorPreferences(Map> entryEditorTabList, boolean allowIntegerEditionBibtex, double dividerPosition) { - this.entryEditorTabList = entryEditorTabList; - this.shouldOpenOnNewEntry = shouldOpenOnNewEntry; - this.shouldShowRecommendationsTab = shouldShowRecommendationsTab; - this.isMrdlibAccepted = isMrdlibAccepted; - this.shouldShowLatexCitationsTab = shouldShowLatexCitationsTab; - this.showSourceTabByDefault = showSourceTabByDefault; - this.enableValidation = enableValidation; - this.allowIntegerEditionBibtex = allowIntegerEditionBibtex; - this.dividerPosition = dividerPosition; + this.entryEditorTabList = new SimpleMapProperty<>(FXCollections.observableMap(entryEditorTabList)); + this.shouldOpenOnNewEntry = new SimpleBooleanProperty(shouldOpenOnNewEntry); + this.shouldShowRecommendationsTab = new SimpleBooleanProperty(shouldShowRecommendationsTab); + this.isMrdlibAccepted = new SimpleBooleanProperty(isMrdlibAccepted); + this.shouldShowLatexCitationsTab = new SimpleBooleanProperty(shouldShowLatexCitationsTab); + this.showSourceTabByDefault = new SimpleBooleanProperty(showSourceTabByDefault); + this.enableValidation = new SimpleBooleanProperty(enableValidation); + this.allowIntegerEditionBibtex = new SimpleBooleanProperty(allowIntegerEditionBibtex); + this.dividerPosition = new SimpleDoubleProperty(dividerPosition); + } + + public ObservableMap> getEntryEditorTabList() { + return entryEditorTabList.get(); } - public Map> getEntryEditorTabList() { + public MapProperty> entryEditorTabListProperty() { return entryEditorTabList; } + public void setEntryEditorTabList(Map> entryEditorTabList) { + this.entryEditorTabList.set(FXCollections.observableMap(entryEditorTabList)); + } + public boolean shouldOpenOnNewEntry() { + return shouldOpenOnNewEntry.get(); + } + + public BooleanProperty shouldOpenOnNewEntryProperty() { return shouldOpenOnNewEntry; } + public void setShouldOpenOnNewEntry(boolean shouldOpenOnNewEntry) { + this.shouldOpenOnNewEntry.set(shouldOpenOnNewEntry); + } + public boolean shouldShowRecommendationsTab() { + return shouldShowRecommendationsTab.get(); + } + + public BooleanProperty shouldShowRecommendationsTabProperty() { return shouldShowRecommendationsTab; } + public void setShouldShowRecommendationsTab(boolean shouldShowRecommendationsTab) { + this.shouldShowRecommendationsTab.set(shouldShowRecommendationsTab); + } + public boolean isMrdlibAccepted() { + return isMrdlibAccepted.get(); + } + + public BooleanProperty isMrdlibAcceptedProperty() { return isMrdlibAccepted; } - public boolean showSourceTabByDefault() { - return showSourceTabByDefault; + public void setIsMrdlibAccepted(boolean isMrdlibAccepted) { + this.isMrdlibAccepted.set(isMrdlibAccepted); } public boolean shouldShowLatexCitationsTab() { + return shouldShowLatexCitationsTab.get(); + } + + public BooleanProperty shouldShowLatexCitationsTabProperty() { return shouldShowLatexCitationsTab; } + public void setShouldShowLatexCitationsTab(boolean shouldShowLatexCitationsTab) { + this.shouldShowLatexCitationsTab.set(shouldShowLatexCitationsTab); + } + + public boolean showSourceTabByDefault() { + return showSourceTabByDefault.get(); + } + + public BooleanProperty showSourceTabByDefaultProperty() { + return showSourceTabByDefault; + } + + public void setShowSourceTabByDefault(boolean showSourceTabByDefault) { + this.showSourceTabByDefault.set(showSourceTabByDefault); + } + public boolean shouldEnableValidation() { + return enableValidation.get(); + } + + public BooleanProperty enableValidationProperty() { return enableValidation; } + public void setEnableValidation(boolean enableValidation) { + this.enableValidation.set(enableValidation); + } + public boolean shouldAllowIntegerEditionBibtex() { + return allowIntegerEditionBibtex.get(); + } + + public BooleanProperty allowIntegerEditionBibtexProperty() { return allowIntegerEditionBibtex; } + public void setAllowIntegerEditionBibtex(boolean allowIntegerEditionBibtex) { + this.allowIntegerEditionBibtex.set(allowIntegerEditionBibtex); + } + public double getDividerPosition() { + return dividerPosition.get(); + } + + public DoubleProperty dividerPositionProperty() { return dividerPosition; } - public EntryEditorPreferences withDividerPosition(double dividerPosition) { - this.dividerPosition = dividerPosition; - return this; + public void setDividerPosition(double dividerPosition) { + this.dividerPosition.set(dividerPosition); } } diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index 9647ef443a9..c5384437c51 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -66,7 +66,7 @@ private StackPane getRelatedArticlesPane(BibEntry entry) { progress.setMaxSize(100, 100); MrDLibFetcher fetcher = new MrDLibFetcher(preferencesService.getLanguage().name(), - Globals.BUILD_INFO.version, preferencesService); + Globals.BUILD_INFO.version, preferencesService.getMrDlibPreferences()); BackgroundTask .wrap(() -> fetcher.performSearch(entry)) .onRunning(() -> progress.setVisible(true)) @@ -211,11 +211,12 @@ private ScrollPane getPrivacyDialog(BibEntry entry) { vb.setSpacing(10); button.setOnAction(event -> { - preferencesService.storeMrDlibPreferences(new MrDlibPreferences( - true, - cbLanguage.isSelected(), - cbOS.isSelected(), - cbTimezone.isSelected())); + preferences.setIsMrdlibAccepted(true); + + MrDlibPreferences mrDlibPreferences = preferencesService.getMrDlibPreferences(); + mrDlibPreferences.setSendLanguage(cbLanguage.isSelected()); + mrDlibPreferences.setSendOs(cbOS.isSelected()); + mrDlibPreferences.setSendTimezone(cbTimezone.isSelected()); dialogService.showWarningDialogAndWait(Localization.lang("Restart"), Localization.lang("Please restart JabRef for preferences to take effect.")); setContent(getRelatedArticlesPane(entry)); diff --git a/src/main/java/org/jabref/gui/icon/IconTheme.java b/src/main/java/org/jabref/gui/icon/IconTheme.java index da489a20c47..b00e81d1b27 100644 --- a/src/main/java/org/jabref/gui/icon/IconTheme.java +++ b/src/main/java/org/jabref/gui/icon/IconTheme.java @@ -235,6 +235,7 @@ public enum JabRefIcons implements JabRefIcon { QUALITY_ASSURED(MaterialDesignC.CERTIFICATE), QUALITY(MaterialDesignC.CERTIFICATE), OPEN(MaterialDesignF.FOLDER_OUTLINE), + OPEN_LIST(MaterialDesignF.FOLDER_OPEN_OUTLINE), ADD_ROW(MaterialDesignS.SERVER_PLUS), REMOVE_ROW(MaterialDesignS.SERVER_MINUS), PICTURE(MaterialDesignF.FILE_IMAGE), diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java index 4c116e7fd15..30d8d75fa6d 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java @@ -163,7 +163,6 @@ public void resetPreferences() { */ private void updateAfterPreferenceChanges() { // Reload internal preferences cache - preferences.updateEntryEditorTabList(); preferences.updateGlobalCitationKeyPattern(); preferences.updateMainTableColumns(); diff --git a/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java b/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java index 6c72b12e924..600f437419e 100644 --- a/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java +++ b/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java @@ -41,7 +41,7 @@ public String getTabName() { } public void initialize() { - this.viewModel = new EntryEditorTabViewModel(dialogService, preferencesService); + this.viewModel = new EntryEditorTabViewModel(preferencesService); openOnNewEntry.selectedProperty().bindBidirectional(viewModel.openOnNewEntryProperty()); defaultSource.selectedProperty().bindBidirectional(viewModel.defaultSourceProperty()); diff --git a/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTabViewModel.java b/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTabViewModel.java index bcf449ac688..3e7fe564619 100644 --- a/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTabViewModel.java @@ -8,7 +8,6 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; -import org.jabref.gui.DialogService; import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode; import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.entryeditor.EntryEditorPreferences; @@ -35,32 +34,30 @@ public class EntryEditorTabViewModel implements PreferenceTabViewModel { private final BooleanProperty firstNameModeFullProperty = new SimpleBooleanProperty(); private final BooleanProperty firstNameModeBothProperty = new SimpleBooleanProperty(); - private final DialogService dialogService; private final PreferencesService preferencesService; - private final EntryEditorPreferences initialEntryEditorPreferences; + private final EntryEditorPreferences entryEditorPreferences; private final AutoCompletePreferences initialAutoCompletePreferences; private final List restartWarnings = new ArrayList<>(); - public EntryEditorTabViewModel(DialogService dialogService, PreferencesService preferencesService) { - this.dialogService = dialogService; + public EntryEditorTabViewModel(PreferencesService preferencesService) { this.preferencesService = preferencesService; - this.initialEntryEditorPreferences = preferencesService.getEntryEditorPreferences(); + this.entryEditorPreferences = preferencesService.getEntryEditorPreferences(); this.initialAutoCompletePreferences = preferencesService.getAutoCompletePreferences(); } @Override public void setValues() { // ToDo: Include CustomizeGeneralFieldsDialog in PreferencesDialog - // therefore yet unused: initialEntryEditorPreferences.getEntryEditorTabList(); + // therefore yet unused: entryEditorPreferences.getEntryEditorTabList(); - openOnNewEntryProperty.setValue(initialEntryEditorPreferences.shouldOpenOnNewEntry()); - defaultSourceProperty.setValue(initialEntryEditorPreferences.showSourceTabByDefault()); - enableRelatedArticlesTabProperty.setValue(initialEntryEditorPreferences.shouldShowRecommendationsTab()); - acceptRecommendationsProperty.setValue(initialEntryEditorPreferences.isMrdlibAccepted()); - enableLatexCitationsTabProperty.setValue(initialEntryEditorPreferences.shouldShowLatexCitationsTab()); - enableValidationProperty.setValue(initialEntryEditorPreferences.shouldEnableValidation()); - allowIntegerEditionProperty.setValue(initialEntryEditorPreferences.shouldAllowIntegerEditionBibtex()); + openOnNewEntryProperty.setValue(entryEditorPreferences.shouldOpenOnNewEntry()); + defaultSourceProperty.setValue(entryEditorPreferences.showSourceTabByDefault()); + enableRelatedArticlesTabProperty.setValue(entryEditorPreferences.shouldShowRecommendationsTab()); + acceptRecommendationsProperty.setValue(entryEditorPreferences.isMrdlibAccepted()); + enableLatexCitationsTabProperty.setValue(entryEditorPreferences.shouldShowLatexCitationsTab()); + enableValidationProperty.setValue(entryEditorPreferences.shouldEnableValidation()); + allowIntegerEditionProperty.setValue(entryEditorPreferences.shouldAllowIntegerEditionBibtex()); enableAutoCompleteProperty.setValue(initialAutoCompletePreferences.shouldAutoComplete()); autoCompleteFieldsProperty.setValue(initialAutoCompletePreferences.getCompleteNamesAsString()); @@ -82,16 +79,15 @@ public void setValues() { @Override public void storeSettings() { - preferencesService.storeEntryEditorPreferences(new EntryEditorPreferences( - initialEntryEditorPreferences.getEntryEditorTabList(), - openOnNewEntryProperty.getValue(), - enableRelatedArticlesTabProperty.getValue(), - acceptRecommendationsProperty.getValue(), - enableLatexCitationsTabProperty.getValue(), - defaultSourceProperty.getValue(), - enableValidationProperty.getValue(), - allowIntegerEditionProperty.getValue(), - initialEntryEditorPreferences.getDividerPosition())); + // entryEditorPreferences.setEntryEditorTabList(); + entryEditorPreferences.setShouldOpenOnNewEntry(openOnNewEntryProperty.getValue()); + entryEditorPreferences.setShouldShowRecommendationsTab(enableRelatedArticlesTabProperty.getValue()); + entryEditorPreferences.setIsMrdlibAccepted(acceptRecommendationsProperty.getValue()); + entryEditorPreferences.setShouldShowLatexCitationsTab(enableLatexCitationsTabProperty.getValue()); + entryEditorPreferences.setShowSourceTabByDefault(defaultSourceProperty.getValue()); + entryEditorPreferences.setEnableValidation(enableValidationProperty.getValue()); + entryEditorPreferences.setAllowIntegerEditionBibtex(allowIntegerEditionProperty.getValue()); + // entryEditorPreferences.setDividerPosition(); // default AutoCompletePreferences.NameFormat nameFormat = AutoCompletePreferences.NameFormat.BOTH; diff --git a/src/main/java/org/jabref/gui/preferences/entryeditortabs/CustomEditorFieldsTabViewModel.java b/src/main/java/org/jabref/gui/preferences/entryeditortabs/CustomEditorFieldsTabViewModel.java index e1748e6c493..ef51d2486e5 100644 --- a/src/main/java/org/jabref/gui/preferences/entryeditortabs/CustomEditorFieldsTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/entryeditortabs/CustomEditorFieldsTabViewModel.java @@ -8,6 +8,7 @@ import javafx.beans.property.StringProperty; import org.jabref.gui.DialogService; +import org.jabref.gui.entryeditor.EntryEditorPreferences; import org.jabref.gui.preferences.PreferenceTabViewModel; import org.jabref.logic.citationkeypattern.CitationKeyGenerator; import org.jabref.logic.l10n.Localization; @@ -21,15 +22,17 @@ public class CustomEditorFieldsTabViewModel implements PreferenceTabViewModel { private final DialogService dialogService; private final PreferencesService preferences; + private final EntryEditorPreferences entryEditorPreferences; public CustomEditorFieldsTabViewModel(DialogService dialogService, PreferencesService preferences) { this.dialogService = dialogService; this.preferences = preferences; + this.entryEditorPreferences = preferences.getEntryEditorPreferences(); } @Override public void setValues() { - setFields(preferences.getEntryEditorTabList()); + setFields(entryEditorPreferences.getEntryEditorTabList()); } public void resetToDefaults() { @@ -79,7 +82,7 @@ public void storeSettings() { customTabsMap.put(parts[0], FieldFactory.parseFieldList(parts[1])); } - preferences.storeEntryEditorTabList(customTabsMap); + entryEditorPreferences.setEntryEditorTabList(customTabsMap); } public StringProperty fieldsProperty() { diff --git a/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java b/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java index 739c0248319..679fc56f17a 100644 --- a/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java +++ b/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java @@ -11,19 +11,19 @@ import javafx.scene.layout.VBox; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.l10n.Localization; import org.jabref.logic.protectedterms.ProtectedTermsList; import org.jabref.logic.util.StandardFileType; +import org.jabref.preferences.PreferencesService; public class NewProtectedTermsFileDialog extends BaseDialog { private final TextField newFile = new TextField(); private final DialogService dialogService; - public NewProtectedTermsFileDialog(List termsLists, DialogService dialogService) { + public NewProtectedTermsFileDialog(List termsLists, DialogService dialogService, PreferencesService preferencesService) { this.dialogService = dialogService; this.setTitle(Localization.lang("New protected terms file")); @@ -31,7 +31,7 @@ public NewProtectedTermsFileDialog(List termsLists, DialogSe FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(Localization.lang("Protected terms file"), StandardFileType.TERMS) .withDefaultExtension(Localization.lang("Protected terms file"), StandardFileType.TERMS) - .withInitialDirectory(Globals.prefs.getWorkingDir()) + .withInitialDirectory(preferencesService.getWorkingDir()) .build(); Button browse = new Button(Localization.lang("Browse")); @@ -55,7 +55,7 @@ public NewProtectedTermsFileDialog(List termsLists, DialogSe ProtectedTermsList newList = new ProtectedTermsList(newDescription.getText(), new ArrayList<>(), newFile.getText(), false); newList.setEnabled(true); newList.createAndWriteHeading(newDescription.getText()); - termsLists.add(newList); + termsLists.add(new ProtectedTermsListItemModel(newList)); } return null; }); diff --git a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsListItemModel.java b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsListItemModel.java new file mode 100644 index 00000000000..ad06b94b55c --- /dev/null +++ b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsListItemModel.java @@ -0,0 +1,42 @@ +package org.jabref.gui.preferences.protectedterms; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ReadOnlyBooleanProperty; +import javafx.beans.property.ReadOnlyBooleanWrapper; +import javafx.beans.property.ReadOnlyStringProperty; +import javafx.beans.property.ReadOnlyStringWrapper; +import javafx.beans.property.SimpleBooleanProperty; + +import org.jabref.logic.protectedterms.ProtectedTermsList; + +public class ProtectedTermsListItemModel { + + private final ProtectedTermsList termsList; + private final BooleanProperty enabledProperty = new SimpleBooleanProperty(); + + public ProtectedTermsListItemModel(ProtectedTermsList termsList) { + this.termsList = termsList; + this.enabledProperty.setValue(termsList.isEnabled()); + } + + public ProtectedTermsList getTermsList() { + termsList.setEnabled(enabledProperty.getValue()); + return termsList; + } + + public ReadOnlyStringProperty descriptionProperty() { + return new ReadOnlyStringWrapper(termsList.getDescription()); + } + + public ReadOnlyStringProperty locationProperty() { + return new ReadOnlyStringWrapper(termsList.getLocation()); + } + + public ReadOnlyBooleanProperty internalProperty() { + return new ReadOnlyBooleanWrapper(termsList.isInternalList()); + } + + public BooleanProperty enabledProperty() { + return enabledProperty; + } +} diff --git a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTab.fxml b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTab.fxml index 0a098fc02c7..29df0104da2 100644 --- a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTab.fxml @@ -6,6 +6,7 @@ + @@ -24,8 +25,16 @@ - - + diff --git a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTab.java b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTab.java index 3ab8e036e71..b5285f5e07c 100644 --- a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTab.java +++ b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTab.java @@ -2,13 +2,17 @@ import javax.inject.Inject; +import javafx.beans.property.ReadOnlyBooleanWrapper; import javafx.fxml.FXML; import javafx.scene.control.ContextMenu; -import javafx.scene.control.MenuItem; import javafx.scene.control.TableColumn; 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.preferences.AbstractPreferenceTabView; import org.jabref.gui.preferences.PreferencesTab; @@ -25,12 +29,12 @@ * Dialog for managing term list files. */ public class ProtectedTermsTab extends AbstractPreferenceTabView implements PreferencesTab { - @FXML private TableView filesTable; - @FXML private TableColumn filesTableEnabledColumn; - @FXML private TableColumn filesTableDescriptionColumn; - @FXML private TableColumn filesTableFileColumn; - @FXML private TableColumn filesTableEditColumn; - @FXML private TableColumn filesTableDeleteColumn; + @FXML private TableView filesTable; + @FXML private TableColumn filesTableEnabledColumn; + @FXML private TableColumn filesTableDescriptionColumn; + @FXML private TableColumn filesTableFileColumn; + @FXML private TableColumn filesTableEditColumn; + @FXML private TableColumn filesTableDeleteColumn; @Inject private ProtectedTermsLoader termsLoader; @@ -49,60 +53,52 @@ public String getTabName() { public void initialize() { viewModel = new ProtectedTermsTabViewModel(termsLoader, dialogService, preferencesService); - filesTable.itemsProperty().bind(viewModel.termsFilesProperty()); - new ViewModelTableRowFactory() + new ViewModelTableRowFactory() .withContextMenu(this::createContextMenu) .install(filesTable); - filesTableEnabledColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().isEnabled())); filesTableEnabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(filesTableEnabledColumn)); - filesTableDescriptionColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getDescription())); + filesTableEnabledColumn.setCellValueFactory(data -> data.getValue().enabledProperty()); + filesTableDescriptionColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getTermsList().getDescription())); + filesTableFileColumn.setCellValueFactory(data -> { - ProtectedTermsList list = data.getValue(); + ProtectedTermsList list = data.getValue().getTermsList(); if (list.isInternalList()) { return BindingsHelper.constantOf(Localization.lang("Internal list")); } else { - return BindingsHelper.constantOf(data.getValue().getLocation()); + return BindingsHelper.constantOf(list.getLocation()); } }); - filesTableEditColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); - filesTableDeleteColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); - new ValueTableCellFactory() + filesTableEditColumn.setCellValueFactory(data -> data.getValue().internalProperty().not()); + new ValueTableCellFactory() .withGraphic(none -> IconTheme.JabRefIcons.EDIT.getGraphicNode()) - .withOnMouseClickedEvent((file, none) -> event -> viewModel.edit(file)) + .withVisibleExpression(ReadOnlyBooleanWrapper::new) + .withOnMouseClickedEvent((item, none) -> event -> viewModel.edit(item)) .install(filesTableEditColumn); - new ValueTableCellFactory() - .withGraphic(none -> IconTheme.JabRefIcons.REMOVE.getGraphicNode()) + + filesTableDeleteColumn.setCellValueFactory(data -> data.getValue().internalProperty().not()); + new ValueTableCellFactory() + .withGraphic(none -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode()) + .withVisibleExpression(ReadOnlyBooleanWrapper::new) .withTooltip(none -> Localization.lang("Remove protected terms file")) - .withOnMouseClickedEvent((file, none) -> event -> viewModel.removeFile(file)) + .withOnMouseClickedEvent((item, none) -> event -> viewModel.removeList(item)) .install(filesTableDeleteColumn); + + filesTable.itemsProperty().set(viewModel.termsFilesProperty()); } - private ContextMenu createContextMenu(ProtectedTermsList file) { - MenuItem edit = new MenuItem(Localization.lang("Edit")); - edit.setOnAction(event -> viewModel.edit(file)); - MenuItem show = new MenuItem(Localization.lang("View")); - show.setOnAction(event -> viewModel.displayContent(file)); - MenuItem remove = new MenuItem(Localization.lang("Remove")); - remove.setOnAction(event -> viewModel.removeFile(file)); - MenuItem reload = new MenuItem(Localization.lang("Reload")); - reload.setOnAction(event -> viewModel.reloadFile(file)); - - // Enable/disable context menu items - if (file.isInternalList()) { - edit.setDisable(true); - show.setDisable(false); - remove.setDisable(true); - reload.setDisable(true); - } else { - edit.setDisable(false); - show.setDisable(false); - remove.setDisable(false); - reload.setDisable(false); - } + private ContextMenu createContextMenu(ProtectedTermsListItemModel file) { + ActionFactory factory = new ActionFactory(Globals.getKeyPrefs()); + ContextMenu contextMenu = new ContextMenu(); + contextMenu.getItems().addAll( + factory.createMenuItem(StandardActions.EDIT_LIST, new ProtectedTermsTab.ContextAction(StandardActions.EDIT_LIST, file)), + factory.createMenuItem(StandardActions.VIEW_LIST, new ProtectedTermsTab.ContextAction(StandardActions.VIEW_LIST, file)), + factory.createMenuItem(StandardActions.REMOVE_LIST, new ProtectedTermsTab.ContextAction(StandardActions.REMOVE_LIST, file)), + factory.createMenuItem(StandardActions.RELOAD_LIST, new ProtectedTermsTab.ContextAction(StandardActions.RELOAD_LIST, file)) + ); + contextMenu.getItems().forEach(item -> item.setGraphic(null)); + contextMenu.getStyleClass().add("context-menu"); - final ContextMenu contextMenu = new ContextMenu(); - contextMenu.getItems().addAll(edit, show, remove, reload); return contextMenu; } @@ -115,4 +111,31 @@ private void addFile() { private void createNewFile() { viewModel.createNewFile(); } + + private class ContextAction extends SimpleCommand { + + private final StandardActions command; + private final ProtectedTermsListItemModel itemModel; + + public ContextAction(StandardActions command, ProtectedTermsListItemModel itemModel) { + this.command = command; + this.itemModel = itemModel; + + this.executable.bind(BindingsHelper.constantOf( + switch (command) { + case EDIT_LIST, REMOVE_LIST, RELOAD_LIST -> !itemModel.getTermsList().isInternalList(); + default -> true; + })); + } + + @Override + public void execute() { + switch (command) { + case EDIT_LIST -> viewModel.edit(itemModel); + case VIEW_LIST -> viewModel.displayContent(itemModel); + case REMOVE_LIST -> viewModel.removeList(itemModel); + case RELOAD_LIST -> viewModel.reloadList(itemModel); + } + } + } } diff --git a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java index dc370f12455..c3cc950660c 100644 --- a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java @@ -10,6 +10,10 @@ import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; +import javafx.scene.control.ButtonType; +import javafx.scene.control.DialogPane; +import javafx.scene.control.ScrollPane; +import javafx.scene.control.TextArea; import org.jabref.gui.DialogService; import org.jabref.gui.desktop.JabRefDesktop; @@ -33,9 +37,10 @@ public class ProtectedTermsTabViewModel implements PreferenceTabViewModel { private static final Logger LOGGER = LoggerFactory.getLogger(ProtectedTermsTabViewModel.class); private final ProtectedTermsLoader termsLoader; - private final ListProperty termsFilesProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final ListProperty termsFilesProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); private final PreferencesService preferences; private final DialogService dialogService; + private final ProtectedTermsPreferences protectedTermsPreferences; public ProtectedTermsTabViewModel(ProtectedTermsLoader termsLoader, DialogService dialogService, @@ -43,11 +48,13 @@ public ProtectedTermsTabViewModel(ProtectedTermsLoader termsLoader, this.termsLoader = termsLoader; this.dialogService = dialogService; this.preferences = preferences; + this.protectedTermsPreferences = preferences.getProtectedTermsPreferences(); } @Override public void setValues() { - termsFilesProperty.setValue(FXCollections.observableArrayList(termsLoader.getProtectedTermsLists())); + termsFilesProperty.clear(); + termsFilesProperty.addAll(termsLoader.getProtectedTermsLists().stream().map(ProtectedTermsListItemModel::new).toList()); } public void storeSettings() { @@ -56,7 +63,8 @@ public void storeSettings() { List enabledInternalList = new ArrayList<>(); List disabledInternalList = new ArrayList<>(); - for (ProtectedTermsList list : termsFilesProperty.getValue()) { + for (ProtectedTermsList list : termsFilesProperty.getValue().stream() + .map(ProtectedTermsListItemModel::getTermsList).toList()) { if (list.isInternalList()) { if (list.isEnabled()) { enabledInternalList.add(list.getLocation()); @@ -72,14 +80,12 @@ public void storeSettings() { } } - ProtectedTermsPreferences newPreferences = new ProtectedTermsPreferences( - enabledInternalList, - enabledExternalList, - disabledInternalList, - disabledExternalList); + protectedTermsPreferences.setEnabledInternalTermLists(enabledInternalList); + protectedTermsPreferences.setEnabledExternalTermLists(enabledExternalList); + protectedTermsPreferences.setDisabledInternalTermLists(disabledInternalList); + protectedTermsPreferences.setDisabledExternalTermLists(disabledExternalList); - preferences.storeProtectedTermsPreferences(newPreferences); - termsLoader.update(newPreferences); + termsLoader.update(protectedTermsPreferences); } public void addFile() { @@ -93,37 +99,38 @@ public void addFile() { .ifPresent(file -> { String fileName = file.toAbsolutePath().toString(); try { - termsFilesProperty.add(ProtectedTermsLoader.readProtectedTermsListFromFile(new File(fileName), true)); + termsFilesProperty.add(new ProtectedTermsListItemModel(ProtectedTermsLoader.readProtectedTermsListFromFile(new File(fileName), true))); } catch (FileNotFoundException e) { LOGGER.warn("Cannot find protected terms file " + fileName, e); } }); } - public void removeFile(ProtectedTermsList list) { + public void removeList(ProtectedTermsListItemModel itemModel) { + ProtectedTermsList list = itemModel.getTermsList(); if (!list.isInternalList() && dialogService.showConfirmationDialogAndWait(Localization.lang("Remove protected terms file"), Localization.lang("Are you sure you want to remove the protected terms file?"), Localization.lang("Remove protected terms file"), Localization.lang("Cancel"))) { - list.setEnabled(false); - if (!termsFilesProperty.remove(list)) { + itemModel.enabledProperty().setValue(false); + if (!termsFilesProperty.remove(itemModel)) { LOGGER.info("Problem removing protected terms file"); } } } public void createNewFile() { - dialogService.showCustomDialogAndWait(new NewProtectedTermsFileDialog(termsFilesProperty, dialogService)); + dialogService.showCustomDialogAndWait(new NewProtectedTermsFileDialog(termsFilesProperty, dialogService, preferences)); } - public void edit(ProtectedTermsList file) { + public void edit(ProtectedTermsListItemModel file) { Optional termsFileType = OptionalUtil.orElse( ExternalFileTypes.getInstance().getExternalFileTypeByExt("terms"), ExternalFileTypes.getInstance().getExternalFileTypeByExt("txt") ); - String fileName = file.getLocation(); + String fileName = file.getTermsList().getLocation(); try { JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), preferences, fileName, termsFileType); } catch (IOException e) { @@ -131,19 +138,29 @@ public void edit(ProtectedTermsList file) { } } - public void displayContent(ProtectedTermsList list) { - dialogService.showInformationDialogAndWait( - list.getDescription() + " - " + list.getLocation(), - list.getTermListing() - ); + public void displayContent(ProtectedTermsListItemModel itemModel) { + ProtectedTermsList list = itemModel.getTermsList(); + TextArea listingView = new TextArea(list.getTermListing()); + listingView.setEditable(false); + + ScrollPane scrollPane = new ScrollPane(); + scrollPane.setFitToHeight(true); + scrollPane.setFitToWidth(true); + scrollPane.setContent(listingView); + + DialogPane dialogPane = new DialogPane(); + dialogPane.setContent(scrollPane); + + dialogService.showCustomDialogAndWait(list.getDescription() + " - " + list.getLocation(), dialogPane, ButtonType.OK); } - public void reloadFile(ProtectedTermsList oldList) { + public void reloadList(ProtectedTermsListItemModel oldItemModel) { + ProtectedTermsList oldList = oldItemModel.getTermsList(); try { ProtectedTermsList newList = ProtectedTermsLoader.readProtectedTermsListFromFile(new File(oldList.getLocation()), oldList.isEnabled()); - int index = termsFilesProperty.indexOf(oldList); + int index = termsFilesProperty.indexOf(oldItemModel); if (index >= 0) { - termsFilesProperty.set(index, newList); + termsFilesProperty.set(index, new ProtectedTermsListItemModel(newList)); } else { LOGGER.warn("Problem reloading protected terms file {}.", oldList.getLocation()); } @@ -152,7 +169,7 @@ public void reloadFile(ProtectedTermsList oldList) { } } - public ListProperty termsFilesProperty() { + public ListProperty termsFilesProperty() { return termsFilesProperty; } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java index e505d2da78e..bbe4ad1c27c 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java @@ -19,7 +19,6 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.preferences.MrDlibPreferences; -import org.jabref.preferences.PreferencesService; import org.apache.http.client.utils.URIBuilder; import org.slf4j.Logger; @@ -39,12 +38,12 @@ public class MrDLibFetcher implements EntryBasedFetcher { private String heading; private String description; private String recommendationSetId; - private final PreferencesService preferencesService; + private final MrDlibPreferences preferences; - public MrDLibFetcher(String language, Version version, PreferencesService preferencesService) { + public MrDLibFetcher(String language, Version version, MrDlibPreferences preferences) { LANGUAGE = language; VERSION = version; - this.preferencesService = preferencesService; + this.preferences = preferences; } @Override @@ -118,8 +117,6 @@ private String makeServerRequest(String queryByTitle) throws FetcherException { * @return the string used to make the query at mdl server */ private String constructQuery(String queryWithTitle) { - MrDlibPreferences preferences = preferencesService.getMrDlibPreferences(); - // The encoding does not work for / so we convert them by our own queryWithTitle = queryWithTitle.replaceAll("/", " "); URIBuilder builder = new URIBuilder(); diff --git a/src/main/java/org/jabref/logic/protectedterms/ProtectedTermsPreferences.java b/src/main/java/org/jabref/logic/protectedterms/ProtectedTermsPreferences.java index 6fe9f735fc2..b15fee9b9ed 100644 --- a/src/main/java/org/jabref/logic/protectedterms/ProtectedTermsPreferences.java +++ b/src/main/java/org/jabref/logic/protectedterms/ProtectedTermsPreferences.java @@ -2,34 +2,59 @@ import java.util.List; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + public class ProtectedTermsPreferences { - private final List enabledInternalTermLists; - private final List enabledExternalTermLists; - private final List disabledInternalTermLists; - private final List disabledExternalTermLists; + private final ObservableList enabledInternalTermLists; + private final ObservableList enabledExternalTermLists; + private final ObservableList disabledInternalTermLists; + private final ObservableList disabledExternalTermLists; + + public ProtectedTermsPreferences(List enabledInternalTermLists, + List enabledExternalTermLists, + List disabledInternalTermLists, + List disabledExternalTermLists) { + this.enabledInternalTermLists = FXCollections.observableArrayList(enabledInternalTermLists); + this.disabledInternalTermLists = FXCollections.observableArrayList(disabledInternalTermLists); + this.enabledExternalTermLists = FXCollections.observableArrayList(enabledExternalTermLists); + this.disabledExternalTermLists = FXCollections.observableArrayList(disabledExternalTermLists); + } + + public ObservableList getEnabledInternalTermLists() { + return FXCollections.unmodifiableObservableList(enabledInternalTermLists); + } + + public ObservableList getEnabledExternalTermLists() { + return FXCollections.unmodifiableObservableList(enabledExternalTermLists); + } + + public ObservableList getDisabledInternalTermLists() { + return FXCollections.unmodifiableObservableList(disabledInternalTermLists); + } - public ProtectedTermsPreferences(List enabledInternalTermLists, List enabledExternalTermLists, - List disabledInternalTermLists, List disabledExternalTermLists) { - this.enabledInternalTermLists = enabledInternalTermLists; - this.disabledInternalTermLists = disabledInternalTermLists; - this.enabledExternalTermLists = enabledExternalTermLists; - this.disabledExternalTermLists = disabledExternalTermLists; + public ObservableList getDisabledExternalTermLists() { + return FXCollections.unmodifiableObservableList(disabledExternalTermLists); } - public List getEnabledInternalTermLists() { - return enabledInternalTermLists; + public void setEnabledInternalTermLists(List list) { + enabledInternalTermLists.clear(); + enabledInternalTermLists.addAll(list); } - public List getEnabledExternalTermLists() { - return enabledExternalTermLists; + public void setEnabledExternalTermLists(List list) { + enabledExternalTermLists.clear(); + enabledExternalTermLists.addAll(list); } - public List getDisabledInternalTermLists() { - return disabledInternalTermLists; + public void setDisabledInternalTermLists(List list) { + disabledInternalTermLists.clear(); + disabledInternalTermLists.addAll(list); } - public List getDisabledExternalTermLists() { - return disabledExternalTermLists; + public void setDisabledExternalTermLists(List list) { + disabledExternalTermLists.clear(); + disabledExternalTermLists.addAll(list); } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 602f237630d..dadcb69d43a 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -33,6 +33,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import javafx.beans.InvalidationListener; import javafx.scene.control.TableColumn.SortType; import org.jabref.gui.Globals; @@ -410,13 +411,17 @@ public class JabRefPreferences implements PreferencesService { private Map> entryEditorTabList; private List mainTableColumns; private List mainTableColumnSortOrder; - private PreviewPreferences previewPreferences; - private SidePanePreferences sidePanePreferences; private Theme globalTheme; private Set customImporters; private String userName; + + private PreviewPreferences previewPreferences; + private SidePanePreferences sidePanePreferences; private AppearancePreferences appearancePreferences; private ImporterPreferences importerPreferences; + private ProtectedTermsPreferences protectedTermsPreferences; + private MrDlibPreferences mrDlibPreferences; + private EntryEditorPreferences entryEditorPreferences; // The constructor is made private to enforce this as a singleton class: private JabRefPreferences() { @@ -1450,8 +1455,7 @@ public boolean getDisplayGroupCount() { * * @return a list of defined tabs */ - @Override - public Map> getEntryEditorTabList() { + private Map> getEntryEditorTabList() { if (entryEditorTabList == null) { updateEntryEditorTabList(); } @@ -1461,8 +1465,7 @@ public Map> getEntryEditorTabList() { /** * Reloads the list of the currently defined tabs in the entry editor from scratch to cache */ - @Override - public void updateEntryEditorTabList() { + private void updateEntryEditorTabList() { Map> tabs = new LinkedHashMap<>(); int i = 0; String name; @@ -1491,8 +1494,7 @@ public void updateEntryEditorTabList() { * * @param customTabs a map of tab names and the corresponding set of fields to be displayed in */ - @Override - public void storeEntryEditorTabList(Map> customTabs) { + private void storeEntryEditorTabList(Map> customTabs) { String[] names = customTabs.keySet().toArray(String[]::new); String[] fields = customTabs.values().stream() .map(set -> set.stream() @@ -1562,7 +1564,11 @@ public List getAllDefaultTabFieldNames() { @Override public EntryEditorPreferences getEntryEditorPreferences() { - return new EntryEditorPreferences(getEntryEditorTabList(), + if (Objects.nonNull(entryEditorPreferences)) { + return entryEditorPreferences; + } + + entryEditorPreferences = new EntryEditorPreferences(getEntryEditorTabList(), getBoolean(AUTO_OPEN_FORM), getBoolean(SHOW_RECOMMENDATIONS), getBoolean(ACCEPT_RECOMMENDATIONS), @@ -1571,19 +1577,18 @@ public EntryEditorPreferences getEntryEditorPreferences() { getBoolean(VALIDATE_IN_ENTRY_EDITOR), getBoolean(ALLOW_INTEGER_EDITION_BIBTEX), getDouble(ENTRY_EDITOR_HEIGHT)); - } - @Override - public void storeEntryEditorPreferences(EntryEditorPreferences preferences) { - storeEntryEditorTabList(preferences.getEntryEditorTabList()); - putBoolean(AUTO_OPEN_FORM, preferences.shouldOpenOnNewEntry()); - putBoolean(SHOW_RECOMMENDATIONS, preferences.shouldShowRecommendationsTab()); - putBoolean(ACCEPT_RECOMMENDATIONS, preferences.isMrdlibAccepted()); - putBoolean(SHOW_LATEX_CITATIONS, preferences.shouldShowLatexCitationsTab()); - putBoolean(DEFAULT_SHOW_SOURCE, preferences.showSourceTabByDefault()); - putBoolean(VALIDATE_IN_ENTRY_EDITOR, preferences.shouldEnableValidation()); - putBoolean(ALLOW_INTEGER_EDITION_BIBTEX, preferences.shouldAllowIntegerEditionBibtex()); - putDouble(ENTRY_EDITOR_HEIGHT, preferences.getDividerPosition()); + EasyBind.subscribe(entryEditorPreferences.entryEditorTabListProperty(), this::storeEntryEditorTabList); + EasyBind.subscribe(entryEditorPreferences.shouldOpenOnNewEntryProperty(), newValue -> putBoolean(AUTO_OPEN_FORM, newValue)); + EasyBind.subscribe(entryEditorPreferences.shouldShowRecommendationsTabProperty(), newValue -> putBoolean(SHOW_RECOMMENDATIONS, newValue)); + EasyBind.subscribe(entryEditorPreferences.isMrdlibAcceptedProperty(), newValue -> putBoolean(ACCEPT_RECOMMENDATIONS, newValue)); + EasyBind.subscribe(entryEditorPreferences.shouldShowLatexCitationsTabProperty(), newValue -> putBoolean(SHOW_LATEX_CITATIONS, newValue)); + EasyBind.subscribe(entryEditorPreferences.showSourceTabByDefaultProperty(), newValue -> putBoolean(DEFAULT_SHOW_SOURCE, newValue)); + EasyBind.subscribe(entryEditorPreferences.enableValidationProperty(), newValue -> putBoolean(VALIDATE_IN_ENTRY_EDITOR, newValue)); + EasyBind.subscribe(entryEditorPreferences.allowIntegerEditionBibtexProperty(), newValue -> putBoolean(ALLOW_INTEGER_EDITION_BIBTEX, newValue)); + EasyBind.subscribe(entryEditorPreferences.dividerPositionProperty(), newValue -> putDouble(ENTRY_EDITOR_HEIGHT, newValue.doubleValue())); + + return entryEditorPreferences; } //************************************************************************************************************* @@ -2680,19 +2685,22 @@ public void storeMergeDiffMode(String diffMode) { @Override public MrDlibPreferences getMrDlibPreferences() { - return new MrDlibPreferences( + if (Objects.nonNull(mrDlibPreferences)) { + return mrDlibPreferences; + } + + mrDlibPreferences = new MrDlibPreferences( getBoolean(ACCEPT_RECOMMENDATIONS), getBoolean(SEND_LANGUAGE_DATA), getBoolean(SEND_OS_DATA), getBoolean(SEND_TIMEZONE_DATA)); - } - @Override - public void storeMrDlibPreferences(MrDlibPreferences preferences) { - putBoolean(ACCEPT_RECOMMENDATIONS, preferences.shouldAcceptRecommendations()); - putBoolean(SEND_LANGUAGE_DATA, preferences.shouldSendLanguage()); - putBoolean(SEND_OS_DATA, preferences.shouldSendOs()); - putBoolean(SEND_TIMEZONE_DATA, preferences.shouldSendTimezone()); + EasyBind.subscribe(mrDlibPreferences.acceptRecommendationsProperty(), newValue -> putBoolean(ACCEPT_RECOMMENDATIONS, newValue)); + EasyBind.subscribe(mrDlibPreferences.sendLanguageProperty(), newValue -> putBoolean(SEND_LANGUAGE_DATA, newValue)); + EasyBind.subscribe(mrDlibPreferences.sendOsProperty(), newValue -> putBoolean(SEND_OS_DATA, newValue)); + EasyBind.subscribe(mrDlibPreferences.sendTimezoneProperty(), newValue -> putBoolean(SEND_TIMEZONE_DATA, newValue)); + + return mrDlibPreferences; } @Override @@ -2707,19 +2715,27 @@ public void storeIdBasedFetcherForEntryGenerator(String fetcherName) { @Override public ProtectedTermsPreferences getProtectedTermsPreferences() { - return new ProtectedTermsPreferences( + if (Objects.nonNull(protectedTermsPreferences)) { + return protectedTermsPreferences; + } + + protectedTermsPreferences = new ProtectedTermsPreferences( getStringList(PROTECTED_TERMS_ENABLED_INTERNAL), getStringList(PROTECTED_TERMS_ENABLED_EXTERNAL), getStringList(PROTECTED_TERMS_DISABLED_INTERNAL), - getStringList(PROTECTED_TERMS_DISABLED_EXTERNAL)); - } + getStringList(PROTECTED_TERMS_DISABLED_EXTERNAL) + ); - @Override - public void storeProtectedTermsPreferences(ProtectedTermsPreferences preferences) { - putStringList(PROTECTED_TERMS_ENABLED_EXTERNAL, preferences.getEnabledExternalTermLists()); - putStringList(PROTECTED_TERMS_DISABLED_EXTERNAL, preferences.getDisabledExternalTermLists()); - putStringList(PROTECTED_TERMS_ENABLED_INTERNAL, preferences.getEnabledInternalTermLists()); - putStringList(PROTECTED_TERMS_DISABLED_INTERNAL, preferences.getDisabledInternalTermLists()); + protectedTermsPreferences.getEnabledExternalTermLists().addListener((InvalidationListener) change -> + putStringList(PROTECTED_TERMS_ENABLED_EXTERNAL, protectedTermsPreferences.getEnabledExternalTermLists())); + protectedTermsPreferences.getDisabledExternalTermLists().addListener((InvalidationListener) change -> + putStringList(PROTECTED_TERMS_DISABLED_EXTERNAL, protectedTermsPreferences.getDisabledExternalTermLists())); + protectedTermsPreferences.getEnabledInternalTermLists().addListener((InvalidationListener) change -> + putStringList(PROTECTED_TERMS_ENABLED_INTERNAL, protectedTermsPreferences.getEnabledInternalTermLists())); + protectedTermsPreferences.getDisabledInternalTermLists().addListener((InvalidationListener) change -> + putStringList(PROTECTED_TERMS_DISABLED_INTERNAL, protectedTermsPreferences.getDisabledInternalTermLists())); + + return protectedTermsPreferences; } //************************************************************************************************************* @@ -2728,12 +2744,16 @@ public void storeProtectedTermsPreferences(ProtectedTermsPreferences preferences @Override public ImporterPreferences getImporterPreferences() { - importerPreferences = Objects.requireNonNullElseGet(importerPreferences, () -> new ImporterPreferences( + if (Objects.nonNull(importerPreferences)) { + return importerPreferences; + } + + importerPreferences = new ImporterPreferences( getBoolean(GENERATE_KEY_ON_IMPORT), getBoolean(GROBID_ENABLED), getBoolean(GROBID_OPT_OUT), get(GROBID_URL) - )); + ); EasyBind.subscribe(importerPreferences.generateNewKeyOnImportProperty(), newValue -> putBoolean(GENERATE_KEY_ON_IMPORT, newValue)); EasyBind.subscribe(importerPreferences.grobidEnabledProperty(), newValue -> putBoolean(GROBID_ENABLED, newValue)); diff --git a/src/main/java/org/jabref/preferences/MrDlibPreferences.java b/src/main/java/org/jabref/preferences/MrDlibPreferences.java index cb1a1b5f1b3..fd6a0b4cc4a 100644 --- a/src/main/java/org/jabref/preferences/MrDlibPreferences.java +++ b/src/main/java/org/jabref/preferences/MrDlibPreferences.java @@ -1,32 +1,67 @@ package org.jabref.preferences; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; + public class MrDlibPreferences { - private final boolean acceptRecommendations; - private final boolean shouldSendLanguage; - private final boolean shouldSendOs; - private final boolean shouldSendTimezone; + private final BooleanProperty acceptRecommendations; + private final BooleanProperty sendLanguage; + private final BooleanProperty sendOs; + private final BooleanProperty sendTimezone; public MrDlibPreferences(boolean acceptRecommendations, boolean shouldSendLanguage, boolean shouldSendOs, boolean shouldSendTimezone) { - this.acceptRecommendations = acceptRecommendations; - this.shouldSendLanguage = shouldSendLanguage; - this.shouldSendOs = shouldSendOs; - this.shouldSendTimezone = shouldSendTimezone; + this.acceptRecommendations = new SimpleBooleanProperty(acceptRecommendations); + this.sendLanguage = new SimpleBooleanProperty(shouldSendLanguage); + this.sendOs = new SimpleBooleanProperty(shouldSendOs); + this.sendTimezone = new SimpleBooleanProperty(shouldSendTimezone); } public boolean shouldAcceptRecommendations() { + return acceptRecommendations.get(); + } + + public BooleanProperty acceptRecommendationsProperty() { return acceptRecommendations; } + public void setAcceptRecommendations(boolean acceptRecommendations) { + this.acceptRecommendations.set(acceptRecommendations); + } + public boolean shouldSendLanguage() { - return shouldSendLanguage; + return sendLanguage.get(); + } + + public BooleanProperty sendLanguageProperty() { + return sendLanguage; + } + + public void setSendLanguage(boolean sendLanguage) { + this.sendLanguage.set(sendLanguage); } public boolean shouldSendOs() { - return shouldSendOs; + return sendOs.get(); + } + + public BooleanProperty sendOsProperty() { + return sendOs; + } + + public void setSendOs(boolean sendOs) { + this.sendOs.set(sendOs); } public boolean shouldSendTimezone() { - return shouldSendTimezone; + return sendTimezone.get(); + } + + public BooleanProperty sendTimezoneProperty() { + return sendTimezone; + } + + public void setSendTimezone(boolean sendTimezone) { + this.sendTimezone.set(sendTimezone); } } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index e5ce77b258f..d180b256629 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -181,20 +181,12 @@ public interface PreferencesService { // EntryEditorPreferences //************************************************************************************************************* - Map> getEntryEditorTabList(); - - void updateEntryEditorTabList(); - Map> getDefaultTabNamesAndFields(); List getAllDefaultTabFieldNames(); - void storeEntryEditorTabList(Map> customTabsMap); - EntryEditorPreferences getEntryEditorPreferences(); - void storeEntryEditorPreferences(EntryEditorPreferences preferences); - //************************************************************************************************************* // Network preferences //************************************************************************************************************* @@ -371,13 +363,9 @@ public interface PreferencesService { MrDlibPreferences getMrDlibPreferences(); - void storeMrDlibPreferences(MrDlibPreferences preferences); - String getIdBasedFetcherForEntryGenerator(); void storeIdBasedFetcherForEntryGenerator(String fetcherName); ProtectedTermsPreferences getProtectedTermsPreferences(); - - void storeProtectedTermsPreferences(ProtectedTermsPreferences preferences); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MrDLibFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MrDLibFetcherTest.java index 0a8c21cb756..830cc5f67b1 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MrDLibFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MrDLibFetcherTest.java @@ -7,7 +7,6 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.preferences.MrDlibPreferences; -import org.jabref.preferences.PreferencesService; import org.jabref.testutils.category.FetcherTest; import org.junit.jupiter.api.BeforeEach; @@ -15,8 +14,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; @FetcherTest public class MrDLibFetcherTest { @@ -25,15 +22,12 @@ public class MrDLibFetcherTest { @BeforeEach public void setUp() { - PreferencesService preferencesService = mock(PreferencesService.class); MrDlibPreferences mrDlibPreferences = new MrDlibPreferences( true, false, false, false); - when(preferencesService.getMrDlibPreferences()).thenReturn(mrDlibPreferences); - - fetcher = new MrDLibFetcher("", Version.parse(""), preferencesService); + fetcher = new MrDLibFetcher("", Version.parse(""), mrDlibPreferences); } @Test