diff --git a/CHANGELOG.md b/CHANGELOG.md index 76e1d0e6cb8..7a05ff48ba3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# ## [Unreleased] ### Changed +- All fields are now properly sorted alphabetically (in the subgroups of required/optional fields) when the entry is written to the bib file. +- We fixed an issue where some importers used the field `pubstatus` instead of the standard BibTeX field `pubstate`. - We changed the latex command removal for docbook exporter. [#3838](https://github.com/JabRef/jabref/issues/3838) - We changed the location of some fields in the entry editor (you might need to reset your preferences for these changes to come into effect) - Journal/Year/Month in biblatex mode -> Deprecated (if filled) diff --git a/src/jmh/java/org/jabref/benchmarks/Benchmarks.java b/src/jmh/java/org/jabref/benchmarks/Benchmarks.java index a7316584eee..d0a0704c5f6 100644 --- a/src/jmh/java/org/jabref/benchmarks/Benchmarks.java +++ b/src/jmh/java/org/jabref/benchmarks/Benchmarks.java @@ -22,6 +22,9 @@ import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.database.BibDatabaseModeDetection; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.field.UnknownField; import org.jabref.model.groups.GroupHierarchyType; import org.jabref.model.groups.KeywordGroup; import org.jabref.model.groups.WordKeywordGroup; @@ -54,12 +57,12 @@ public void init() throws Exception { for (int i = 0; i < 1000; i++) { BibEntry entry = new BibEntry(); entry.setCiteKey("id" + i); - entry.setField("title", "This is my title " + i); - entry.setField("author", "Firstname Lastname and FirstnameA LastnameA and FirstnameB LastnameB" + i); - entry.setField("journal", "Journal Title " + i); - entry.setField("keyword", "testkeyword"); - entry.setField("year", "1" + i); - entry.setField("rnd", "2" + randomizer.nextInt()); + entry.setField(StandardField.TITLE, "This is my title " + i); + entry.setField(StandardField.AUTHOR, "Firstname Lastname and FirstnameA LastnameA and FirstnameB LastnameB" + i); + entry.setField(StandardField.JOURNAL, "Journal Title " + i); + entry.setField(StandardField.KEYWORDS, "testkeyword"); + entry.setField(StandardField.YEAR, "1" + i); + entry.setField(new UnknownField("rnd"), "2" + randomizer.nextInt()); database.insertEntry(entry); } @@ -72,7 +75,7 @@ public void init() throws Exception { private StringWriter getOutputWriter() throws IOException { StringWriter outputWriter = new StringWriter(); - BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(outputWriter, mock(SavePreferences.class)); + BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(outputWriter, mock(SavePreferences.class), new BibEntryTypesManager()); databaseWriter.savePartOfDatabase( new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries()); return outputWriter; @@ -128,7 +131,7 @@ public String htmlToLatexConversion() { @Benchmark public boolean keywordGroupContains() { - KeywordGroup group = new WordKeywordGroup("testGroup", GroupHierarchyType.INDEPENDENT, "keyword", "testkeyword", false, ',', false); + KeywordGroup group = new WordKeywordGroup("testGroup", GroupHierarchyType.INDEPENDENT, StandardField.KEYWORDS, "testkeyword", false, ',', false); return group.containsAll(database.getEntries()); } diff --git a/src/main/java/org/jabref/Globals.java b/src/main/java/org/jabref/Globals.java index 0c26f8f6d38..71466ee47c7 100644 --- a/src/main/java/org/jabref/Globals.java +++ b/src/main/java/org/jabref/Globals.java @@ -21,6 +21,7 @@ import org.jabref.logic.protectedterms.ProtectedTermsLoader; import org.jabref.logic.remote.server.RemoteListenerServerLifecycle; import org.jabref.logic.util.BuildInfo; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.JabRefPreferences; @@ -61,6 +62,7 @@ public class Globals { public static StateManager stateManager = new StateManager(); public static ExporterFactory exportFactory; public static CountingUndoManager undoManager = new CountingUndoManager(); + public static BibEntryTypesManager entryTypesManager = new BibEntryTypesManager(); // Key binding preferences private static KeyBindingRepository keyBindingRepository; private static DefaultFileUpdateMonitor fileUpdateMonitor; diff --git a/src/main/java/org/jabref/JabRefMain.java b/src/main/java/org/jabref/JabRefMain.java index 62758e9c9f0..b33849356b5 100644 --- a/src/main/java/org/jabref/JabRefMain.java +++ b/src/main/java/org/jabref/JabRefMain.java @@ -22,9 +22,7 @@ import org.jabref.logic.util.JavaVersion; import org.jabref.logic.util.OS; import org.jabref.migrations.PreferencesMigrations; -import org.jabref.model.EntryTypes; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.InternalBibtexFields; import org.jabref.preferences.JabRefPreferences; import org.slf4j.Logger; @@ -153,21 +151,14 @@ private static boolean handleMultipleAppInstances(String[] args) { } private static void applyPreferences(JabRefPreferences preferences) { - // Update handling of special fields based on preferences - InternalBibtexFields.updateSpecialFields(Globals.prefs.getBoolean(JabRefPreferences.SERIALIZESPECIALFIELDS)); - // Update name of the time stamp field based on preferences - InternalBibtexFields.updateTimeStampField(Globals.prefs.getTimestampPreferences().getTimestampField()); - // Update which fields should be treated as numeric, based on preferences: - InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS)); - // Read list(s) of journal names and abbreviations Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(); // Build list of Import and Export formats Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(), Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor()); - EntryTypes.loadCustomEntryTypes(preferences.loadCustomEntryTypes(BibDatabaseMode.BIBTEX), - preferences.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX)); + Globals.entryTypesManager.addCustomizedEntryTypes(preferences.loadBibEntryTypes(BibDatabaseMode.BIBTEX), + preferences.loadBibEntryTypes(BibDatabaseMode.BIBLATEX)); Globals.exportFactory = Globals.prefs.getExporterFactory(Globals.journalAbbreviationLoader); // Initialize protected terms loader diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index 56a4de65bde..4fd9a9f2b51 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -44,7 +44,6 @@ import org.jabref.logic.util.OS; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.Defaults; -import org.jabref.model.EntryTypes; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; @@ -391,7 +390,7 @@ private void saveDatabase(BibDatabase newBase, String subName) { System.out.println(Localization.lang("Saving") + ": " + subName); SavePreferences prefs = Globals.prefs.loadForSaveFromPreferences(); AtomicFileWriter fileWriter = new AtomicFileWriter(Paths.get(subName), prefs.getEncoding()); - BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(fileWriter, prefs); + BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(fileWriter, prefs, Globals.entryTypesManager); Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode()); databaseWriter.saveDatabase(new BibDatabaseContext(newBase, defaults)); @@ -458,8 +457,8 @@ private void exportFile(List loaded, String[] data) { private void importPreferences() { try { Globals.prefs.importPreferences(cli.getPreferencesImport()); - EntryTypes.loadCustomEntryTypes(Globals.prefs.loadCustomEntryTypes(BibDatabaseMode.BIBTEX), - Globals.prefs.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX)); + Globals.entryTypesManager.addCustomizedEntryTypes(Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBTEX), + Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBLATEX)); List customExporters = Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationLoader); LayoutFormatterPreferences layoutPreferences = Globals.prefs .getLayoutFormatterPreferences(Globals.journalAbbreviationLoader); diff --git a/src/main/java/org/jabref/cli/CrossrefFetcherEvaluator.java b/src/main/java/org/jabref/cli/CrossrefFetcherEvaluator.java index 2713698933d..69641fa60c7 100644 --- a/src/main/java/org/jabref/cli/CrossrefFetcherEvaluator.java +++ b/src/main/java/org/jabref/cli/CrossrefFetcherEvaluator.java @@ -16,7 +16,7 @@ import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.identifier.DOI; import org.jabref.preferences.JabRefPreferences; @@ -53,7 +53,7 @@ public static void main(String[] args) throws IOException, InterruptedException @Override public void run() { - Optional origDOI = entry.getField(FieldName.DOI).flatMap(DOI::parse); + Optional origDOI = entry.getField(StandardField.DOI).flatMap(DOI::parse); if (origDOI.isPresent()) { dois.incrementAndGet(); try { diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index d64f2226ff0..b679083fd8d 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -92,13 +92,14 @@ import org.jabref.model.database.shared.DatabaseLocation; import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.InternalBibtexFields; import org.jabref.model.entry.LinkedFile; import org.jabref.model.entry.event.EntryChangedEvent; import org.jabref.model.entry.event.EntryEventSource; -import org.jabref.model.entry.specialfields.SpecialField; -import org.jabref.model.entry.specialfields.SpecialFieldValue; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldFactory; +import org.jabref.model.entry.field.SpecialField; +import org.jabref.model.entry.field.SpecialFieldValue; +import org.jabref.model.entry.field.StandardField; import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.PreviewPreferences; @@ -573,13 +574,13 @@ private void openExternalFile() { } JabRefExecutorService.INSTANCE.execute(() -> { final BibEntry entry = selectedEntries.get(0); - if (!entry.hasField(FieldName.FILE)) { + if (!entry.hasField(StandardField.FILE)) { // no bibtex field new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen(); return; } FileListTableModel fileListTableModel = new FileListTableModel(); - entry.getField(FieldName.FILE).ifPresent(fileListTableModel::setContent); + entry.getField(StandardField.FILE).ifPresent(fileListTableModel::setContent); if (fileListTableModel.getRowCount() == 0) { // content in BibTeX field is not readable new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen(); @@ -637,7 +638,7 @@ public void insertEntry(final BibEntry bibEntry) { // Create an UndoableInsertEntry object. getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), bibEntry)); - output(Localization.lang("Added new '%0' entry.", bibEntry.getType())); + output(Localization.lang("Added new '%0' entry.", bibEntry.getType().getDisplayName())); markBaseChanged(); // The database just changed. if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) { @@ -650,11 +651,11 @@ public void insertEntry(final BibEntry bibEntry) { } } - public void editEntryAndFocusField(BibEntry entry, String fieldName) { + public void editEntryAndFocusField(BibEntry entry, Field field) { showAndEdit(entry); Platform.runLater(() -> { // Focus field and entry in main table (async to give entry editor time to load) - entryEditor.setFocusToField(fieldName); + entryEditor.setFocusToField(field); clearAndSelect(entry); }); } @@ -808,7 +809,7 @@ public void updateSearchManager() { } private void instantiateSearchAutoCompleter() { - searchAutoCompleter = new PersonNameSuggestionProvider(InternalBibtexFields.getPersonNameFields()); + searchAutoCompleter = new PersonNameSuggestionProvider(FieldFactory.getPersonNameFields()); for (BibEntry entry : bibDatabaseContext.getDatabase().getEntries()) { searchAutoCompleter.indexEntry(entry); } @@ -1300,11 +1301,11 @@ private class OpenURLAction implements BaseAction { public void action() { final List bes = mainTable.getSelectedEntries(); if (bes.size() == 1) { - String field = FieldName.DOI; - Optional link = bes.get(0).getField(FieldName.DOI); - if (bes.get(0).hasField(FieldName.URL)) { - link = bes.get(0).getField(FieldName.URL); - field = FieldName.URL; + Field field = StandardField.DOI; + Optional link = bes.get(0).getField(StandardField.DOI); + if (bes.get(0).hasField(StandardField.URL)) { + link = bes.get(0).getField(StandardField.URL); + field = StandardField.URL; } if (link.isPresent()) { try { @@ -1320,9 +1321,9 @@ public void action() { List files = bes.get(0).getFiles(); Optional linkedFile = files.stream() - .filter(file -> (FieldName.URL.equalsIgnoreCase(file.getFileType()) - || FieldName.PS.equalsIgnoreCase(file.getFileType()) - || FieldName.PDF.equalsIgnoreCase(file.getFileType()))) + .filter(file -> (StandardField.URL.getName().equalsIgnoreCase(file.getFileType()) + || StandardField.PS.getName().equalsIgnoreCase(file.getFileType()) + || StandardField.PDF.getName().equalsIgnoreCase(file.getFileType()))) .findFirst(); if (linkedFile.isPresent()) { diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index 26bc331fbb4..0411f8afd4e 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -81,7 +81,7 @@ public void setContent(String string) { public void setContent(List entries) throws IOException { final ClipboardContent content = new ClipboardContent(); - BibEntryWriter writer = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()), false); + BibEntryWriter writer = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()), Globals.entryTypesManager); String serializedEntries = writer.serializeAll(entries, BibDatabaseMode.BIBTEX); content.put(DragAndDropDataFormats.ENTRIES, serializedEntries); content.putString(serializedEntries); diff --git a/src/main/java/org/jabref/gui/EntryTypeView.java b/src/main/java/org/jabref/gui/EntryTypeView.java index 326c1aa855a..36ab61e5a66 100644 --- a/src/main/java/org/jabref/gui/EntryTypeView.java +++ b/src/main/java/org/jabref/gui/EntryTypeView.java @@ -13,13 +13,14 @@ import javafx.scene.control.TitledPane; import javafx.scene.layout.FlowPane; +import org.jabref.Globals; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.logic.importer.IdBasedFetcher; import org.jabref.logic.l10n.Localization; -import org.jabref.model.EntryTypes; import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.BiblatexEntryTypes; import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.EntryType; @@ -84,10 +85,9 @@ public EntryTypeView(BasePanel basePanel, DialogService dialogService, JabRefPre } - private void addEntriesToPane(FlowPane pane, Collection entries) { - - for (EntryType entryType : entries) { - Button entryButton = new Button(entryType.getName()); + private void addEntriesToPane(FlowPane pane, Collection entries) { + for (BibEntryType entryType : entries) { + Button entryButton = new Button(entryType.getType().getDisplayName()); entryButton.setUserData(entryType); entryButton.setOnAction(event -> setEntryTypeForReturnAndClose(entryType)); pane.getChildren().add(entryButton); @@ -124,7 +124,7 @@ public void initialize() { bibTexTitlePane.setVisible(false); ieeeTranTitlePane.setVisible(false); - List customTypes = EntryTypes.getAllCustomTypes(BibDatabaseMode.BIBLATEX); + List customTypes = Globals.entryTypesManager.getAllCustomTypes(BibDatabaseMode.BIBLATEX); if (customTypes.isEmpty()) { customTitlePane.setVisible(false); } else { @@ -136,7 +136,7 @@ public void initialize() { addEntriesToPane(bibTexPane, BibtexEntryTypes.ALL); addEntriesToPane(ieeetranPane, IEEETranEntryTypes.ALL); - List customTypes = EntryTypes.getAllCustomTypes(BibDatabaseMode.BIBTEX); + List customTypes = Globals.entryTypesManager.getAllCustomTypes(BibDatabaseMode.BIBTEX); if (customTypes.isEmpty()) { customTitlePane.setVisible(false); } else { @@ -162,8 +162,8 @@ private void focusTextField(Event event) { idTextField.selectAll(); } - private void setEntryTypeForReturnAndClose(EntryType entryType) { - type = entryType; + private void setEntryTypeForReturnAndClose(BibEntryType entryType) { + type = entryType.getType(); viewModel.stopFetching(); this.close(); } diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index f6956a4ac23..62344a16889 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -14,6 +14,7 @@ import javafx.concurrent.Task; import javafx.concurrent.Worker; +import org.jabref.Globals; import org.jabref.gui.duplicationFinder.DuplicateResolverDialog; import org.jabref.logic.bibtex.DuplicateCheck; import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; @@ -138,7 +139,7 @@ public void runFetcherWorker() { Optional result = fetcherWorker.getValue(); if (result.isPresent()) { final BibEntry entry = result.get(); - Optional duplicate = DuplicateCheck.containsDuplicate(basePanel.getDatabase(), entry, basePanel.getBibDatabaseContext().getMode()); + Optional duplicate = new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(basePanel.getDatabase(), entry, basePanel.getBibDatabaseContext().getMode()); if ((duplicate.isPresent())) { DuplicateResolverDialog dialog = new DuplicateResolverDialog(entry, duplicate.get(), DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, basePanel.getBibDatabaseContext()); switch (dialog.showAndWait().orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK)) { diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 9922adca817..4ce6c1c1ffc 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -121,9 +121,9 @@ import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.database.shared.DatabaseLocation; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BiblatexEntryTypes; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.specialfields.SpecialField; +import org.jabref.model.entry.StandardEntryType; +import org.jabref.model.entry.field.SpecialField; +import org.jabref.model.entry.field.StandardField; import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.LastFocusedTabPreferences; @@ -526,7 +526,7 @@ private Node createToolbar() { pushToApplicationsManager.setToolBarButton(pushToApplicationButton); HBox rightSide = new HBox( - factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(this, BiblatexEntryTypes.ARTICLE, dialogService, Globals.prefs, stateManager)), + factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(this, StandardEntryType.Article, dialogService, Globals.prefs, stateManager)), factory.createIconButton(StandardActions.DELETE_ENTRY, new OldDatabaseCommandWrapper(Actions.DELETE, this, stateManager)), new Separator(Orientation.VERTICAL), factory.createIconButton(StandardActions.UNDO, new OldDatabaseCommandWrapper(Actions.UNDO, this, stateManager)), @@ -1006,7 +1006,7 @@ public void addTab(BasePanel basePanel, boolean raisePanel) { autosaver.registerListener(new AutosaveUIManager(basePanel)); } - BackupManager.start(context); + BackupManager.start(context, Globals.entryTypesManager, prefs); // Track opening trackOpenNewDatabase(basePanel); @@ -1087,7 +1087,7 @@ public void setProgressBarIndeterminate(final boolean value) { private boolean isExistFile(List selectEntryList) { if (selectEntryList.size() == 1) { BibEntry selectedEntry = selectEntryList.get(0); - return selectedEntry.getField(FieldName.FILE).isPresent(); + return selectedEntry.getField(StandardField.FILE).isPresent(); } return false; } @@ -1102,7 +1102,7 @@ private boolean isExistFile(List selectEntryList) { private boolean isExistURLorDOI(List selectEntryList) { if (selectEntryList.size() == 1) { BibEntry selectedEntry = selectEntryList.get(0); - return (selectedEntry.getField(FieldName.URL).isPresent() || selectedEntry.getField(FieldName.DOI).isPresent()); + return (selectedEntry.getField(StandardField.URL).isPresent() || selectedEntry.getField(StandardField.DOI).isPresent()); } return false; } diff --git a/src/main/java/org/jabref/gui/SaveOrderConfigDisplayView.java b/src/main/java/org/jabref/gui/SaveOrderConfigDisplayView.java index aeca6f4ddad..2c4ef4c5f6f 100644 --- a/src/main/java/org/jabref/gui/SaveOrderConfigDisplayView.java +++ b/src/main/java/org/jabref/gui/SaveOrderConfigDisplayView.java @@ -10,6 +10,7 @@ import javafx.scene.layout.GridPane; import org.jabref.logic.l10n.Localization; +import org.jabref.model.entry.field.Field; import org.jabref.model.metadata.SaveOrderConfig; import org.jabref.preferences.PreferencesService; @@ -20,9 +21,9 @@ public class SaveOrderConfigDisplayView extends GridPane { private final SaveOrderConfig config; @FXML private ToggleGroup saveOrderToggleGroup; - @FXML private ComboBox savePriSort; - @FXML private ComboBox saveSecSort; - @FXML private ComboBox saveTerSort; + @FXML private ComboBox savePriSort; + @FXML private ComboBox saveSecSort; + @FXML private ComboBox saveTerSort; @FXML private RadioButton exportInSpecifiedOrder; @FXML private RadioButton exportInTableOrder; @FXML private RadioButton exportInOriginalOrder; diff --git a/src/main/java/org/jabref/gui/SaveOrderConfigDisplayViewModel.java b/src/main/java/org/jabref/gui/SaveOrderConfigDisplayViewModel.java index 0846ee4866c..cc06c9e8cd9 100644 --- a/src/main/java/org/jabref/gui/SaveOrderConfigDisplayViewModel.java +++ b/src/main/java/org/jabref/gui/SaveOrderConfigDisplayViewModel.java @@ -1,37 +1,35 @@ package org.jabref.gui; -import java.util.Collections; -import java.util.List; -import java.util.Locale; import java.util.Objects; +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.SimpleStringProperty; -import javafx.beans.property.StringProperty; +import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.InternalBibtexFields; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldFactory; import org.jabref.model.metadata.SaveOrderConfig; import org.jabref.model.metadata.SaveOrderConfig.SortCriterion; import org.jabref.preferences.PreferencesService; public class SaveOrderConfigDisplayViewModel { - private final ListProperty priSortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); - private final ListProperty secSortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); - private final ListProperty terSortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final ListProperty priSortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final ListProperty secSortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final ListProperty terSortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); private final BooleanProperty savePriDescPropertySelected = new SimpleBooleanProperty(); private final BooleanProperty saveSecDescPropertySelected = new SimpleBooleanProperty(); private final BooleanProperty saveTerDescPropertySelected = new SimpleBooleanProperty(); - private final StringProperty savePriSortSelectedValueProperty = new SimpleStringProperty(""); - private final StringProperty saveSecSortSelectedValueProperty = new SimpleStringProperty(""); - private final StringProperty saveTerSortSelectedValueProperty = new SimpleStringProperty(""); + private final ObjectProperty savePriSortSelectedValueProperty = new SimpleObjectProperty<>(null); + private final ObjectProperty saveSecSortSelectedValueProperty = new SimpleObjectProperty<>(null); + private final ObjectProperty saveTerSortSelectedValueProperty = new SimpleObjectProperty<>(null); private final BooleanProperty saveInOriginalProperty = new SimpleBooleanProperty(); private final BooleanProperty saveInTableOrderProperty = new SimpleBooleanProperty(); @@ -42,10 +40,7 @@ public class SaveOrderConfigDisplayViewModel { public SaveOrderConfigDisplayViewModel(SaveOrderConfig config, PreferencesService prefs) { this.prefs = prefs; - List fieldNames = InternalBibtexFields.getAllPublicFieldNames(); - fieldNames.add(BibEntry.KEY_FIELD); - Collections.sort(fieldNames); - + Set fieldNames = FieldFactory.getCommonFields(); priSortFieldsProperty.addAll(fieldNames); secSortFieldsProperty.addAll(fieldNames); terSortFieldsProperty.addAll(fieldNames); @@ -53,26 +48,24 @@ public SaveOrderConfigDisplayViewModel(SaveOrderConfig config, PreferencesServic setSaveOrderConfig(config); } - public ListProperty priSortFieldsProperty() { + public ListProperty priSortFieldsProperty() { return priSortFieldsProperty; } - public ListProperty secSortFieldsProperty() { + public ListProperty secSortFieldsProperty() { return secSortFieldsProperty; } - public ListProperty terSortFieldsProperty() { + public ListProperty terSortFieldsProperty() { return terSortFieldsProperty; } public SaveOrderConfig getSaveOrderConfig() { - SortCriterion primary = new SortCriterion(getSelectedItemAsLowerCaseTrim(savePriSortSelectedValueProperty), savePriDescPropertySelected.getValue()); - SortCriterion secondary = new SortCriterion(getSelectedItemAsLowerCaseTrim(saveSecSortSelectedValueProperty), saveSecDescPropertySelected.getValue()); - SortCriterion tertiary = new SortCriterion(getSelectedItemAsLowerCaseTrim(saveTerSortSelectedValueProperty), saveTerDescPropertySelected.getValue()); - - SaveOrderConfig saveOrderConfig = new SaveOrderConfig(saveInOriginalProperty.getValue(), saveInSpecifiedOrderProperty.getValue(), primary, secondary, tertiary); + SortCriterion primary = new SortCriterion(savePriSortSelectedValueProperty.get(), savePriDescPropertySelected.getValue()); + SortCriterion secondary = new SortCriterion(saveSecSortSelectedValueProperty.get(), saveSecDescPropertySelected.getValue()); + SortCriterion tertiary = new SortCriterion(saveTerSortSelectedValueProperty.get(), saveTerDescPropertySelected.getValue()); - return saveOrderConfig; + return new SaveOrderConfig(saveInOriginalProperty.getValue(), saveInSpecifiedOrderProperty.getValue(), primary, secondary, tertiary); } public void setSaveOrderConfig(SaveOrderConfig saveOrderConfig) { @@ -95,10 +88,6 @@ public void setSaveOrderConfig(SaveOrderConfig saveOrderConfig) { } - private String getSelectedItemAsLowerCaseTrim(StringProperty string) { - return string.getValue().toLowerCase(Locale.ROOT).trim(); - } - public BooleanProperty savePriDescPropertySelected() { return savePriDescPropertySelected; } @@ -111,15 +100,15 @@ public BooleanProperty saveTerDescPropertySelected() { return saveTerDescPropertySelected; } - public StringProperty savePriSortSelectedValueProperty() { + public ObjectProperty savePriSortSelectedValueProperty() { return savePriSortSelectedValueProperty; } - public StringProperty saveSecSortSelectedValueProperty() { + public ObjectProperty saveSecSortSelectedValueProperty() { return saveSecSortSelectedValueProperty; } - public StringProperty saveTerSortSelectedValueProperty() { + public ObjectProperty saveTerSortSelectedValueProperty() { return saveTerSortSelectedValueProperty; } diff --git a/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java b/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java index 1a54be767f1..bd2088e6a3c 100644 --- a/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java +++ b/src/main/java/org/jabref/gui/autocompleter/AutoCompletePreferences.java @@ -1,22 +1,21 @@ package org.jabref.gui.autocompleter; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; +import java.util.Set; import org.jabref.logic.journals.JournalAbbreviationPreferences; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldFactory; public class AutoCompletePreferences { - private static final String DELIMITER = ";"; private boolean shouldAutoComplete; private AutoCompleteFirstNameMode firstNameMode; private boolean onlyCompleteLastFirst; private boolean onlyCompleteFirstLast; - private List completeFields; + private Set completeFields; private final JournalAbbreviationPreferences journalAbbreviationPreferences; - public AutoCompletePreferences(boolean shouldAutoComplete, AutoCompleteFirstNameMode firstNameMode, boolean onlyCompleteLastFirst, boolean onlyCompleteFirstLast, List completeFields, JournalAbbreviationPreferences journalAbbreviationPreferences) { + public AutoCompletePreferences(boolean shouldAutoComplete, AutoCompleteFirstNameMode firstNameMode, boolean onlyCompleteLastFirst, boolean onlyCompleteFirstLast, Set completeFields, JournalAbbreviationPreferences journalAbbreviationPreferences) { this.shouldAutoComplete = shouldAutoComplete; this.firstNameMode = firstNameMode; this.onlyCompleteLastFirst = onlyCompleteLastFirst; @@ -64,20 +63,20 @@ public void setOnlyCompleteFirstLast(boolean onlyCompleteFirstLast) { * Returns the list of fields for which autocomplete is enabled * @return List of field names */ - public List getCompleteFields() { + public Set getCompleteFields() { return completeFields; } - public void setCompleteFields(List completeFields) { + public void setCompleteFields(Set completeFields) { this.completeFields = completeFields; } public void setCompleteNames(String input) { - setCompleteFields(Arrays.asList(input.split(DELIMITER))); + setCompleteFields(FieldFactory.parseFieldList(input)); } public String getCompleteNamesAsString() { - return completeFields.stream().collect(Collectors.joining(DELIMITER)); + return FieldFactory.serializeFieldsList(completeFields); } public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { diff --git a/src/main/java/org/jabref/gui/autocompleter/BibEntrySuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/BibEntrySuggestionProvider.java index db1e4546b6b..3a5ecbffae4 100644 --- a/src/main/java/org/jabref/gui/autocompleter/BibEntrySuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/BibEntrySuggestionProvider.java @@ -4,6 +4,7 @@ import org.jabref.logic.bibtex.comparator.EntryComparator; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.InternalField; import org.controlsfx.control.textfield.AutoCompletionBinding; @@ -23,7 +24,7 @@ public void indexEntry(BibEntry entry) { @Override protected Comparator getComparator() { - return new EntryComparator(false, true, BibEntry.KEY_FIELD); + return new EntryComparator(false, true, InternalField.KEY_FIELD); } @Override diff --git a/src/main/java/org/jabref/gui/autocompleter/FieldValueSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/FieldValueSuggestionProvider.java index 871723b2cd7..87048951ec4 100644 --- a/src/main/java/org/jabref/gui/autocompleter/FieldValueSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/FieldValueSuggestionProvider.java @@ -3,16 +3,17 @@ import java.util.Objects; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; /** * Stores the full content of one field. */ class FieldValueSuggestionProvider extends StringSuggestionProvider implements AutoCompleteSuggestionProvider { - private final String fieldName; + private final Field field; - FieldValueSuggestionProvider(String fieldName) { - this.fieldName = Objects.requireNonNull(fieldName); + FieldValueSuggestionProvider(Field field) { + this.field = Objects.requireNonNull(field); } @Override @@ -21,6 +22,6 @@ public void indexEntry(BibEntry entry) { return; } - entry.getField(fieldName).ifPresent(fieldValue -> addPossibleSuggestions(fieldValue.trim())); + entry.getField(field).ifPresent(fieldValue -> addPossibleSuggestions(fieldValue.trim())); } } diff --git a/src/main/java/org/jabref/gui/autocompleter/JournalsSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/JournalsSuggestionProvider.java index f0749e3c7c7..5e8b5c95f4d 100644 --- a/src/main/java/org/jabref/gui/autocompleter/JournalsSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/JournalsSuggestionProvider.java @@ -6,13 +6,13 @@ import org.jabref.logic.journals.Abbreviation; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.logic.journals.JournalAbbreviationPreferences; +import org.jabref.model.entry.field.Field; public class JournalsSuggestionProvider extends FieldValueSuggestionProvider { - - JournalsSuggestionProvider(String fieldName, AutoCompletePreferences preferences, + JournalsSuggestionProvider(Field field, AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) { - super(fieldName); + super(field); JournalAbbreviationPreferences journalAbbreviationPreferences = preferences.getJournalAbbreviationPreferences(); List journals = abbreviationLoader.getRepository(journalAbbreviationPreferences) diff --git a/src/main/java/org/jabref/gui/autocompleter/PersonNameSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/PersonNameSuggestionProvider.java index 8182be6a33c..db84646648d 100644 --- a/src/main/java/org/jabref/gui/autocompleter/PersonNameSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/PersonNameSuggestionProvider.java @@ -1,13 +1,14 @@ package org.jabref.gui.autocompleter; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.List; import java.util.Objects; import org.jabref.model.entry.Author; import org.jabref.model.entry.AuthorList; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; import org.controlsfx.control.textfield.AutoCompletionBinding; @@ -16,17 +17,17 @@ */ public class PersonNameSuggestionProvider extends SuggestionProvider implements AutoCompleteSuggestionProvider { - private final List fieldNames; + private final Collection fields; private final Comparator authorComparator = Comparator.comparing(Author::getNameForAlphabetization); - PersonNameSuggestionProvider(String fieldName) { + PersonNameSuggestionProvider(Field fieldName) { this(Collections.singletonList(Objects.requireNonNull(fieldName))); } - public PersonNameSuggestionProvider(List fieldNames) { + public PersonNameSuggestionProvider(Collection fields) { super(); - this.fieldNames = Objects.requireNonNull(fieldNames); + this.fields = Objects.requireNonNull(fields); } @@ -36,8 +37,8 @@ public void indexEntry(BibEntry entry) { return; } - for (String fieldName : fieldNames) { - entry.getField(fieldName).ifPresent(fieldValue -> { + for (Field field : fields) { + entry.getField(field).ifPresent(fieldValue -> { AuthorList authorList = AuthorList.parse(fieldValue); for (Author author : authorList.getAuthors()) { addPossibleSuggestions(author); diff --git a/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java b/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java index a4bf835a19b..4f8f76a405c 100644 --- a/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java +++ b/src/main/java/org/jabref/gui/autocompleter/SuggestionProviders.java @@ -1,23 +1,23 @@ package org.jabref.gui.autocompleter; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import org.jabref.logic.journals.JournalAbbreviationLoader; import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.FieldProperty; -import org.jabref.model.entry.InternalBibtexFields; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldProperty; +import org.jabref.model.entry.field.StandardField; public class SuggestionProviders { /** * key: field name */ - private final Map> providers = new HashMap<>(); + private final Map> providers = new HashMap<>(); /** * Empty @@ -30,15 +30,15 @@ public SuggestionProviders(AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) { Objects.requireNonNull(preferences); - List completeFields = preferences.getCompleteFields(); - for (String field : completeFields) { + Set completeFields = preferences.getCompleteFields(); + for (Field field : completeFields) { AutoCompleteSuggestionProvider autoCompleter = initalizeSuggestionProvider(field, preferences, abbreviationLoader); providers.put(field, autoCompleter); } } - public AutoCompleteSuggestionProvider getForField(String fieldName) { - return providers.get(fieldName); + public AutoCompleteSuggestionProvider getForField(Field field) { + return providers.get(field); } public void indexDatabase(BibDatabase database) { @@ -56,16 +56,17 @@ public void indexEntry(BibEntry bibEntry) { } } - private AutoCompleteSuggestionProvider initalizeSuggestionProvider(String fieldName, AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) { - if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.PERSON_NAMES)) { - return new PersonNameSuggestionProvider(fieldName); - } else if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.SINGLE_ENTRY_LINK)) { + private AutoCompleteSuggestionProvider initalizeSuggestionProvider(Field field, AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) { + Set fieldProperties = field.getProperties(); + if (fieldProperties.contains(FieldProperty.PERSON_NAMES)) { + return new PersonNameSuggestionProvider(field); + } else if (fieldProperties.contains(FieldProperty.SINGLE_ENTRY_LINK)) { return new BibEntrySuggestionProvider(); - } else if (InternalBibtexFields.getFieldProperties(fieldName).contains(FieldProperty.JOURNAL_NAME) - || FieldName.PUBLISHER.equals(fieldName)) { - return new JournalsSuggestionProvider(fieldName, preferences, abbreviationLoader); + } else if (fieldProperties.contains(FieldProperty.JOURNAL_NAME) + || StandardField.PUBLISHER.equals(field)) { + return new JournalsSuggestionProvider(field, preferences, abbreviationLoader); } else { - return new WordSuggestionProvider(fieldName); + return new WordSuggestionProvider(field); } } } diff --git a/src/main/java/org/jabref/gui/autocompleter/WordSuggestionProvider.java b/src/main/java/org/jabref/gui/autocompleter/WordSuggestionProvider.java index 0f9c2ec56fa..a591d684a3b 100644 --- a/src/main/java/org/jabref/gui/autocompleter/WordSuggestionProvider.java +++ b/src/main/java/org/jabref/gui/autocompleter/WordSuggestionProvider.java @@ -4,6 +4,7 @@ import java.util.StringTokenizer; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; /** * Stores all words in the given field which are separated by SEPARATING_CHARS. @@ -12,10 +13,10 @@ public class WordSuggestionProvider extends StringSuggestionProvider implements private static final String SEPARATING_CHARS = ";,\n "; - private final String fieldName; + private final Field field; - public WordSuggestionProvider(String fieldName) { - this.fieldName = Objects.requireNonNull(fieldName); + public WordSuggestionProvider(Field field) { + this.field = Objects.requireNonNull(field); } @Override @@ -24,7 +25,7 @@ public void indexEntry(BibEntry entry) { return; } - entry.getField(fieldName).ifPresent(fieldValue -> { + entry.getField(field).ifPresent(fieldValue -> { StringTokenizer tok = new StringTokenizer(fieldValue, SEPARATING_CHARS); while (tok.hasMoreTokens()) { addPossibleSuggestions(tok.nextToken()); diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java index e1e81d2bc03..76649341ab2 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java @@ -1,7 +1,6 @@ package org.jabref.gui.bibtexkeypattern; import java.util.HashMap; -import java.util.Locale; import java.util.Map; import javafx.scene.Node; @@ -18,11 +17,11 @@ import org.jabref.gui.help.HelpAction; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; -import org.jabref.model.EntryTypes; import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import org.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; import org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.EntryType; import org.jabref.preferences.JabRefPreferences; @@ -32,7 +31,7 @@ public class BibtexKeyPatternPanel extends Pane { protected final TextField defaultPat = new TextField(); // one field for each type - private final Map textFields = new HashMap<>(); + private final Map textFields = new HashMap<>(); private final BasePanel panel; private final GridPane gridPane = new GridPane(); @@ -43,6 +42,14 @@ public BibtexKeyPatternPanel(BasePanel panel) { buildGUI(); } + private static void setValue(TextField tf, EntryType fieldName, AbstractBibtexKeyPattern keyPattern) { + if (keyPattern.isDefaultValue(fieldName)) { + tf.setText(""); + } else { + tf.setText(keyPattern.getValue(fieldName).get(0)); + } + } + private void buildGUI() { BibDatabaseMode mode; // check mode of currently used DB @@ -74,8 +81,8 @@ private void buildGUI() { gridPane.add(button, 3, rowIndex); columnIndex = 1; - for (EntryType type : EntryTypes.getAllValues(mode)) { - Label label1 = new Label(type.getName()); + for (BibEntryType type : Globals.entryTypesManager.getAllTypes(mode)) { + Label label1 = new Label(type.getType().getDisplayName()); TextField textField = new TextField(); Button button1 = new Button("Default"); button1.setOnAction(e1 -> textField.setText((String) Globals.prefs.defaults.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); @@ -84,7 +91,7 @@ private void buildGUI() { gridPane.add(textField, 2 + (columnIndex * 3), rowIndex); gridPane.add(button1, 3 + (columnIndex * 3), rowIndex); - textFields.put(type.getName().toLowerCase(Locale.ROOT), textField); + textFields.put(type.getType(), textField); if (columnIndex == (columnsNumber - 1)) { columnIndex = 0; @@ -111,12 +118,24 @@ private void buildGUI() { gridPane.add(btnDefaultAll1, 2, rowIndex); } + protected GlobalBibtexKeyPattern getKeyPatternAsGlobalBibtexKeyPattern() { + GlobalBibtexKeyPattern res = GlobalBibtexKeyPattern.fromPattern(Globals.prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN)); + fillPatternUsingPanelData(res); + return res; + } + + public DatabaseBibtexKeyPattern getKeyPatternAsDatabaseBibtexKeyPattern() { + DatabaseBibtexKeyPattern res = new DatabaseBibtexKeyPattern(Globals.prefs.getKeyPattern()); + fillPatternUsingPanelData(res); + return res; + } + /** * fill the given LabelPattern by values generated from the text fields */ private void fillPatternUsingPanelData(AbstractBibtexKeyPattern keypatterns) { // each entry type - for (Map.Entry entry : textFields.entrySet()) { + for (Map.Entry entry : textFields.entrySet()) { String text = entry.getValue().getText(); if (!text.trim().isEmpty()) { keypatterns.addBibtexKeyPattern(entry.getKey(), text); @@ -130,25 +149,13 @@ private void fillPatternUsingPanelData(AbstractBibtexKeyPattern keypatterns) { } } - protected GlobalBibtexKeyPattern getKeyPatternAsGlobalBibtexKeyPattern() { - GlobalBibtexKeyPattern res = GlobalBibtexKeyPattern.fromPattern(Globals.prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN)); - fillPatternUsingPanelData(res); - return res; - } - - public DatabaseBibtexKeyPattern getKeyPatternAsDatabaseBibtexKeyPattern() { - DatabaseBibtexKeyPattern res = new DatabaseBibtexKeyPattern(Globals.prefs.getKeyPattern()); - fillPatternUsingPanelData(res); - return res; - } - /** * Fills the current values to the text fields * * @param keyPattern the BibtexKeyPattern to use as initial value */ public void setValues(AbstractBibtexKeyPattern keyPattern) { - for (Map.Entry entry : textFields.entrySet()) { + for (Map.Entry entry : textFields.entrySet()) { setValue(entry.getValue(), entry.getKey(), keyPattern); } @@ -159,14 +166,6 @@ public void setValues(AbstractBibtexKeyPattern keyPattern) { } } - private static void setValue(TextField tf, String fieldName, AbstractBibtexKeyPattern keyPattern) { - if (keyPattern.isDefaultValue(fieldName)) { - tf.setText(""); - } else { - tf.setText(keyPattern.getValue(fieldName).get(0)); - } - } - public Node getPanel() { return gridPane; } diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java index 9149ef4a5f0..719c11bc267 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java @@ -15,7 +15,7 @@ import org.jabref.logic.cleanup.Cleanups; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.entry.FieldName; +import org.jabref.model.entry.field.StandardField; import org.jabref.model.metadata.FilePreferences; import com.airhacks.afterburner.views.ViewLoader; @@ -62,7 +62,7 @@ private void init(CleanupPreset cleanupPreset, FilePreferences filePreferences) cleanUpRenamePDFonlyRelativePaths.disableProperty().bind(cleanUpRenamePDF.selectedProperty().not()); - cleanUpUpgradeExternalLinks.setText(Localization.lang("Upgrade external PDF/PS links to use the '%0' field.", FieldName.FILE)); + cleanUpUpgradeExternalLinks.setText(Localization.lang("Upgrade external PDF/PS links to use the '%0' field.", StandardField.FILE.getDisplayName())); cleanUpFormatters = new FieldFormatterCleanupsPanel(Localization.lang("Run field formatter:"), Cleanups.DEFAULT_SAVE_ACTIONS); formatterContainer.getChildren().setAll(cleanUpFormatters); diff --git a/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java b/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java index ab544366e0d..ffb8aa18e69 100644 --- a/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java +++ b/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java @@ -1,9 +1,9 @@ package org.jabref.gui.cleanup; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.Set; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; @@ -29,8 +29,9 @@ import org.jabref.model.cleanup.FieldFormatterCleanups; import org.jabref.model.cleanup.Formatter; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.InternalBibtexFields; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldFactory; +import org.jabref.model.entry.field.InternalField; import org.jabref.model.metadata.MetaData; import org.fxmisc.easybind.EasyBind; @@ -42,7 +43,7 @@ public class FieldFormatterCleanupsPanel extends GridPane { private FieldFormatterCleanups fieldFormatterCleanups; private ListView actionsList; private ComboBox formattersCombobox; - private ComboBox selectFieldCombobox; + private ComboBox selectFieldCombobox; private Button addButton; private Label descriptionAreaText; private Button removeButton; @@ -161,10 +162,9 @@ private void updateDescription() { */ private GridPane getSelectorPanel() { GridPane builder = new GridPane(); - List fieldNames = InternalBibtexFields.getAllPublicAndInternalFieldNames(); - fieldNames.add(BibEntry.KEY_FIELD); - Collections.sort(fieldNames); - selectFieldCombobox = new ComboBox<>(FXCollections.observableArrayList(fieldNames)); + Set fields = FieldFactory.getCommonFields(); + fields.add(InternalField.KEY_FIELD); + selectFieldCombobox = new ComboBox<>(FXCollections.observableArrayList(fields)); selectFieldCombobox.setEditable(true); builder.add(selectFieldCombobox, 1, 1); @@ -217,8 +217,8 @@ public boolean isDefaultSaveActions() { private FieldFormatterCleanup getFieldFormatterCleanup() { Formatter selectedFormatter = formattersCombobox.getValue(); - String fieldKey = selectFieldCombobox.getValue(); - return new FieldFormatterCleanup(fieldKey, selectedFormatter); + Field field = selectFieldCombobox.getValue(); + return new FieldFormatterCleanup(field, selectedFormatter); } class EnablementStatusListener implements ChangeListener { diff --git a/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java b/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java index fcad087163d..8cd799b204c 100644 --- a/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java @@ -16,6 +16,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,12 +44,12 @@ public EntryChangeViewModel(BibEntry memEntry, BibEntry tmpEntry, BibEntry diskE LOGGER.debug("Modified entry: " + memEntry.getCiteKeyOptional().orElse("") + "\n Modified locally: " + isModifiedLocally + " Modifications agree: " + modificationsAgree); - Set allFields = new TreeSet<>(); - allFields.addAll(memEntry.getFieldNames()); - allFields.addAll(tmpEntry.getFieldNames()); - allFields.addAll(diskEntry.getFieldNames()); + Set allFields = new TreeSet<>(); + allFields.addAll(memEntry.getFields()); + allFields.addAll(tmpEntry.getFields()); + allFields.addAll(diskEntry.getFields()); - for (String field : allFields) { + for (Field field : allFields) { Optional mem = memEntry.getField(field); Optional tmp = tmpEntry.getField(field); Optional disk = diskEntry.getField(field); @@ -94,13 +95,13 @@ static class FieldChangeViewModel extends DatabaseChangeViewModel { private final BibEntry entry; private final BibEntry tmpEntry; - private final String field; + private final Field field; private final String inMem; private final String onTmp; private final String onDisk; - public FieldChangeViewModel(String field, BibEntry memEntry, BibEntry tmpEntry, String inMem, String onTmp, String onDisk) { - super(field); + public FieldChangeViewModel(Field field, BibEntry memEntry, BibEntry tmpEntry, String inMem, String onTmp, String onDisk) { + super(field.getName()); entry = memEntry; this.tmpEntry = tmpEntry; this.field = field; diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.fxml b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.fxml index 091f3b3ab91..a2f89fa69af 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.fxml +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.fxml @@ -16,7 +16,7 @@