Skip to content

Commit

Permalink
Refactor of remaining preference tabs to PreferencesService (#6836)
Browse files Browse the repository at this point in the history
* Refactored NameFormatterTab to use PreferencesService

* Refactored XmpPreferencesTab

* Fixed missing storeNameFormatterPreferences

* Refactor PreviewPreferences to conventions and use PreferencesService

* Fixed not reloading PreviewPreferences

* Removed unused preference

* Introduced GroupsPreferences and refactored GroupsTabViewModel to use them

* Cleanups

* CHANGELOG.md
  • Loading branch information
calixtus authored Sep 1, 2020
1 parent 63270ad commit 5850341
Show file tree
Hide file tree
Showing 43 changed files with 346 additions and 276 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

- We restructured the 'File' tab and extracted some parts into the 'Linked files' tab [#6779](https://github.com/JabRef/jabref/pull/6779)
- JabRef now offers journal lists from <https://abbrv.jabref.org>. JabRef the lists which use a dot inside the abbreviations. [#5749](https://github.com/JabRef/jabref/pull/5749)
- We removed two useless preferences in the groups preferences dialog. [#6836](https://github.com/JabRef/jabref/pull/6836)

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ private static void applyPreferences(JabRefPreferences preferences) {

// Build list of Import and Export formats
Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(),
Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor());
Globals.prefs.getXmpPreferences(), Globals.getFileUpdateMonitor());
Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
preferences.loadBibEntryTypes(BibDatabaseMode.BIBLATEX));
Globals.exportFactory = ExporterFactory.create(
Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationRepository),
Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository),
Globals.prefs.getSavePreferencesForExport(),
Globals.prefs.getXMPPreferences());
Globals.prefs.getXmpPreferences());

// Initialize protected terms loader
Globals.protectedTermsLoader = new ProtectedTermsLoader(Globals.prefs.getProtectedTermsPreferences());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private void importPreferences() {
LayoutFormatterPreferences layoutPreferences =
Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository);
SavePreferences savePreferences = Globals.prefs.getSavePreferencesForExport();
XmpPreferences xmpPreferences = Globals.prefs.getXMPPreferences();
XmpPreferences xmpPreferences = Globals.prefs.getXmpPreferences();
Globals.exportFactory = ExporterFactory.create(customExporters, layoutPreferences, savePreferences, xmpPreferences);
} catch (JabRefException ex) {
LOGGER.error("Cannot import preferences", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.jabref.model.bibtexkeypattern.AbstractCitationKeyPattern;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.types.EntryType;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;

Expand All @@ -32,7 +32,7 @@ public class CitationKeyPatternPanel extends TableView<CitationKeyPatternPanelIt
private long lastKeyPressTime;
private String tableSearchTerm;

public CitationKeyPatternPanel(JabRefPreferences preferences, Collection<BibEntryType> entryTypeList, AbstractCitationKeyPattern keyPattern) {
public CitationKeyPatternPanel(PreferencesService preferences, Collection<BibEntryType> entryTypeList, AbstractCitationKeyPattern keyPattern) {
super();

viewModel = new CitationKeyPatternPanelViewModel(preferences, entryTypeList, keyPattern);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.jabref.model.bibtexkeypattern.AbstractCitationKeyPattern;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.types.EntryType;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

public class CitationKeyPatternPanelViewModel {

Expand All @@ -38,9 +38,9 @@ public class CitationKeyPatternPanelViewModel {
private final ObjectProperty<CitationKeyPatternPanelItemModel> defaultItemProperty = new SimpleObjectProperty<>();
private final AbstractCitationKeyPattern initialKeyPattern;
private final Collection<BibEntryType> bibEntryTypeList;
private final JabRefPreferences preferences;
private final PreferencesService preferences;

public CitationKeyPatternPanelViewModel(JabRefPreferences preferences, Collection<BibEntryType> entryTypeList, AbstractCitationKeyPattern initialKeyPattern) {
public CitationKeyPatternPanelViewModel(PreferencesService preferences, Collection<BibEntryType> entryTypeList, AbstractCitationKeyPattern initialKeyPattern) {
this.preferences = preferences;
this.bibEntryTypeList = entryTypeList;
this.initialKeyPattern = initialKeyPattern;
Expand Down Expand Up @@ -72,12 +72,12 @@ public void setValues() {
}

public void setItemToDefaultPattern(CitationKeyPatternPanelItemModel item) {
item.setPattern((String) preferences.defaults.get(JabRefPreferences.DEFAULT_CITATION_KEY_PATTERN));
item.setPattern(preferences.getDefaultsDefaultCitationKeyPattern());
}

public void resetAll() {
patternListProperty.forEach(item -> item.setPattern(""));
defaultItemProperty.getValue().setPattern((String) preferences.defaults.get(JabRefPreferences.DEFAULT_CITATION_KEY_PATTERN));
defaultItemProperty.getValue().setPattern(preferences.getDefaultsDefaultCitationKeyPattern());
}

public ListProperty<CitationKeyPatternPanelItemModel> patternListProperty() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/exporter/ExportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void execute() {
List<TemplateExporter> customExporters = preferences.getCustomExportFormats(Globals.journalAbbreviationRepository);
LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository);
SavePreferences savePreferences = preferences.getSavePreferencesForExport();
XmpPreferences xmpPreferences = preferences.getXMPPreferences();
XmpPreferences xmpPreferences = preferences.getXmpPreferences();

// Get list of exporters and sort before adding to file dialog
List<Exporter> exporters = Globals.exportFactory.getExporters().stream()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/exporter/WriteXMPAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void writeXMP() {
for (Path file : files) {
if (Files.exists(file)) {
try {
XmpUtilWriter.writeXmp(file, entry, database, Globals.prefs.getXMPPreferences());
XmpUtilWriter.writeXmp(file, entry, database, Globals.prefs.getXmpPreferences());
Platform.runLater(
() -> optionsDialog.getProgressArea().appendText(" " + Localization.lang("OK") + ".\n"));
entriesChanged++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void addLinkedFileFromURL(BibDatabaseContext databaseContext, URL url, B
databaseContext,
Globals.TASK_EXECUTOR,
dialogService,
preferences.getXMPPreferences(),
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
ExternalFileTypes.getInstance());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public LinkedFileViewModel fromFile(Path file) {
databaseContext,
taskExecutor,
dialogService,
preferences.getXMPPreferences(),
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
externalFileTypes);
}
Expand All @@ -128,7 +128,7 @@ private List<LinkedFileViewModel> parseToFileViewModel(String stringValue) {
databaseContext,
taskExecutor,
dialogService,
preferences.getXMPPreferences(),
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
externalFileTypes))
.collect(Collectors.toList());
Expand Down Expand Up @@ -159,7 +159,7 @@ public void addNewFile() {
databaseContext,
taskExecutor,
dialogService,
preferences.getXMPPreferences(),
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
externalFileTypes));
});
Expand Down Expand Up @@ -197,7 +197,7 @@ private List<LinkedFileViewModel> findAssociatedNotLinkedFiles(BibEntry entry) {
databaseContext,
taskExecutor,
dialogService,
preferences.getXMPPreferences(),
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
externalFileTypes);
newLinkedFile.markAsAutomaticallyFound();
Expand Down Expand Up @@ -248,7 +248,7 @@ private void addFromURL(URL url) {
databaseContext,
taskExecutor,
dialogService,
preferences.getXMPPreferences(),
preferences.getXmpPreferences(),
preferences.getFilePreferences(),
externalFileTypes);
files.add(onlineFile);
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupsPreferences.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jabref.gui.groups;

public class GroupsPreferences {

private final GroupViewMode groupViewMode;
private final boolean shouldAutoAssignGroup;
private final boolean shouldDisplayGroupCount;
private final Character keywordSeparator;

public GroupsPreferences(GroupViewMode groupViewMode,
boolean shouldAutoAssignGroup,
boolean shouldDisplayGroupCount,
Character keywordSeparator) {

this.groupViewMode = groupViewMode;
this.shouldAutoAssignGroup = shouldAutoAssignGroup;
this.shouldDisplayGroupCount = shouldDisplayGroupCount;
this.keywordSeparator = keywordSeparator;
}

public GroupViewMode getGroupViewMode() {
return groupViewMode;
}

public boolean shouldAutoAssignGroup() {
return shouldAutoAssignGroup;
}

public boolean shouldDisplayGroupCount() {
return shouldDisplayGroupCount;
}

public Character getKeywordDelimiter() {
return keywordSeparator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ public void removeSelectedImporter() {
public void saveToPrefs() {
Globals.prefs.customImports.clear();
Globals.prefs.customImports.addAll(importers);
Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(), Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor());
Globals.IMPORT_FORMAT_READER.resetImportFormats(
Globals.prefs.getImportFormatPreferences(),
Globals.prefs.getXmpPreferences(),
Globals.getFileUpdateMonitor());
}

public ListProperty<CustomImporter> selectedImportersProperty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,15 @@ public void importEntries(List<BibEntry> entriesToImport, boolean shouldDownload
if (shouldDownloadFiles) {
for (BibEntry bibEntry : entriesToImport) {
for (LinkedFile linkedFile : bibEntry.getFiles()) {
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFile, bibEntry, databaseContext, taskExecutor, dialogService, preferences.getXMPPreferences(), filePreferences, ExternalFileTypes.getInstance());
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(
linkedFile,
bibEntry,
databaseContext,
taskExecutor,
dialogService,
preferences.getXmpPreferences(),
filePreferences,
ExternalFileTypes.getInstance());
linkedFileViewModel.download();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void execute() {
databaseContext,
Globals.TASK_EXECUTOR,
dialogService,
preferencesService.getXMPPreferences(),
preferencesService.getXmpPreferences(),
preferencesService.getFilePreferences(),
ExternalFileTypes.getInstance());
linkedFileViewModel.open();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void execute() {
databaseContext,
Globals.TASK_EXECUTOR,
dialogService,
preferencesService.getXMPPreferences(),
preferencesService.getXmpPreferences(),
preferencesService.getFilePreferences(),
ExternalFileTypes.getInstance()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public FileColumn(MainTableColumnModel model,
entry.getEntry(),
database, Globals.TASK_EXECUTOR,
dialogService,
preferencesService.getXMPPreferences(),
preferencesService.getXmpPreferences(),
preferencesService.getFilePreferences(),
externalFileTypes);
linkedFileViewModel.open();
Expand Down Expand Up @@ -132,7 +132,7 @@ private ContextMenu createFileMenu(BibEntryTableViewModel entry, List<LinkedFile
database,
Globals.TASK_EXECUTOR,
dialogService,
preferencesService.getXMPPreferences(),
preferencesService.getXmpPreferences(),
preferencesService.getFilePreferences(),
externalFileTypes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

public abstract class AbstractPreferenceTabView<T extends PreferenceTabViewModel> extends VBox implements PreferencesTab {

Expand All @@ -18,7 +18,7 @@ public abstract class AbstractPreferenceTabView<T extends PreferenceTabViewModel

protected T viewModel;

protected JabRefPreferences preferences;
protected PreferencesService preferences;

@Override
public Node getBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import org.jabref.gui.util.IconValidationDecorator;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;
Expand All @@ -26,7 +26,7 @@ public class AppearanceTabView extends AbstractPreferenceTabView<AppearanceTabVi

private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer();

public AppearanceTabView(JabRefPreferences preferences) {
public AppearanceTabView(PreferencesService preferences) {
this.preferences = preferences;

ViewLoader.view(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.jabref.gui.help.HelpAction;
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;

Expand All @@ -34,11 +34,11 @@ public class CitationKeyPatternTabView extends AbstractPreferenceTabView<Citatio

private final CitationKeyPatternPanel bibtexKeyPatternTable;

public CitationKeyPatternTabView(JabRefPreferences preferences) {
public CitationKeyPatternTabView(PreferencesService preferences) {
this.preferences = preferences;

bibtexKeyPatternTable = new CitationKeyPatternPanel(preferences,
Globals.entryTypesManager.getAllTypes(preferences.getDefaultBibDatabaseMode()),
Globals.entryTypesManager.getAllTypes(preferences.getGeneralPreferences().getDefaultBibDatabaseMode()),
preferences.getGlobalCitationKeyPattern());

ViewLoader.view(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import javafx.scene.control.TextField;

import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;

Expand All @@ -27,7 +27,7 @@ public class EntryEditorTabView extends AbstractPreferenceTabView<EntryEditorTab
@FXML private RadioButton firstNameModeFull;
@FXML private RadioButton firstNameModeBoth;

public EntryEditorTabView(JabRefPreferences preferences) {
public EntryEditorTabView(PreferencesService preferences) {
this.preferences = preferences;
ViewLoader.view(this)
.root(this)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/preferences/ExternalTabView.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.jabref.gui.util.IconValidationDecorator;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;
Expand All @@ -37,7 +37,7 @@ public class ExternalTabView extends AbstractPreferenceTabView<ExternalTabViewMo

private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer();

public ExternalTabView(JabRefPreferences preferences, PushToApplicationsManager pushToApplicationsManager) {
public ExternalTabView(PreferencesService preferences, PushToApplicationsManager pushToApplicationsManager) {
this.preferences = preferences;
this.pushToApplicationsManager = pushToApplicationsManager;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/preferences/FileTabView.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.NewLineSeparator;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;

Expand All @@ -38,7 +38,7 @@ public class FileTabView extends AbstractPreferenceTabView<FileTabViewModel> imp
@FXML private CheckBox autosaveLocalLibraries;
@FXML private Button autosaveLocalLibrariesHelp;

public FileTabView(JabRefPreferences preferences) {
public FileTabView(PreferencesService preferences) {
this.preferences = preferences;

ViewLoader.view(this)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/preferences/GeneralTabView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.jabref.logic.l10n.Language;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;
Expand Down Expand Up @@ -51,7 +51,7 @@ public class GeneralTabView extends AbstractPreferenceTabView<GeneralTabViewMode

private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer();

public GeneralTabView(JabRefPreferences preferences) {
public GeneralTabView(PreferencesService preferences) {
this.preferences = preferences;

ViewLoader.view(this)
Expand Down
Loading

0 comments on commit 5850341

Please sign in to comment.