From 4b39b78e4afcd6c36b385f5c46f1d9a4eac2e29b Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 2 Aug 2019 09:20:10 +0200 Subject: [PATCH] Move to extended enums for fields and entry types (#5148) * Introduce interface for fields * Continue using fields interface instead of strings * Introduce OrFields class * Move FieldProperty * Convert entry types to extended enum * Start fixing build * Fix build * Start fixing tests * Everything compiles again * Make model tests pass * Fix most tests * Fix build * Fix a few more tests * Fix a few more tests * Fix a few more tests * Fix a few more tests * Fix checkstyle issues * Fix more tests * Fix more tests * Disable test that fails on CI * Disable test that fails on CI --- CHANGELOG.md | 2 + .../org/jabref/benchmarks/Benchmarks.java | 19 +- src/main/java/org/jabref/Globals.java | 2 + src/main/java/org/jabref/JabRefMain.java | 13 +- .../org/jabref/cli/ArgumentProcessor.java | 7 +- .../jabref/cli/CrossrefFetcherEvaluator.java | 4 +- src/main/java/org/jabref/gui/BasePanel.java | 37 +- .../java/org/jabref/gui/ClipBoardManager.java | 2 +- .../java/org/jabref/gui/EntryTypeView.java | 18 +- .../org/jabref/gui/EntryTypeViewModel.java | 3 +- src/main/java/org/jabref/gui/JabRefFrame.java | 14 +- .../gui/SaveOrderConfigDisplayView.java | 7 +- .../gui/SaveOrderConfigDisplayViewModel.java | 55 +- .../AutoCompletePreferences.java | 19 +- .../BibEntrySuggestionProvider.java | 3 +- .../FieldValueSuggestionProvider.java | 9 +- .../JournalsSuggestionProvider.java | 6 +- .../PersonNameSuggestionProvider.java | 15 +- .../autocompleter/SuggestionProviders.java | 35 +- .../autocompleter/WordSuggestionProvider.java | 9 +- .../BibtexKeyPatternPanel.java | 55 +- .../gui/cleanup/CleanupPresetPanel.java | 4 +- .../cleanup/FieldFormatterCleanupsPanel.java | 20 +- .../gui/collab/EntryChangeViewModel.java | 17 +- .../ContentSelectorDialog.fxml | 2 +- .../ContentSelectorDialogView.java | 21 +- .../ContentSelectorDialogViewModel.java | 128 +- .../CustomizeEntryAction.java | 2 +- .../EntryTypeCustomizationDialog.java | 34 +- .../gui/customentrytypes/EntryTypeList.java | 139 -- .../customentrytypes/FieldSetComponent.java | 2 +- ...CustomizeGeneralFieldsDialogViewModel.java | 8 +- .../org/jabref/gui/desktop/JabRefDesktop.java | 34 +- .../duplicationFinder/DuplicateSearch.java | 2 +- .../gui/edit/CopyBibTeXKeyAndLinkAction.java | 4 +- .../jabref/gui/edit/MassSetFieldsDialog.java | 19 +- .../gui/edit/ReplaceStringViewModel.java | 25 +- .../gui/entryeditor/DeprecatedFieldsTab.java | 26 +- .../jabref/gui/entryeditor/EntryEditor.java | 10 +- .../entryeditor/EntryEditorPreferences.java | 12 +- .../gui/entryeditor/EntryEditorTab.java | 5 +- .../gui/entryeditor/EntryEditorTabList.java | 15 +- .../gui/entryeditor/FieldsEditorTab.java | 68 +- .../jabref/gui/entryeditor/MathSciNetTab.java | 4 +- .../gui/entryeditor/OptionalFields2Tab.java | 18 +- .../gui/entryeditor/OptionalFieldsTab.java | 22 +- .../gui/entryeditor/OtherFieldsTab.java | 43 +- .../gui/entryeditor/RelatedArticlesTab.java | 14 +- .../gui/entryeditor/RequiredFieldsTab.java | 32 +- .../org/jabref/gui/entryeditor/SourceTab.java | 14 +- .../gui/entryeditor/UserDefinedFieldsTab.java | 17 +- .../fileannotationtab/FileAnnotationTab.java | 4 +- .../gui/exporter/SaveDatabaseAction.java | 8 +- .../externalfiles/AutoSetFileLinksUtil.java | 6 +- .../gui/externalfiles/ImportHandler.java | 4 +- .../EditExternalFileTypeViewModel.java | 2 +- .../ExternalFileMenuItem.java | 22 +- .../externalfiletype/ExternalFileType.java | 8 +- .../fieldeditors/AbstractEditorViewModel.java | 17 +- .../gui/fieldeditors/BibtexKeyEditor.java | 5 +- .../BibtexKeyEditorViewModel.java | 5 +- .../jabref/gui/fieldeditors/DateEditor.java | 5 +- .../gui/fieldeditors/DateEditorViewModel.java | 5 +- .../EditorTypeEditorViewModel.java | 5 +- .../jabref/gui/fieldeditors/FieldEditors.java | 106 +- .../gui/fieldeditors/FieldNameLabel.java | 6 +- .../fieldeditors/GenderEditorViewModel.java | 5 +- .../gui/fieldeditors/IdentifierEditor.java | 13 +- .../IdentifierEditorViewModel.java | 18 +- .../gui/fieldeditors/JournalEditor.java | 5 +- .../fieldeditors/JournalEditorViewModel.java | 7 +- .../gui/fieldeditors/KeywordsEditor.java | 5 +- .../gui/fieldeditors/LinkedEntriesEditor.java | 5 +- .../LinkedEntriesEditorViewModel.java | 5 +- .../gui/fieldeditors/LinkedFilesEditor.java | 7 +- .../LinkedFilesEditorViewModel.java | 5 +- .../fieldeditors/MapBasedEditorViewModel.java | 5 +- .../fieldeditors/MonthEditorViewModel.java | 5 +- .../gui/fieldeditors/MultilineEditor.java | 5 +- .../fieldeditors/OptionEditorViewModel.java | 5 +- .../jabref/gui/fieldeditors/OwnerEditor.java | 5 +- .../fieldeditors/OwnerEditorViewModel.java | 5 +- .../PaginationEditorViewModel.java | 5 +- .../PatentTypeEditorViewModel.java | 5 +- .../gui/fieldeditors/PersonsEditor.java | 5 +- .../fieldeditors/PersonsEditorViewModel.java | 5 +- .../jabref/gui/fieldeditors/SimpleEditor.java | 10 +- .../fieldeditors/SimpleEditorViewModel.java | 5 +- .../gui/fieldeditors/TypeEditorViewModel.java | 5 +- .../jabref/gui/fieldeditors/UrlEditor.java | 5 +- .../gui/fieldeditors/UrlEditorViewModel.java | 5 +- .../fieldeditors/YesNoEditorViewModel.java | 5 +- .../org/jabref/gui/groups/GroupDialog.java | 22 +- .../gui/groups/WarnAssignmentSideEffects.java | 26 +- .../ImportCustomEntryTypesDialog.fxml | 5 +- .../ImportCustomEntryTypesDialog.java | 15 +- ...ImportCustomEntryTypesDialogViewModel.java | 31 +- .../gui/importer/ImportEntriesDialog.java | 24 +- .../gui/importer/ImportEntriesViewModel.java | 6 +- .../actions/CheckForNewEntryTypesAction.java | 15 +- .../gui/integrity/IntegrityCheckAction.java | 2 +- .../gui/integrity/IntegrityCheckDialog.java | 4 +- .../jabref/gui/journals/AbbreviateAction.java | 5 +- .../gui/journals/UnabbreviateAction.java | 5 +- .../gui/journals/UndoableAbbreviator.java | 3 +- .../gui/journals/UndoableUnabbreviator.java | 13 +- .../gui/maintable/BibEntryTableViewModel.java | 16 +- .../org/jabref/gui/maintable/CellFactory.java | 49 +- .../gui/maintable/ColumnPreferences.java | 6 +- .../gui/maintable/MainTableColumnFactory.java | 71 +- .../gui/maintable/NormalTableColumn.java | 52 +- .../jabref/gui/maintable/RightClickMenu.java | 17 +- .../jabref/gui/menus/ChangeEntryTypeMenu.java | 21 +- .../gui/mergeentries/FetchAndMergeEntry.java | 34 +- .../jabref/gui/mergeentries/MergeEntries.java | 40 +- .../MergeWithFetchedEntryAction.java | 9 +- .../org/jabref/gui/openoffice/OOBibBase.java | 12 +- .../gui/openoffice/StyleSelectDialogView.java | 4 +- .../gui/preferences/FileTabViewModel.java | 6 +- .../gui/preferences/GeneralTabViewModel.java | 4 - .../gui/preferences/TableColumnsTab.java | 6 +- .../jabref/gui/preferences/XmpPrefsTab.java | 14 +- .../ManageProtectedTermsViewModel.java | 2 +- .../gui/specialfields/SpecialFieldAction.java | 2 +- .../specialfields/SpecialFieldDropDown.java | 4 +- .../SpecialFieldMenuItemFactory.java | 4 +- .../SpecialFieldUpdateListener.java | 11 +- .../SpecialFieldValueViewModel.java | 2 +- .../specialfields/SpecialFieldViewModel.java | 4 +- .../jabref/gui/undo/UndoableChangeType.java | 14 +- .../jabref/gui/undo/UndoableFieldChange.java | 9 +- .../gui/util/comparator/IconComparator.java | 50 - .../jabref/gui/worker/SendAsEMailAction.java | 2 +- .../java/org/jabref/logic/TypedBibEntry.java | 17 +- .../autosaveandbackup/BackupManager.java | 15 +- .../logic/auxparser/DefaultAuxParser.java | 4 +- .../jabref/logic/bibtex/BibEntryWriter.java | 94 +- .../jabref/logic/bibtex/DuplicateCheck.java | 189 +-- .../logic/bibtex/FieldContentParser.java | 22 +- .../bibtex/FieldContentParserPreferences.java | 9 +- .../logic/bibtex/LatexFieldFormatter.java | 48 +- .../LatexFieldFormatterPreferences.java | 11 +- .../bibtex/comparator/BibDatabaseDiff.java | 8 +- .../comparator/CrossRefEntryComparator.java | 6 +- .../bibtex/comparator/EntryComparator.java | 22 +- .../bibtex/comparator/FieldComparator.java | 54 +- .../bibtexkeypattern/BibtexKeyGenerator.java | 3 +- .../bibtexkeypattern/BracketedPattern.java | 74 +- src/main/java/org/jabref/logic/bst/VM.java | 25 +- .../logic/citationstyle/CSLAdapter.java | 11 +- .../org/jabref/logic/cleanup/Cleanups.java | 24 +- .../cleanup/ConvertToBiblatexCleanup.java | 27 +- .../logic/cleanup/ConvertToBibtexCleanup.java | 27 +- .../org/jabref/logic/cleanup/DoiCleanup.java | 22 +- .../jabref/logic/cleanup/EprintCleanup.java | 15 +- .../logic/cleanup/FileLinksCleanup.java | 8 +- .../org/jabref/logic/cleanup/ISSNCleanup.java | 8 +- .../logic/cleanup/MoveFieldCleanup.java | 7 +- .../cleanup/UpgradePdfPsToFileCleanup.java | 17 +- .../logic/exporter/BibDatabaseWriter.java | 34 +- .../logic/exporter/BibTeXMLExporter.java | 103 +- .../logic/exporter/BibtexDatabaseWriter.java | 16 +- .../logic/exporter/GroupSerializer.java | 6 +- .../logic/exporter/MetaDataSerializer.java | 7 +- .../jabref/logic/exporter/ModsExporter.java | 150 +- .../jabref/logic/exporter/OOCalcDatabase.java | 87 +- .../exporter/OpenDocumentRepresentation.java | 81 +- .../logic/exporter/TemplateExporter.java | 6 +- .../jabref/logic/exporter/XmpExporter.java | 4 +- .../importer/EntryBasedParserFetcher.java | 2 +- .../logic/importer/FulltextFetchers.java | 8 +- .../logic/importer/IdBasedParserFetcher.java | 2 +- .../logic/importer/IdParserFetcher.java | 2 +- .../jabref/logic/importer/ParserResult.java | 16 +- .../importer/SearchBasedParserFetcher.java | 2 +- .../jabref/logic/importer/WebFetchers.java | 36 +- .../jabref/logic/importer/fetcher/ACS.java | 4 +- .../jabref/logic/importer/fetcher/ArXiv.java | 35 +- .../fetcher/AstrophysicsDataSystem.java | 19 +- .../logic/importer/fetcher/CiteSeer.java | 7 +- .../logic/importer/fetcher/CrossRef.java | 40 +- .../logic/importer/fetcher/DBLPFetcher.java | 4 +- .../logic/importer/fetcher/DOAJFetcher.java | 39 +- .../logic/importer/fetcher/DoiFetcher.java | 8 +- .../logic/importer/fetcher/DoiResolution.java | 4 +- .../logic/importer/fetcher/GoogleScholar.java | 6 +- .../jabref/logic/importer/fetcher/IEEE.java | 48 +- .../importer/fetcher/INSPIREFetcher.java | 7 +- .../importer/fetcher/IacrEprintFetcher.java | 14 +- .../logic/importer/fetcher/IsbnFetcher.java | 4 +- .../fetcher/IsbnViaChimboriFetcher.java | 5 +- .../fetcher/IsbnViaEbookDeFetcher.java | 12 +- .../logic/importer/fetcher/MathSciNet.java | 21 +- .../importer/fetcher/MedlineFetcher.java | 13 +- .../logic/importer/fetcher/MrDLibFetcher.java | 4 +- .../logic/importer/fetcher/OpenAccessDoi.java | 6 +- .../logic/importer/fetcher/ScienceDirect.java | 4 +- .../importer/fetcher/SpringerFetcher.java | 42 +- .../logic/importer/fetcher/SpringerLink.java | 4 +- .../logic/importer/fetcher/TitleFetcher.java | 4 +- .../jabref/logic/importer/fetcher/ZbMATH.java | 11 +- .../importer/fileformat/BibTeXMLImporter.java | 70 +- .../fileformat/BiblioscapeImporter.java | 87 +- .../importer/fileformat/BibtexParser.java | 53 +- .../importer/fileformat/CoinsParser.java | 29 +- .../importer/fileformat/CopacImporter.java | 47 +- .../importer/fileformat/EndnoteImporter.java | 89 +- .../fileformat/EndnoteXmlImporter.java | 50 +- .../importer/fileformat/FreeCiteImporter.java | 53 +- .../logic/importer/fileformat/GvkParser.java | 64 +- .../importer/fileformat/InspecImporter.java | 37 +- .../importer/fileformat/IsiImporter.java | 81 +- .../importer/fileformat/MedlineImporter.java | 195 +-- .../fileformat/MedlinePlainImporter.java | 248 ++-- .../importer/fileformat/ModsImporter.java | 102 +- .../importer/fileformat/MrDLibImporter.java | 12 +- .../importer/fileformat/OvidImporter.java | 113 +- .../fileformat/PdfContentImporter.java | 36 +- .../importer/fileformat/RepecNepImporter.java | 25 +- .../importer/fileformat/RisImporter.java | 141 +- .../fileformat/SilverPlatterImporter.java | 55 +- .../logic/importer/util/GroupsParser.java | 8 +- .../logic/importer/util/IdentifierParser.java | 26 +- .../logic/importer/util/MetaDataParser.java | 9 +- .../integrity/ASCIICharacterChecker.java | 3 +- .../logic/integrity/BibStringChecker.java | 10 +- .../integrity/BibTeXEntryTypeChecker.java | 7 +- .../logic/integrity/BibtexKeyChecker.java | 11 +- .../BibtexKeyDuplicationChecker.java | 4 +- .../integrity/BibtexkeyDeviationChecker.java | 3 +- .../logic/integrity/EntryLinkChecker.java | 8 +- .../jabref/logic/integrity/FieldChecker.java | 5 +- .../jabref/logic/integrity/FieldCheckers.java | 65 +- .../logic/integrity/HTMLCharacterChecker.java | 8 +- .../logic/integrity/IntegrityCheck.java | 12 +- .../logic/integrity/IntegrityMessage.java | 19 +- .../JournalInAbbreviationListChecker.java | 8 +- .../logic/integrity/NoBibtexFieldChecker.java | 27 +- .../jabref/logic/integrity/TypeChecker.java | 9 +- .../org/jabref/logic/layout/LayoutEntry.java | 27 +- .../layout/format/CreateDocBook4Authors.java | 4 +- .../layout/format/CreateDocBook4Editors.java | 4 +- .../layout/format/CreateDocBook5Authors.java | 4 +- .../layout/format/CreateDocBook5Editors.java | 4 +- .../layout/format/EntryTypeFormatter.java | 9 +- .../jabref/logic/msbib/BibTeXConverter.java | 83 +- .../jabref/logic/msbib/MSBibConverter.java | 93 +- .../org/jabref/logic/msbib/MSBibEntry.java | 7 +- .../org/jabref/logic/msbib/MSBibMapping.java | 183 ++- .../org/jabref/logic/net/URLDownload.java | 2 +- .../jabref/logic/openoffice/OOBibStyle.java | 82 +- .../org/jabref/logic/openoffice/OOUtil.java | 4 +- .../openoffice/UndefinedBibtexEntry.java | 4 +- .../preferences/TimestampPreferences.java | 8 +- .../jabref/logic/shared/DBMSProcessor.java | 35 +- .../jabref/logic/shared/DBMSSynchronizer.java | 9 +- .../logic/shared/PostgreSQLProcessor.java | 2 +- .../specialfields/SpecialFieldsUtils.java | 16 +- .../texparser/TexBibEntriesResolver.java | 4 +- .../java/org/jabref/logic/util/TestEntry.java | 56 +- .../org/jabref/logic/util/UpdateField.java | 23 +- .../logic/util/UpdateFieldPreferences.java | 10 +- .../xmp/DocumentInformationExtractor.java | 24 +- .../jabref/logic/xmp/DublinCoreExtractor.java | 109 +- .../org/jabref/logic/xmp/XmpPreferences.java | 9 +- .../org/jabref/logic/xmp/XmpUtilWriter.java | 70 +- .../migrations/ConvertMarkingToGroups.java | 6 +- .../CustomEntryTypePreferenceMigration.java | 41 +- .../MergeReviewIntoCommentMigration.java | 30 +- .../migrations/PreferencesMigrations.java | 23 +- .../java/org/jabref/model/EntryTypes.java | 257 ---- .../java/org/jabref/model/FieldChange.java | 17 +- .../AbstractBibtexKeyPattern.java | 31 +- .../DatabaseBibtexKeyPattern.java | 6 +- .../GlobalBibtexKeyPattern.java | 4 +- .../model/cleanup/FieldFormatterCleanup.java | 29 +- .../model/cleanup/FieldFormatterCleanups.java | 9 +- .../jabref/model/database/BibDatabase.java | 17 +- .../model/database/BibDatabaseContext.java | 11 +- .../database/BibDatabaseModeDetection.java | 8 +- .../jabref/model/database/BibDatabases.java | 2 +- .../model/database/DuplicationChecker.java | 3 +- .../model/database/KeyChangeListener.java | 30 +- .../database/event/CoarseChangeFilter.java | 7 +- .../java/org/jabref/model/entry/BibEntry.java | 334 ++--- .../org/jabref/model/entry/BibEntryType.java | 144 ++ .../model/entry/BibEntryTypeBuilder.java | 81 + .../model/entry/BibEntryTypesManager.java | 161 ++ .../jabref/model/entry/BiblatexEntryType.java | 64 - .../model/entry/BiblatexEntryTypes.java | 1313 +++++------------ .../jabref/model/entry/BibtexEntryType.java | 64 - .../jabref/model/entry/BibtexEntryTypes.java | 263 +--- .../jabref/model/entry/BibtexSingleField.java | 135 -- .../model/entry/CanonicalBibtexEntry.java | 13 +- .../jabref/model/entry/CustomEntryType.java | 137 -- .../jabref/model/entry/EntryConverter.java | 23 +- .../org/jabref/model/entry/EntryType.java | 97 +- .../jabref/model/entry/EntryTypeFactory.java | 46 + .../org/jabref/model/entry/FieldName.java | 199 --- .../model/entry/IEEETranEntryTypes.java | 115 +- .../model/entry/InternalBibtexFields.java | 478 +----- .../jabref/model/entry/StandardEntryType.java | 65 + .../jabref/model/entry/UnknownEntryType.java | 48 + .../model/entry/event/FieldChangedEvent.java | 21 +- .../jabref/model/entry/field/BibField.java | 52 + .../org/jabref/model/entry/field/Field.java | 38 + .../model/entry/field/FieldFactory.java | 145 ++ .../model/entry/field/FieldPriority.java | 6 + .../entry/{ => field}/FieldProperty.java | 36 +- .../jabref/model/entry/field/IEEEField.java | 54 + .../model/entry/field/InternalField.java | 58 + .../jabref/model/entry/field/OrFields.java | 42 + .../SpecialField.java | 55 +- .../SpecialFieldValue.java | 8 +- .../model/entry/field/StandardField.java | 184 +++ .../model/entry/field/UnknownField.java | 53 + .../entry/identifier/ArXivIdentifier.java | 7 +- .../jabref/model/entry/identifier/DOI.java | 7 +- .../jabref/model/entry/identifier/Eprint.java | 7 +- .../jabref/model/entry/identifier/ISBN.java | 7 +- .../model/entry/identifier/Identifier.java | 4 +- .../model/entry/identifier/MathSciNetId.java | 7 +- .../model/groups/AutomaticKeywordGroup.java | 7 +- .../model/groups/AutomaticPersonsGroup.java | 7 +- .../jabref/model/groups/ExplicitGroup.java | 8 +- .../org/jabref/model/groups/KeywordGroup.java | 9 +- .../model/groups/RegexKeywordGroup.java | 3 +- .../jabref/model/groups/WordKeywordGroup.java | 19 +- .../model/metadata/ContentSelector.java | 20 +- .../model/metadata/ContentSelectors.java | 42 +- .../model/metadata/FilePreferences.java | 11 +- .../org/jabref/model/metadata/MetaData.java | 21 +- .../model/metadata/SaveOrderConfig.java | 13 +- .../search/rules/ContainBasedSearchRule.java | 3 +- .../search/rules/GrammarBasedSearchRule.java | 14 +- .../search/rules/RegexBasedSearchRule.java | 3 +- .../org/jabref/model/util/FileHelper.java | 7 +- .../org/jabref/model/util/OptionalUtil.java | 14 +- .../jabref/preferences/JabRefPreferences.java | 135 +- .../preferences/PreferencesService.java | 6 +- src/main/resources/l10n/JabRef_en.properties | 8 - .../gui/UpdateTimestampListenerTest.java | 11 +- .../DefaultAutoCompleterTest.java | 27 +- .../FieldValueSuggestionProviderTest.java | 27 +- .../PersonNameSuggestionProviderTest.java | 23 +- .../jabref/gui/entryeditor/SourceTabTest.java | 5 +- .../AutoSetFileLinksUtilTest.java | 4 +- .../IdentifierEditorViewModelTest.java | 3 +- .../gui/groups/GroupNodeViewModelTest.java | 63 +- .../gui/groups/GroupTreeViewModelTest.java | 9 +- .../org/jabref/logic/TypedBibEntryTest.java | 43 +- .../logic/bibtex/BibEntryWriterTest.java | 72 +- .../logic/bibtex/DuplicateCheckTest.java | 304 ++-- .../logic/bibtex/FieldContentParserTest.java | 12 +- .../bibtex/LatexFieldFormatterTests.java | 53 +- .../CrossRefEntryComparatorTest.java | 10 +- .../comparator/EntryComparatorTest.java | 3 +- .../comparator/FieldComparatorTest.java | 105 +- .../bibtex/comparator/MetaDataDiffTest.java | 5 +- .../BibtexKeyGeneratorTest.java | 82 +- .../MakeLabelWithDatabaseTest.java | 75 +- .../MakeLabelWithoutDatabaseTest.java | 13 +- .../CitationStyleGeneratorTest.java | 6 +- .../cleanup/BibtexBiblatexRoundtripTest.java | 54 +- .../logic/cleanup/CleanupWorkerTest.java | 137 +- .../cleanup/ConvertToBiblatexCleanupTest.java | 30 +- .../cleanup/ConvertToBibtexCleanupTest.java | 28 +- .../logic/cleanup/EprintCleanupTest.java | 15 +- .../cleanup/FieldFormatterCleanupTest.java | 74 +- .../jabref/logic/cleanup/ISSNCleanupTest.java | 13 +- .../logic/cleanup/MoveFilesCleanupTest.java | 17 +- .../logic/cleanup/RenamePdfCleanupTest.java | 23 +- .../exporter/BibtexDatabaseWriterTest.java | 119 +- .../logic/exporter/CsvExportFormatTest.java | 9 +- .../logic/exporter/DocBook5ExporterTest.java | 24 +- .../logic/exporter/DocbookExporterTest.java | 7 +- .../exporter/FieldFormatterCleanupsTest.java | 68 +- .../logic/exporter/GroupSerializerTest.java | 21 +- .../logic/exporter/HtmlExportFormatTest.java | 5 +- .../exporter/MSBibExportFormatTestFiles.java | 10 +- .../exporter/MetaDataSerializerTest.java | 10 +- .../exporter/ModsExportFormatTestFiles.java | 34 +- .../logic/exporter/XmpExporterTest.java | 37 +- .../logic/importer/OpenDatabaseTest.java | 7 +- .../fetcher/ACMPortalFetcherTest.java | 36 +- .../logic/importer/fetcher/ACSTest.java | 5 +- .../logic/importer/fetcher/ArXivTest.java | 78 +- .../fetcher/AstrophysicsDataSystemTest.java | 158 +- .../logic/importer/fetcher/CiteSeerTest.java | 23 +- .../logic/importer/fetcher/CrossRefTest.java | 65 +- .../importer/fetcher/DBLPFetcherTest.java | 25 +- .../importer/fetcher/DOAJFetcherTest.java | 37 +- .../logic/importer/fetcher/DiVATest.java | 24 +- .../importer/fetcher/DoiFetcherTest.java | 37 +- .../importer/fetcher/DoiResolutionTest.java | 7 +- .../importer/fetcher/GoogleScholarTest.java | 20 +- .../importer/fetcher/GvkFetcherTest.java | 50 +- .../logic/importer/fetcher/GvkParserTest.java | 20 +- .../logic/importer/fetcher/IEEETest.java | 80 +- .../importer/fetcher/INSPIREFetcherTest.java | 22 +- .../fetcher/IacrEprintFetcherTest.java | 90 +- .../importer/fetcher/IsbnFetcherTest.java | 26 +- .../fetcher/IsbnViaChimboriFetcherTest.java | 43 +- .../fetcher/IsbnViaEbookDeFetcherTest.java | 42 +- .../fetcher/LibraryOfCongressTest.java | 28 +- .../importer/fetcher/MathSciNetTest.java | 35 +- .../importer/fetcher/MedlineFetcherTest.java | 190 +-- .../importer/fetcher/MrDLibFetcherTest.java | 28 +- .../importer/fetcher/OpenAccessDoiTest.java | 5 +- .../importer/fetcher/RfcFetcherTest.java | 29 +- .../importer/fetcher/ScienceDirectTest.java | 7 +- .../importer/fetcher/SpringerFetcherTest.java | 43 +- .../importer/fetcher/SpringerLinkTest.java | 5 +- .../importer/fetcher/TitleFetcherTest.java | 19 +- .../logic/importer/fetcher/ZbMATHTest.java | 28 +- .../fileformat/BibTeXMLImporterTestTypes.java | 48 +- .../BiblioscapeImporterTestTypes.java | 42 +- .../fileformat/BibtexImporterTest.java | 55 +- .../importer/fileformat/BibtexParserTest.java | 393 ++--- .../fileformat/EndnoteImporterTest.java | 84 +- .../fileformat/FreeCiteImporterTest.java | 3 +- .../fileformat/InspecImporterTest.java | 32 +- .../importer/fileformat/IsiImporterTest.java | 186 +-- .../fileformat/MedlinePlainImporterTest.java | 47 +- .../fileformat/MrDLibImporterTest.java | 6 +- .../importer/fileformat/OvidImporterTest.java | 75 +- .../fileformat/PdfContentImporterTest.java | 10 +- .../fileformat/PdfXmpImporterTest.java | 9 +- .../logic/importer/util/GroupsParserTest.java | 11 +- .../logic/integrity/EntryLinkCheckerTest.java | 11 +- .../logic/integrity/IntegrityCheckTest.java | 353 +++-- .../integrity/NoBibTexFieldCheckerTest.java | 30 +- .../jabref/logic/layout/LayoutEntryTest.java | 46 +- .../org/jabref/logic/layout/LayoutTest.java | 27 +- .../logic/openoffice/OOBibStyleTest.java | 129 +- .../pdf/EntryAnnotationImporterTest.java | 8 +- .../logic/search/DatabaseSearcherTest.java | 28 +- .../jabref/logic/search/SearchQueryTest.java | 48 +- .../logic/shared/DBMSConnectionTest.java | 4 +- .../logic/shared/DBMSProcessorTest.java | 33 +- .../logic/shared/DBMSSynchronizerTest.java | 27 +- .../shared/SynchronizationTestSimulator.java | 24 +- .../specialfields/SpecialFieldsUtilsTest.java | 26 +- .../texparser/TexBibEntriesResolverTest.java | 63 +- .../jabref/logic/texparser/TexParserTest.java | 63 +- .../logic/util/BracketedPatternTest.java | 58 +- .../jabref/logic/util/UpdateFieldTest.java | 87 +- .../util/io/CiteKeyBasedFileFinderTest.java | 4 +- .../jabref/logic/util/io/FileUtilTest.java | 23 +- .../util/io/RegExpBasedFileFinderTests.java | 47 +- .../jabref/logic/xmp/XmpUtilWriterTest.java | 79 +- .../ConvertLegacyExplicitGroupsTest.java | 5 +- .../ConvertMarkingToGroupsTest.java | 6 +- ...eReviewIntoCommentActionMigrationTest.java | 22 +- .../jabref/model/BibDatabaseContextTest.java | 4 +- .../jabref/model/BibEntryTypeFactoryTest.java | 127 ++ .../java/org/jabref/model/EntryTypesTest.java | 177 --- .../database/BibDatabaseContextTest.java | 9 +- .../BibDatabaseModeDetectionTest.java | 39 +- .../model/database/BibDatabaseTest.java | 21 +- .../model/database/KeyChangeListenerTest.java | 31 +- .../model/entry/BibEntryEqualityTest.java | 12 +- .../org/jabref/model/entry/BibEntryTest.java | 28 +- .../org/jabref/model/entry/BibEntryTests.java | 150 +- .../model/entry/CanonicalBibEntryTest.java | 14 +- .../jabref/model/entry/EntryLinkListTest.java | 5 +- .../org/jabref/model/entry/FieldNameTest.java | 18 - .../model/entry/IEEETranEntryTypesTest.java | 19 - .../model/entry/field/BibFieldTest.java | 19 + .../model/entry/field/FieldFactoryTest.java | 17 + .../model/entry/field/SpecialFieldTest.java | 21 + .../model/entry/field/StandardFieldTest.java | 13 + .../model/entry/field/UnknownFieldTest.java | 17 + .../entry/specialfields/SpecialFieldTest.java | 33 - .../groups/AutomaticKeywordGroupTest.java | 9 +- .../model/groups/ExplicitGroupTest.java | 28 +- .../model/groups/GroupTreeNodeTest.java | 19 +- .../model/groups/WordKeywordGroupTest.java | 42 +- .../rules/ContainBasedSearchRuleTest.java | 13 +- .../ModsExportFormatTestAllFields.bib | 1 + .../ModsExportFormatTestAllFields.xml | 58 +- .../exporter/ModsExportFormatTestBook.bib | 1 + .../exporter/ModsExportFormatTestBook.xml | 4 +- .../ModsExportFormatTestMultipleEntries.bib | 1 + .../ModsExportFormatTestMultipleEntries.xml | 32 +- ...ModsExportFormatTestOnlyRequiredFields.bib | 1 + ...ModsExportFormatTestOnlyRequiredFields.xml | 2 +- .../ModsExportFormatTestTotalPages.bib | 1 + .../ModsExportFormatTestTotalPages.xml | 8 +- .../MedlineImporterTestArticleID.bib | 2 +- .../MedlineImporterTestBookArticleSet.bib | 2 +- .../MedlineImporterTestKeywordSingleEntry.bib | 2 +- .../fileformat/MedlineImporterTestNbib.bib | 4 +- .../MedlineImporterTestPubmedBook.bib | 2 +- .../bibWithUserCommentAndEntryChange.bib | 4 +- 495 files changed, 8629 insertions(+), 9599 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/customentrytypes/EntryTypeList.java delete mode 100644 src/main/java/org/jabref/gui/util/comparator/IconComparator.java delete mode 100644 src/main/java/org/jabref/model/EntryTypes.java create mode 100644 src/main/java/org/jabref/model/entry/BibEntryType.java create mode 100644 src/main/java/org/jabref/model/entry/BibEntryTypeBuilder.java create mode 100644 src/main/java/org/jabref/model/entry/BibEntryTypesManager.java delete mode 100644 src/main/java/org/jabref/model/entry/BiblatexEntryType.java delete mode 100644 src/main/java/org/jabref/model/entry/BibtexEntryType.java delete mode 100644 src/main/java/org/jabref/model/entry/BibtexSingleField.java delete mode 100644 src/main/java/org/jabref/model/entry/CustomEntryType.java create mode 100644 src/main/java/org/jabref/model/entry/EntryTypeFactory.java delete mode 100644 src/main/java/org/jabref/model/entry/FieldName.java create mode 100644 src/main/java/org/jabref/model/entry/StandardEntryType.java create mode 100644 src/main/java/org/jabref/model/entry/UnknownEntryType.java create mode 100644 src/main/java/org/jabref/model/entry/field/BibField.java create mode 100644 src/main/java/org/jabref/model/entry/field/Field.java create mode 100644 src/main/java/org/jabref/model/entry/field/FieldFactory.java create mode 100644 src/main/java/org/jabref/model/entry/field/FieldPriority.java rename src/main/java/org/jabref/model/entry/{ => field}/FieldProperty.java (76%) create mode 100644 src/main/java/org/jabref/model/entry/field/IEEEField.java create mode 100644 src/main/java/org/jabref/model/entry/field/InternalField.java create mode 100644 src/main/java/org/jabref/model/entry/field/OrFields.java rename src/main/java/org/jabref/model/entry/{specialfields => field}/SpecialField.java (61%) rename src/main/java/org/jabref/model/entry/{specialfields => field}/SpecialFieldValue.java (95%) create mode 100644 src/main/java/org/jabref/model/entry/field/StandardField.java create mode 100644 src/main/java/org/jabref/model/entry/field/UnknownField.java create mode 100644 src/test/java/org/jabref/model/BibEntryTypeFactoryTest.java delete mode 100644 src/test/java/org/jabref/model/EntryTypesTest.java delete mode 100644 src/test/java/org/jabref/model/entry/FieldNameTest.java delete mode 100644 src/test/java/org/jabref/model/entry/IEEETranEntryTypesTest.java create mode 100644 src/test/java/org/jabref/model/entry/field/BibFieldTest.java create mode 100644 src/test/java/org/jabref/model/entry/field/FieldFactoryTest.java create mode 100644 src/test/java/org/jabref/model/entry/field/SpecialFieldTest.java create mode 100644 src/test/java/org/jabref/model/entry/field/StandardFieldTest.java create mode 100644 src/test/java/org/jabref/model/entry/field/UnknownFieldTest.java delete mode 100644 src/test/java/org/jabref/model/entry/specialfields/SpecialFieldTest.java 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 @@