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

Observable preferences B (ProtectedTerms, EntryEditor and MrDlib) #8046

Merged
merged 20 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9f5d83a
Proposal using obserables
tobiasdiez Aug 26, 2021
0cef9f1
Added some flesh to poc
calixtus Aug 26, 2021
44dfde6
Merge remote-tracking branch 'upstream/main' into observable-prefs
calixtus Aug 31, 2021
abbcf2f
Refactored ImporterPreferences to new preferences logic and fixed som…
calixtus Aug 31, 2021
deca803
Update EntryEditor.java
calixtus Aug 31, 2021
7516e3f
Only use Grobid when enabled (#8042)
btut Aug 31, 2021
c0e2814
Refactored ProtectedTermsPreferences to observable prefs
calixtus Aug 31, 2021
57afad2
Fixed ProtectedTermsTab
calixtus Aug 31, 2021
1186603
Reworked context menu and improved visuals of ProtectedTermsTab
calixtus Aug 31, 2021
5bc2974
Merge remote-tracking branch 'upstream/main' into observable-prefs
calixtus Aug 31, 2021
e7c38e1
Merge remote-tracking branch 'upstream/observable-prefs' into observa…
calixtus Aug 31, 2021
7813ae5
Merge remote-tracking branch 'upstream/main' into observable-prefs-b
calixtus Aug 31, 2021
c32a8dd
Merge remote-tracking branch 'upstream/main' into observable-prefs
calixtus Aug 31, 2021
d31593a
Merge branch 'observable-prefs' into observable-prefs-b
calixtus Aug 31, 2021
c4b6ec5
Fixed merge error
calixtus Aug 31, 2021
dbc1c10
Merge branch 'observable-prefs' into observable-prefs-b
calixtus Aug 31, 2021
cc3d0a2
Refactored MrDlibPreferences to prefrences observables
calixtus Aug 31, 2021
5044585
Refactored EntryEditorpreferences to observable preferences
calixtus Aug 31, 2021
de7bdfb
Fixed error and remark, made some small visual improvements on Protec…
calixtus Sep 1, 2021
ea5eb15
Merge remote-tracking branch 'upstream/main' into observable-prefs-b
calixtus Sep 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
124 changes: 100 additions & 24 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Set<Field>> 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<String, Set<Field>> 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<String, Set<Field>> entryEditorTabList,
boolean shouldOpenOnNewEntry,
Expand All @@ -27,55 +36,122 @@ public EntryEditorPreferences(Map<String, Set<Field>> 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<String, Set<Field>> getEntryEditorTabList() {
return entryEditorTabList.get();
}

public Map<String, Set<Field>> getEntryEditorTabList() {
public MapProperty<String, Set<Field>> entryEditorTabListProperty() {
return entryEditorTabList;
}

public void setEntryEditorTabList(Map<String, Set<Field>> 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);
}
}
13 changes: 7 additions & 6 deletions src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/icon/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public void resetPreferences() {
*/
private void updateAfterPreferenceChanges() {
// Reload internal preferences cache
preferences.updateEntryEditorTabList();
preferences.updateGlobalCitationKeyPattern();
preferences.updateMainTableColumns();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> 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());
Expand All @@ -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();
calixtus marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -79,7 +82,7 @@ public void storeSettings() {
customTabsMap.put(parts[0], FieldFactory.parseFieldList(parts[1]));
}

preferences.storeEntryEditorTabList(customTabsMap);
entryEditorPreferences.setEntryEditorTabList(customTabsMap);
}

public StringProperty fieldsProperty() {
Expand Down
Loading