diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b56837dd03..21f968a73ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ### Changed +- 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 . JabRef the lists which use a dot inside the abbreviations. [#5749](https://github.com/JabRef/jabref/pull/5749) ### Fixed diff --git a/docs/adr/0016-mutable-preferences-objects.md b/docs/adr/0016-mutable-preferences-objects.md new file mode 100644 index 00000000000..df12a307db8 --- /dev/null +++ b/docs/adr/0016-mutable-preferences-objects.md @@ -0,0 +1,16 @@ +# Mutable preferences objects + +## Context and Problem Statement + +To create an immutable preferences object every time seems to be a waste of time and computer memory. + +## Considered Options + +* Create a new object every time a preferences object should be altered by a with*-method, similar to a Builder. +* Alter the existing object and return it. + +## Decision Outcome + +Chosen option: 1, because the preferences objects are just wrappers around the basic preferences framework of JDK. They +should be mutable on-the-fly similar to objects with a Builder inside and to be stored immediatly again in the +preferences. diff --git a/src/main/java/org/jabref/JabRefMain.java b/src/main/java/org/jabref/JabRefMain.java index e004d0e1627..369190d5cb5 100644 --- a/src/main/java/org/jabref/JabRefMain.java +++ b/src/main/java/org/jabref/JabRefMain.java @@ -11,6 +11,7 @@ import org.jabref.cli.JabRefCLI; import org.jabref.gui.FXDialog; import org.jabref.gui.remote.JabRefMessageHandler; +import org.jabref.logic.exporter.ExporterFactory; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.ProxyAuthenticator; @@ -168,7 +169,11 @@ private static void applyPreferences(JabRefPreferences preferences) { Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor()); Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.loadBibEntryTypes(BibDatabaseMode.BIBTEX), preferences.loadBibEntryTypes(BibDatabaseMode.BIBLATEX)); - Globals.exportFactory = Globals.prefs.getExporterFactory(Globals.journalAbbreviationRepository); + Globals.exportFactory = ExporterFactory.create( + Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationRepository), + Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository), + Globals.prefs.getSavePreferencesForExport(), + Globals.prefs.getXMPPreferences()); // Initialize protected terms loader Globals.protectedTermsLoader = new ProtectedTermsLoader(Globals.prefs.getProtectedTermsPreferences()); diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index a5d723cfcdb..9aaecfc92de 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -273,7 +273,7 @@ private boolean exportMatches(List loaded) { // export new database Optional exporter = Globals.exportFactory.getExporterByName(formatName); - if (!exporter.isPresent()) { + if (exporter.isEmpty()) { System.err.println(Localization.lang("Unknown export format") + ": " + formatName); } else { // We have an TemplateExporter instance: @@ -387,7 +387,7 @@ private boolean generateAux(List loaded, String[] data) { private void saveDatabase(BibDatabase newBase, String subName) { try { System.out.println(Localization.lang("Saving") + ": " + subName); - SavePreferences prefs = Globals.prefs.loadForSaveFromPreferences(); + SavePreferences prefs = Globals.prefs.getSavePreferences(); AtomicFileWriter fileWriter = new AtomicFileWriter(Path.of(subName), prefs.getEncoding()); BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(fileWriter, prefs, Globals.entryTypesManager); databaseWriter.saveDatabase(new BibDatabaseContext(newBase)); @@ -435,7 +435,7 @@ private void exportFile(List loaded, String[] data) { .getFileDirectories(Globals.prefs.getFilePreferences()); System.out.println(Localization.lang("Exporting") + ": " + data[0]); Optional exporter = Globals.exportFactory.getExporterByName(data[1]); - if (!exporter.isPresent()) { + if (exporter.isEmpty()) { System.err.println(Localization.lang("Unknown export format") + ": " + data[1]); } else { // We have an exporter: @@ -458,9 +458,9 @@ private void importPreferences() { Globals.entryTypesManager.addCustomOrModifiedTypes(Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBTEX), Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBLATEX)); List customExporters = Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationRepository); - LayoutFormatterPreferences layoutPreferences = Globals.prefs - .getLayoutFormatterPreferences(Globals.journalAbbreviationRepository); - SavePreferences savePreferences = Globals.prefs.loadForExportFromPreferences(); + LayoutFormatterPreferences layoutPreferences = + Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository); + SavePreferences savePreferences = Globals.prefs.getSavePreferencesForExport(); XmpPreferences xmpPreferences = Globals.prefs.getXMPPreferences(); Globals.exportFactory = ExporterFactory.create(customExporters, layoutPreferences, savePreferences, xmpPreferences); } catch (JabRefException ex) { @@ -495,7 +495,11 @@ private void automaticallySetFileLinks(List loaded) { for (ParserResult parserResult : loaded) { BibDatabase database = parserResult.getDatabase(); LOGGER.info(Localization.lang("Automatically setting file links")); - AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(parserResult.getDatabaseContext(), Globals.prefs.getFilePreferences(), Globals.prefs.getAutoLinkPreferences(), ExternalFileTypes.getInstance()); + AutoSetFileLinksUtil util = new AutoSetFileLinksUtil( + parserResult.getDatabaseContext(), + Globals.prefs.getFilePreferences(), + Globals.prefs.getAutoLinkPreferences(), + ExternalFileTypes.getInstance()); util.linkAssociatedFiles(database.getEntries(), new NamedCompound("")); } } @@ -534,7 +538,7 @@ private Optional fetch(String fetchCommand) { Optional selectedFetcher = fetchers.stream() .filter(fetcher -> fetcher.getName().equalsIgnoreCase(engine)) .findFirst(); - if (!selectedFetcher.isPresent()) { + if (selectedFetcher.isEmpty()) { System.out.println(Localization.lang("Could not find fetcher '%0'", engine)); System.out.println(Localization.lang("The following fetchers are available:")); diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 924adeacbc3..116c84e14c7 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -70,7 +70,7 @@ public ExporterViewModel saveExporter() { // Create a new exporter to be returned to ExportCustomizationDialogViewModel, which requested it LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(repository); - SavePreferences savePreferences = preferences.loadForExportFromPreferences(); + SavePreferences savePreferences = preferences.getSavePreferencesForExport(); TemplateExporter format = new TemplateExporter(name.get(), layoutFile.get(), extension.get(), layoutPreferences, savePreferences); format.setCustomExport(true); diff --git a/src/main/java/org/jabref/gui/exporter/ExportCommand.java b/src/main/java/org/jabref/gui/exporter/ExportCommand.java index 3a9534fcf65..010708dc30d 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCommand.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCommand.java @@ -53,7 +53,7 @@ public ExportCommand(JabRefFrame frame, boolean selectedOnly, JabRefPreferences public void execute() { List customExporters = preferences.getCustomExportFormats(Globals.journalAbbreviationRepository); LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository); - SavePreferences savePreferences = preferences.loadForExportFromPreferences(); + SavePreferences savePreferences = preferences.getSavePreferencesForExport(); XmpPreferences xmpPreferences = preferences.getXMPPreferences(); // Get list of exporters and sort before adding to file dialog diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index 8abfc0dfc18..871d0acfdcd 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -166,7 +166,7 @@ private Optional askForSavePath() { private boolean save(BibDatabaseContext bibDatabaseContext, SaveDatabaseMode mode) { Optional databasePath = bibDatabaseContext.getDatabasePath(); - if (!databasePath.isPresent()) { + if (databasePath.isEmpty()) { Optional savePath = askForSavePath(); if (!savePath.isPresent()) { return false; @@ -216,10 +216,10 @@ private boolean save(Path targetPath, SaveDatabaseMode mode) { } private boolean saveDatabase(Path file, boolean selectedOnly, Charset encoding, SavePreferences.DatabaseSaveType saveType) throws SaveException { - SavePreferences preferences = this.preferences.loadForSaveFromPreferences() + SavePreferences preferences = this.preferences.getSavePreferences() .withEncoding(encoding) .withSaveType(saveType); - try (AtomicFileWriter fileWriter = new AtomicFileWriter(file, preferences.getEncoding(), preferences.makeBackup())) { + try (AtomicFileWriter fileWriter = new AtomicFileWriter(file, preferences.getEncoding(), preferences.shouldMakeBackup())) { BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(fileWriter, preferences, entryTypesManager); if (selectedOnly) { diff --git a/src/main/java/org/jabref/gui/externalfiles/AutoLinkFilesAction.java b/src/main/java/org/jabref/gui/externalfiles/AutoLinkFilesAction.java index 505137edc35..487e9250a33 100644 --- a/src/main/java/org/jabref/gui/externalfiles/AutoLinkFilesAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/AutoLinkFilesAction.java @@ -52,8 +52,12 @@ public void execute() { List entries = stateManager.getSelectedEntries(); final NamedCompound nc = new NamedCompound(Localization.lang("Automatically set file links")); - AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(database, preferences.getFilePreferences(), preferences.getAutoLinkPreferences(), ExternalFileTypes.getInstance()); - Task> linkFilesTask = new Task>() { + AutoSetFileLinksUtil util = new AutoSetFileLinksUtil( + database, + preferences.getFilePreferences(), + preferences.getAutoLinkPreferences(), + ExternalFileTypes.getInstance()); + Task> linkFilesTask = new Task<>() { @Override protected List call() { diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 7e4dafd5f04..2ba1f4dc78c 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -465,7 +465,7 @@ public BackgroundTask prepareDownloadTask(Path targetDirectory, URLDownloa String suggestedTypeName = externalFileType.getName(); linkedFile.setFileType(suggestedTypeName); String suggestedName = linkedFileHandler.getSuggestedFileName(externalFileType.getExtension()); - String fulltextDir = FileUtil.createDirNameFromPattern(databaseContext.getDatabase(), entry, filePreferences.getFileDirPattern()); + String fulltextDir = FileUtil.createDirNameFromPattern(databaseContext.getDatabase(), entry, filePreferences.getFileDirectoryPattern()); suggestedName = FileNameUniqueness.getNonOverWritingFileName(targetDirectory.resolve(fulltextDir), suggestedName); return targetDirectory.resolve(fulltextDir).resolve(suggestedName); }) diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index 23b8c6b7dc5..50f69c0c0d5 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -101,7 +101,15 @@ public LinkedFileViewModel fromFile(Path file) { List fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFilePreferences()); LinkedFile linkedFile = fromFile(file, fileDirectories, externalFileTypes); - return new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences.getXMPPreferences(), preferences.getFilePreferences(), externalFileTypes); + return new LinkedFileViewModel( + linkedFile, + entry, + databaseContext, + taskExecutor, + dialogService, + preferences.getXMPPreferences(), + preferences.getFilePreferences(), + externalFileTypes); } public boolean isFulltextLookupInProgress() { @@ -114,7 +122,15 @@ public BooleanProperty fulltextLookupInProgressProperty() { private List parseToFileViewModel(String stringValue) { return FileFieldParser.parse(stringValue).stream() - .map(linkedFile -> new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences.getXMPPreferences(), preferences.getFilePreferences(), externalFileTypes)) + .map(linkedFile -> new LinkedFileViewModel( + linkedFile, + entry, + databaseContext, + taskExecutor, + dialogService, + preferences.getXMPPreferences(), + preferences.getFilePreferences(), + externalFileTypes)) .collect(Collectors.toList()); } @@ -137,7 +153,15 @@ public void addNewFile() { List fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFilePreferences()); dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> { LinkedFile newLinkedFile = fromFile(newFile, fileDirectories, externalFileTypes); - files.add(new LinkedFileViewModel(newLinkedFile, entry, databaseContext, taskExecutor, dialogService, preferences.getXMPPreferences(), preferences.getFilePreferences(), externalFileTypes)); + files.add(new LinkedFileViewModel( + newLinkedFile, + entry, + databaseContext, + taskExecutor, + dialogService, + preferences.getXMPPreferences(), + preferences.getFilePreferences(), + externalFileTypes)); }); } @@ -159,11 +183,23 @@ public void bindToEntry(BibEntry entry) { private List findAssociatedNotLinkedFiles(BibEntry entry) { List result = new ArrayList<>(); - AutoSetFileLinksUtil util = new AutoSetFileLinksUtil(databaseContext, preferences.getFilePreferences(), preferences.getAutoLinkPreferences(), ExternalFileTypes.getInstance()); + AutoSetFileLinksUtil util = new AutoSetFileLinksUtil( + databaseContext, + preferences.getFilePreferences(), + preferences.getAutoLinkPreferences(), + ExternalFileTypes.getInstance()); try { List linkedFiles = util.findAssociatedNotLinkedFiles(entry); for (LinkedFile linkedFile : linkedFiles) { - LinkedFileViewModel newLinkedFile = new LinkedFileViewModel(linkedFile, entry, databaseContext, taskExecutor, dialogService, preferences.getXMPPreferences(), preferences.getFilePreferences(), externalFileTypes); + LinkedFileViewModel newLinkedFile = new LinkedFileViewModel( + linkedFile, + entry, + databaseContext, + taskExecutor, + dialogService, + preferences.getXMPPreferences(), + preferences.getFilePreferences(), + externalFileTypes); newLinkedFile.markAsAutomaticallyFound(); result.add(newLinkedFile); } @@ -206,7 +242,15 @@ public void addFromURL() { } private void addFromURL(URL url) { - LinkedFileViewModel onlineFile = new LinkedFileViewModel(new LinkedFile(url, ""), entry, databaseContext, taskExecutor, dialogService, preferences.getXMPPreferences(), preferences.getFilePreferences(), externalFileTypes); + LinkedFileViewModel onlineFile = new LinkedFileViewModel( + new LinkedFile(url, ""), + entry, + databaseContext, + taskExecutor, + dialogService, + preferences.getXMPPreferences(), + preferences.getFilePreferences(), + externalFileTypes); files.add(onlineFile); onlineFile.download(); } diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index 2c12cd4cda4..a41d4371d9b 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -61,7 +61,14 @@ public class ImportEntriesViewModel extends AbstractViewModel { * @param databaseContext the database to import into * @param task the task executed for parsing the selected files(s). */ - public ImportEntriesViewModel(BackgroundTask task, TaskExecutor taskExecutor, BibDatabaseContext databaseContext, DialogService dialogService, UndoManager undoManager, PreferencesService preferences, StateManager stateManager, FileUpdateMonitor fileUpdateMonitor) { + public ImportEntriesViewModel(BackgroundTask task, + TaskExecutor taskExecutor, + BibDatabaseContext databaseContext, + DialogService dialogService, + UndoManager undoManager, + PreferencesService preferences, + StateManager stateManager, + FileUpdateMonitor fileUpdateMonitor) { this.taskExecutor = taskExecutor; this.databaseContext = databaseContext; this.dialogService = dialogService; @@ -94,9 +101,9 @@ public ObservableList getEntries() { } public boolean hasDuplicate(BibEntry entry) { - return findInternalDuplicate(entry).isPresent() - || - new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(databaseContext.getDatabase(), entry, databaseContext.getMode()).isPresent(); + return findInternalDuplicate(entry).isPresent() || + new DuplicateCheck(Globals.entryTypesManager) + .containsDuplicate(databaseContext.getDatabase(), entry, databaseContext.getMode()).isPresent(); } /** @@ -132,8 +139,8 @@ public void importEntries(List entriesToImport, boolean shouldDownload } // Remember the selection in the dialog - FilePreferences filePreferences = preferences.getFilePreferences(); - filePreferences.setShouldDownloadLinkedFiles(shouldDownloadFiles); + FilePreferences filePreferences = preferences.getFilePreferences() + .withShouldDownloadLinkedFiles(shouldDownloadFiles); preferences.storeFilePreferences(filePreferences); if (shouldDownloadFiles) { diff --git a/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java b/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java index 426bbbe516a..7029505ac20 100644 --- a/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java +++ b/src/main/java/org/jabref/gui/menus/FileHistoryMenu.java @@ -11,16 +11,16 @@ import org.jabref.gui.importer.actions.OpenDatabaseAction; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.io.FileHistory; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; public class FileHistoryMenu extends Menu { private final FileHistory history; - private final JabRefPreferences preferences; + private final PreferencesService preferences; private final DialogService dialogService; private final OpenDatabaseAction openDatabaseAction; - public FileHistoryMenu(JabRefPreferences preferences, DialogService dialogService, OpenDatabaseAction openDatabaseAction) { + public FileHistoryMenu(PreferencesService preferences, DialogService dialogService, OpenDatabaseAction openDatabaseAction) { setText(Localization.lang("Recent libraries")); this.preferences = preferences; diff --git a/src/main/java/org/jabref/gui/preferences/AppearanceTabViewModel.java b/src/main/java/org/jabref/gui/preferences/AppearanceTabViewModel.java index b2f3e1638b0..e2edc7a78cb 100644 --- a/src/main/java/org/jabref/gui/preferences/AppearanceTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/AppearanceTabViewModel.java @@ -194,7 +194,7 @@ public void importCSSFile() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(StandardFileType.CSS) .withDefaultExtension(StandardFileType.CSS) - .withInitialDirectory(preferences.setLastPreferencesExportPath()).build(); + .withInitialDirectory(preferences.getLastPreferencesExportPath()).build(); dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> customPathToThemeProperty.setValue(file.toAbsolutePath().toString())); diff --git a/src/main/java/org/jabref/gui/preferences/ExportSortingTab.fxml b/src/main/java/org/jabref/gui/preferences/ExportSortingTab.fxml deleted file mode 100644 index 205de97c15c..00000000000 --- a/src/main/java/org/jabref/gui/preferences/ExportSortingTab.fxml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - diff --git a/src/main/java/org/jabref/gui/preferences/ExportSortingTabView.java b/src/main/java/org/jabref/gui/preferences/ExportSortingTabView.java deleted file mode 100644 index 1535b937809..00000000000 --- a/src/main/java/org/jabref/gui/preferences/ExportSortingTabView.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.jabref.gui.preferences; - -import java.util.ArrayList; -import java.util.List; - -import javafx.fxml.FXML; - -import org.jabref.gui.commonfxcontrols.SaveOrderConfigPanel; -import org.jabref.logic.l10n.Localization; -import org.jabref.preferences.JabRefPreferences; - -import com.airhacks.afterburner.views.ViewLoader; - -public class ExportSortingTabView extends AbstractPreferenceTabView implements PreferencesTab { - - @FXML private SaveOrderConfigPanel exportOrderPanel; - - public ExportSortingTabView(JabRefPreferences preferences) { - this.preferences = preferences; - - ViewLoader.view(this) - .root(this) - .load(); - } - - public void initialize() { - this.viewModel = new ExportSortingTabViewModel(preferences); - - exportOrderPanel.saveInOriginalProperty().bindBidirectional(viewModel.saveInOriginalProperty()); - exportOrderPanel.saveInTableOrderProperty().bindBidirectional(viewModel.saveInTableOrderProperty()); - exportOrderPanel.saveInSpecifiedOrderProperty().bindBidirectional(viewModel.saveInSpecifiedOrderProperty()); - exportOrderPanel.primarySortFieldsProperty().bind(viewModel.primarySortFieldsProperty()); - exportOrderPanel.secondarySortFieldsProperty().bind(viewModel.secondarySortFieldsProperty()); - exportOrderPanel.tertiarySortFieldsProperty().bind(viewModel.tertiarySortFieldsProperty()); - exportOrderPanel.savePrimaryDescPropertySelected().bindBidirectional(viewModel.savePrimaryDescPropertySelected()); - exportOrderPanel.saveSecondaryDescPropertySelected().bindBidirectional(viewModel.saveSecondaryDescPropertySelected()); - exportOrderPanel.saveTertiaryDescPropertySelected().bindBidirectional(viewModel.saveTertiaryDescPropertySelected()); - exportOrderPanel.savePrimarySortSelectedValueProperty().bindBidirectional(viewModel.savePrimarySortSelectedValueProperty()); - exportOrderPanel.saveSecondarySortSelectedValueProperty().bindBidirectional(viewModel.saveSecondarySortSelectedValueProperty()); - exportOrderPanel.saveTertiarySortSelectedValueProperty().bindBidirectional(viewModel.saveTertiarySortSelectedValueProperty()); - } - - @Override - public String getTabName() { - return Localization.lang("Export sorting"); - } - - @Override - public boolean validateSettings() { - return true; - } - - @Override - public List getRestartWarnings() { - return new ArrayList<>(); - } -} diff --git a/src/main/java/org/jabref/gui/preferences/ExportSortingTabViewModel.java b/src/main/java/org/jabref/gui/preferences/ExportSortingTabViewModel.java deleted file mode 100644 index bd34863774c..00000000000 --- a/src/main/java/org/jabref/gui/preferences/ExportSortingTabViewModel.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.jabref.gui.preferences; - -import java.util.List; -import java.util.Set; - -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.ListProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleListProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.collections.FXCollections; - -import org.jabref.model.entry.field.Field; -import org.jabref.model.entry.field.FieldFactory; -import org.jabref.model.metadata.SaveOrderConfig; -import org.jabref.preferences.PreferencesService; - -public class ExportSortingTabViewModel implements PreferenceTabViewModel { - // SaveOrderConfigPanel - private final BooleanProperty saveInOriginalProperty = new SimpleBooleanProperty(); - private final BooleanProperty saveInTableOrderProperty = new SimpleBooleanProperty(); - private final BooleanProperty saveInSpecifiedOrderProperty = new SimpleBooleanProperty(); - // ToDo: The single criterions should really be a map or a list. - private final ListProperty primarySortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); - private final ListProperty secondarySortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); - private final ListProperty tertiarySortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); - private final BooleanProperty savePrimaryDescPropertySelected = new SimpleBooleanProperty(); - private final BooleanProperty saveSecondaryDescPropertySelected = new SimpleBooleanProperty(); - private final BooleanProperty saveTertiaryDescPropertySelected = new SimpleBooleanProperty(); - private final ObjectProperty savePrimarySortSelectedValueProperty = new SimpleObjectProperty<>(null); - private final ObjectProperty saveSecondarySortSelectedValueProperty = new SimpleObjectProperty<>(null); - private final ObjectProperty saveTertiarySortSelectedValueProperty = new SimpleObjectProperty<>(null); - - private final PreferencesService preferences; - - ExportSortingTabViewModel(PreferencesService preferences) { - this.preferences = preferences; - } - - @Override - public void setValues() { - SaveOrderConfig initialExportOrder = preferences.loadExportSaveOrder(); - - if (initialExportOrder.saveInOriginalOrder()) { - saveInOriginalProperty.setValue(true); - } else if (initialExportOrder.saveInSpecifiedOrder()) { - saveInSpecifiedOrderProperty.setValue(true); - } else { - saveInTableOrderProperty.setValue(true); - } - - Set fieldNames = FieldFactory.getCommonFields(); - primarySortFieldsProperty.addAll(fieldNames); - secondarySortFieldsProperty.addAll(fieldNames); - tertiarySortFieldsProperty.addAll(fieldNames); - - savePrimarySortSelectedValueProperty.setValue(initialExportOrder.getSortCriteria().get(0).field); - saveSecondarySortSelectedValueProperty.setValue(initialExportOrder.getSortCriteria().get(1).field); - saveTertiarySortSelectedValueProperty.setValue(initialExportOrder.getSortCriteria().get(2).field); - - savePrimaryDescPropertySelected.setValue(initialExportOrder.getSortCriteria().get(0).descending); - saveSecondaryDescPropertySelected.setValue(initialExportOrder.getSortCriteria().get(1).descending); - saveTertiaryDescPropertySelected.setValue(initialExportOrder.getSortCriteria().get(2).descending); - } - - @Override - public void storeSettings() { - SaveOrderConfig newSaveOrderConfig = new SaveOrderConfig( - saveInOriginalProperty.getValue(), - saveInSpecifiedOrderProperty.getValue(), - new SaveOrderConfig.SortCriterion( - savePrimarySortSelectedValueProperty.get(), - savePrimaryDescPropertySelected.getValue()), - new SaveOrderConfig.SortCriterion( - saveSecondarySortSelectedValueProperty.get(), - saveSecondaryDescPropertySelected.getValue()), - new SaveOrderConfig.SortCriterion( - saveTertiarySortSelectedValueProperty.get(), - saveTertiaryDescPropertySelected.getValue())); - preferences.storeExportSaveOrder(newSaveOrderConfig); - } - - @Override - public boolean validateSettings() { - return false; - } - - @Override - public List getRestartWarnings() { - return null; - } - - // SaveOrderConfigPanel - - public BooleanProperty saveInOriginalProperty() { - return saveInOriginalProperty; - } - - public BooleanProperty saveInTableOrderProperty() { - return saveInTableOrderProperty; - } - - public BooleanProperty saveInSpecifiedOrderProperty() { - return saveInSpecifiedOrderProperty; - } - - public ListProperty primarySortFieldsProperty() { - return primarySortFieldsProperty; - } - - public ListProperty secondarySortFieldsProperty() { - return secondarySortFieldsProperty; - } - - public ListProperty tertiarySortFieldsProperty() { - return tertiarySortFieldsProperty; - } - - public ObjectProperty savePrimarySortSelectedValueProperty() { - return savePrimarySortSelectedValueProperty; - } - - public ObjectProperty saveSecondarySortSelectedValueProperty() { - return saveSecondarySortSelectedValueProperty; - } - - public ObjectProperty saveTertiarySortSelectedValueProperty() { - return saveTertiarySortSelectedValueProperty; - } - - public BooleanProperty savePrimaryDescPropertySelected() { - return savePrimaryDescPropertySelected; - } - - public BooleanProperty saveSecondaryDescPropertySelected() { - return saveSecondaryDescPropertySelected; - } - - public BooleanProperty saveTertiaryDescPropertySelected() { - return saveTertiaryDescPropertySelected; - } -} diff --git a/src/main/java/org/jabref/gui/preferences/FileTab.fxml b/src/main/java/org/jabref/gui/preferences/FileTab.fxml index c3c5e78ee23..4e88ff5144e 100644 --- a/src/main/java/org/jabref/gui/preferences/FileTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/FileTab.fxml @@ -1,23 +1,22 @@ - - - - - + + - + - - + + + + + + +