From ae4e0e44102336bef76610d06a242be422d99e9b Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 16 Jun 2023 21:47:17 +0200 Subject: [PATCH 1/2] Show more fields for save sort order and export sort order Fixes https://github.com/JabRef/jabref/issues/10010 --- CHANGELOG.md | 1 + .../saving/SavingPropertiesViewModel.java | 9 ++------ .../export/ExportTabViewModel.java | 6 +---- .../model/entry/field/FieldFactory.java | 22 ++++++++++++++++++- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64f35b7daa8..84c71fc3902 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - The formatter `remove_unicode_ligatures` is now called `replace_unicode_ligatures`. [#9890](https://github.com/JabRef/jabref/pull/9890) - We improved the error message when no terminal was found [#9607](https://github.com/JabRef/jabref/issues/9607) - In the context of the "systematic literature functionality", we changed the name "database" to "catalog" to use a separate term for online catalogs in comparison to SQL databases. [#9951](https://github.com/JabRef/jabref/pull/9951) +- We now show more fields (including Special Fields) in the dropdown selection for "Save sort order" in the library properties and for "Export sort order" in the preferences. [#10010](https://github.com/JabRef/jabref/issues/10010) ### Fixed diff --git a/src/main/java/org/jabref/gui/libraryproperties/saving/SavingPropertiesViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/saving/SavingPropertiesViewModel.java index 3216e60e2ed..3d5d6ff73f1 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/saving/SavingPropertiesViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/saving/SavingPropertiesViewModel.java @@ -1,8 +1,6 @@ package org.jabref.gui.libraryproperties.saving; import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; import java.util.Optional; import javafx.beans.property.BooleanProperty; @@ -18,7 +16,6 @@ import org.jabref.model.database.BibDatabaseContext; 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.jabref.model.metadata.SaveOrder; import org.jabref.preferences.CleanupPreferences; @@ -65,11 +62,9 @@ public void setValues() { case TABLE -> saveInTableOrderProperty.setValue(true); } - List fieldNames = new ArrayList<>(FieldFactory.getCommonFields()); - fieldNames.add(InternalField.TYPE_HEADER); // allow entrytype field as sort criterion - fieldNames.sort(Comparator.comparing(Field::getDisplayName)); + sortableFieldsProperty.clear(); - sortableFieldsProperty.addAll(fieldNames); + sortableFieldsProperty.addAll(FieldFactory.getAllFieldsSortedWithoutInternalExceptSome()); sortCriteriaProperty.clear(); sortCriteriaProperty.addAll(exportSaveOrder.getSortCriteria().stream() .map(SortCriterionViewModel::new) diff --git a/src/main/java/org/jabref/gui/preferences/export/ExportTabViewModel.java b/src/main/java/org/jabref/gui/preferences/export/ExportTabViewModel.java index 8b2ef12e7ef..0546284f10e 100644 --- a/src/main/java/org/jabref/gui/preferences/export/ExportTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/export/ExportTabViewModel.java @@ -1,8 +1,6 @@ package org.jabref.gui.preferences.export; import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; import javafx.beans.property.BooleanProperty; import javafx.beans.property.ListProperty; @@ -44,9 +42,7 @@ public void setValues() { .map(SortCriterionViewModel::new) .toList()); - List fieldNames = new ArrayList<>(FieldFactory.getCommonFields()); - fieldNames.sort(Comparator.comparing(Field::getDisplayName)); - sortableFieldsProperty.addAll(fieldNames); + sortableFieldsProperty.addAll(FieldFactory.getAllFieldsSortedWithoutInternalExceptSome()); } @Override diff --git a/src/main/java/org/jabref/model/entry/field/FieldFactory.java b/src/main/java/org/jabref/model/entry/field/FieldFactory.java index 0316114b2aa..05f3aeb1eb5 100644 --- a/src/main/java/org/jabref/model/entry/field/FieldFactory.java +++ b/src/main/java/org/jabref/model/entry/field/FieldFactory.java @@ -3,11 +3,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Comparator; import java.util.EnumSet; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import java.util.TreeSet; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -133,7 +135,7 @@ public static Set getJournalNameFields() { } /** - * Returns a List with all standard fields and including some common internal fields + * Returns a Set with all standard fields and including some common internal fields */ public static Set getCommonFields() { EnumSet allFields = EnumSet.allOf(StandardField.class); @@ -147,6 +149,24 @@ public static Set getCommonFields() { return publicAndInternalFields; } + /** + * Returns a sorted Set of Fields (by {@link Field#getDisplayName} with all fields without internal ones, except {@link InternalField#TYPE_HEADER} and {@link InternalField#KEY_FIELD} as they are useful for sorting + */ + public static Set getAllFieldsSortedWithoutInternalExceptSome() { + Set fields = new TreeSet<>(Comparator.comparing(Field::getDisplayName)); + + fields.addAll(EnumSet.allOf(StandardField.class)); + fields.addAll(EnumSet.allOf(SpecialField.class)); + fields.addAll(EnumSet.allOf(IEEEField.class)); + fields.addAll(EnumSet.allOf(BiblatexApaField.class)); + fields.addAll(EnumSet.allOf(BiblatexSoftwareField.class)); + fields.removeIf(field -> field instanceof UserSpecificCommentField); + fields.add(InternalField.KEY_FIELD); + fields.add(InternalField.TYPE_HEADER); + + return fields; + } + /** * Returns a List with all standard fields and the citation key field */ From 733396e41744c1c113a8b19e7955880941950079 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 16 Jun 2023 21:58:37 +0200 Subject: [PATCH 2/2] simplify --- .../saving/SavingPropertiesViewModel.java | 12 ++++++++++-- .../CustomEntryTypesTabViewModel.java | 4 +++- .../preferences/export/ExportTabViewModel.java | 9 ++++++++- .../jabref/model/entry/field/FieldFactory.java | 15 ++++----------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/jabref/gui/libraryproperties/saving/SavingPropertiesViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/saving/SavingPropertiesViewModel.java index 3d5d6ff73f1..15955183f52 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/saving/SavingPropertiesViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/saving/SavingPropertiesViewModel.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Optional; +import java.util.Set; import javafx.beans.property.BooleanProperty; import javafx.beans.property.ListProperty; @@ -16,6 +17,7 @@ import org.jabref.model.database.BibDatabaseContext; 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.jabref.model.metadata.SaveOrder; import org.jabref.preferences.CleanupPreferences; @@ -62,9 +64,15 @@ public void setValues() { case TABLE -> saveInTableOrderProperty.setValue(true); } - sortableFieldsProperty.clear(); - sortableFieldsProperty.addAll(FieldFactory.getAllFieldsSortedWithoutInternalExceptSome()); + + Set fields = FieldFactory.getAllFieldsWithOutInternal(); + fields.add(InternalField.INTERNAL_ALL_FIELD); + fields.add(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD); + fields.add(InternalField.KEY_FIELD); + fields.add(InternalField.TYPE_HEADER); + + sortableFieldsProperty.addAll(FieldFactory.getStandardFieldsWithCitationKey()); sortCriteriaProperty.clear(); sortCriteriaProperty.addAll(exportSaveOrder.getSortCriteria().stream() .map(SortCriterionViewModel::new) diff --git a/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTabViewModel.java index 3e63facf759..08cd62c0ec4 100644 --- a/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTabViewModel.java @@ -76,10 +76,11 @@ public CustomEntryTypesTabViewModel(BibDatabaseMode mode, ValidationMessage.error(Localization.lang("Entry type cannot be empty. Please enter a name."))); fieldValidator = new FunctionBasedValidator<>( newFieldToAdd, - input -> input != null && StringUtil.isNotBlank(input.getDisplayName()), + input -> (input != null) && StringUtil.isNotBlank(input.getDisplayName()), ValidationMessage.error(Localization.lang("Field cannot be empty. Please enter a name."))); } + @Override public void setValues() { if (!this.entryTypesWithFields.isEmpty()) { this.entryTypesWithFields.clear(); @@ -97,6 +98,7 @@ public void setValues() { } } + @Override public void storeSettings() { Set multilineFields = new HashSet<>(); for (EntryTypeViewModel typeViewModel : entryTypesWithFields) { diff --git a/src/main/java/org/jabref/gui/preferences/export/ExportTabViewModel.java b/src/main/java/org/jabref/gui/preferences/export/ExportTabViewModel.java index 0546284f10e..f8b278b9708 100644 --- a/src/main/java/org/jabref/gui/preferences/export/ExportTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/export/ExportTabViewModel.java @@ -1,6 +1,7 @@ package org.jabref.gui.preferences.export; import java.util.ArrayList; +import java.util.Set; import javafx.beans.property.BooleanProperty; import javafx.beans.property.ListProperty; @@ -12,6 +13,7 @@ import org.jabref.gui.preferences.PreferenceTabViewModel; 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.SaveOrder; import org.jabref.preferences.ExportPreferences; @@ -42,7 +44,12 @@ public void setValues() { .map(SortCriterionViewModel::new) .toList()); - sortableFieldsProperty.addAll(FieldFactory.getAllFieldsSortedWithoutInternalExceptSome()); + Set fields = FieldFactory.getAllFieldsWithOutInternal(); + fields.add(InternalField.INTERNAL_ALL_FIELD); + fields.add(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD); + fields.add(InternalField.KEY_FIELD); + fields.add(InternalField.TYPE_HEADER); + sortableFieldsProperty.addAll(FieldFactory.getStandardFieldsWithCitationKey()); } @Override diff --git a/src/main/java/org/jabref/model/entry/field/FieldFactory.java b/src/main/java/org/jabref/model/entry/field/FieldFactory.java index 05f3aeb1eb5..cac6bb3b2c7 100644 --- a/src/main/java/org/jabref/model/entry/field/FieldFactory.java +++ b/src/main/java/org/jabref/model/entry/field/FieldFactory.java @@ -150,19 +150,12 @@ public static Set getCommonFields() { } /** - * Returns a sorted Set of Fields (by {@link Field#getDisplayName} with all fields without internal ones, except {@link InternalField#TYPE_HEADER} and {@link InternalField#KEY_FIELD} as they are useful for sorting + * Returns a sorted Set of Fields (by {@link Field#getDisplayName} with all fields without internal ones */ - public static Set getAllFieldsSortedWithoutInternalExceptSome() { + public static Set getAllFieldsWithOutInternal() { Set fields = new TreeSet<>(Comparator.comparing(Field::getDisplayName)); - - fields.addAll(EnumSet.allOf(StandardField.class)); - fields.addAll(EnumSet.allOf(SpecialField.class)); - fields.addAll(EnumSet.allOf(IEEEField.class)); - fields.addAll(EnumSet.allOf(BiblatexApaField.class)); - fields.addAll(EnumSet.allOf(BiblatexSoftwareField.class)); - fields.removeIf(field -> field instanceof UserSpecificCommentField); - fields.add(InternalField.KEY_FIELD); - fields.add(InternalField.TYPE_HEADER); + fields.addAll(getAllFields()); + fields.removeAll(EnumSet.allOf(InternalField.class)); return fields; }