From 5af1cdfce216dd503ff260067d0aa555069e99d6 Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Fri, 7 May 2021 23:23:27 +0800 Subject: [PATCH 01/14] fix: Random order of fields --- .../model/entry/field/FieldFactory.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) 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 b1c2f3b99b9..07adae13bd8 100644 --- a/src/main/java/org/jabref/model/entry/field/FieldFactory.java +++ b/src/main/java/org/jabref/model/entry/field/FieldFactory.java @@ -8,6 +8,7 @@ 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; @@ -29,8 +30,8 @@ public static String serializeOrFields(Field... fields) { public static String serializeOrFields(OrFields fields) { return fields.stream() - .map(Field::getName) - .collect(Collectors.joining(FIELD_OR_SEPARATOR)); + .map(Field::getName) + .collect(Collectors.joining(FIELD_OR_SEPARATOR)); } public static String serializeOrFieldsList(Set fields) { @@ -47,30 +48,30 @@ public static List getIdentifierFieldNames() { public static OrFields parseOrFields(String fieldNames) { Set fields = Arrays.stream(fieldNames.split(FieldFactory.FIELD_OR_SEPARATOR)) - .filter(StringUtil::isNotBlank) - .map(FieldFactory::parseField) - .collect(Collectors.toCollection(LinkedHashSet::new)); + .filter(StringUtil::isNotBlank) + .map(FieldFactory::parseField) + .collect(Collectors.toCollection(LinkedHashSet::new)); return new OrFields(fields); } public static Set parseOrFieldsList(String fieldNames) { return Arrays.stream(fieldNames.split(FieldFactory.DELIMITER)) - .filter(StringUtil::isNotBlank) - .map(FieldFactory::parseOrFields) - .collect(Collectors.toCollection(LinkedHashSet::new)); + .filter(StringUtil::isNotBlank) + .map(FieldFactory::parseOrFields) + .collect(Collectors.toCollection(LinkedHashSet::new)); } public static Set parseFieldList(String fieldNames) { return Arrays.stream(fieldNames.split(FieldFactory.DELIMITER)) - .filter(StringUtil::isNotBlank) - .map(FieldFactory::parseField) - .collect(Collectors.toCollection(LinkedHashSet::new)); + .filter(StringUtil::isNotBlank) + .map(FieldFactory::parseField) + .collect(Collectors.toCollection(LinkedHashSet::new)); } public static String serializeFieldsList(Collection fields) { return fields.stream() - .map(Field::getName) - .collect(Collectors.joining(DELIMITER)); + .map(Field::getName) + .collect(Collectors.joining(DELIMITER)); } public static Field parseField(String fieldName) { @@ -100,7 +101,12 @@ public static Set getJournalNameFields() { public static Set getCommonFields() { EnumSet allFields = EnumSet.allOf(StandardField.class); - LinkedHashSet publicAndInternalFields = new LinkedHashSet<>(allFields.size() + 3); + TreeSet publicAndInternalFields = new TreeSet<>((field1, field2) -> { + if (field1.getDisplayName().equals(field2.getDisplayName())) + return 0; + return field1.getDisplayName().compareTo(field2.getDisplayName()) > 0 ? 1 : -1; + } + ); publicAndInternalFields.add(InternalField.INTERNAL_ALL_FIELD); publicAndInternalFields.add(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD); publicAndInternalFields.add(InternalField.KEY_FIELD); @@ -132,8 +138,8 @@ public static Set getPersonNameFields() { private static Set getFieldsFiltered(Predicate selector) { return getAllFields().stream() - .filter(selector) - .collect(Collectors.toSet()); + .filter(selector) + .collect(Collectors.toSet()); } private static Set getAllFields() { @@ -147,7 +153,7 @@ private static Set getAllFields() { /** * These are the fields JabRef always displays as default {@link org.jabref.preferences.JabRefPreferences#setLanguageDependentDefaultValues()} - * + *

* A user can change them. The change is currently stored in the preferences only and not explicitly exposed as * separate preferences object */ From 039152d42009bd26cb9c21c39bbdfbc4872c6531 Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Fri, 7 May 2021 23:30:10 +0800 Subject: [PATCH 02/14] fix: Random order of fields --- src/main/java/org/jabref/model/entry/field/FieldFactory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 07adae13bd8..24f5b183362 100644 --- a/src/main/java/org/jabref/model/entry/field/FieldFactory.java +++ b/src/main/java/org/jabref/model/entry/field/FieldFactory.java @@ -6,9 +6,9 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.TreeSet; import java.util.List; import java.util.Set; -import java.util.TreeSet; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -153,7 +153,7 @@ private static Set getAllFields() { /** * These are the fields JabRef always displays as default {@link org.jabref.preferences.JabRefPreferences#setLanguageDependentDefaultValues()} - *

+ * * A user can change them. The change is currently stored in the preferences only and not explicitly exposed as * separate preferences object */ From 95d3b9c792bb5f0d69d971bba43905264804c775 Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Fri, 7 May 2021 23:32:18 +0800 Subject: [PATCH 03/14] fix: Random order of fields --- .../model/entry/field/FieldFactory.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) 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 24f5b183362..ca73ede18bc 100644 --- a/src/main/java/org/jabref/model/entry/field/FieldFactory.java +++ b/src/main/java/org/jabref/model/entry/field/FieldFactory.java @@ -30,8 +30,8 @@ public static String serializeOrFields(Field... fields) { public static String serializeOrFields(OrFields fields) { return fields.stream() - .map(Field::getName) - .collect(Collectors.joining(FIELD_OR_SEPARATOR)); + .map(Field::getName) + .collect(Collectors.joining(FIELD_OR_SEPARATOR)); } public static String serializeOrFieldsList(Set fields) { @@ -48,30 +48,30 @@ public static List getIdentifierFieldNames() { public static OrFields parseOrFields(String fieldNames) { Set fields = Arrays.stream(fieldNames.split(FieldFactory.FIELD_OR_SEPARATOR)) - .filter(StringUtil::isNotBlank) - .map(FieldFactory::parseField) - .collect(Collectors.toCollection(LinkedHashSet::new)); + .filter(StringUtil::isNotBlank) + .map(FieldFactory::parseField) + .collect(Collectors.toCollection(LinkedHashSet::new)); return new OrFields(fields); } public static Set parseOrFieldsList(String fieldNames) { return Arrays.stream(fieldNames.split(FieldFactory.DELIMITER)) - .filter(StringUtil::isNotBlank) - .map(FieldFactory::parseOrFields) - .collect(Collectors.toCollection(LinkedHashSet::new)); + .filter(StringUtil::isNotBlank) + .map(FieldFactory::parseOrFields) + .collect(Collectors.toCollection(LinkedHashSet::new)); } public static Set parseFieldList(String fieldNames) { return Arrays.stream(fieldNames.split(FieldFactory.DELIMITER)) - .filter(StringUtil::isNotBlank) - .map(FieldFactory::parseField) - .collect(Collectors.toCollection(LinkedHashSet::new)); + .filter(StringUtil::isNotBlank) + .map(FieldFactory::parseField) + .collect(Collectors.toCollection(LinkedHashSet::new)); } public static String serializeFieldsList(Collection fields) { return fields.stream() - .map(Field::getName) - .collect(Collectors.joining(DELIMITER)); + .map(Field::getName) + .collect(Collectors.joining(DELIMITER)); } public static Field parseField(String fieldName) { @@ -138,8 +138,8 @@ public static Set getPersonNameFields() { private static Set getFieldsFiltered(Predicate selector) { return getAllFields().stream() - .filter(selector) - .collect(Collectors.toSet()); + .filter(selector) + .collect(Collectors.toSet()); } private static Set getAllFields() { From 9f82e307d29674ef733bfc38362f2dd42e8667eb Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Fri, 7 May 2021 23:33:29 +0800 Subject: [PATCH 04/14] fix: Random order of fields --- .../model/entry/field/FieldFactory.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 ca73ede18bc..36d8eef4840 100644 --- a/src/main/java/org/jabref/model/entry/field/FieldFactory.java +++ b/src/main/java/org/jabref/model/entry/field/FieldFactory.java @@ -56,22 +56,22 @@ public static OrFields parseOrFields(String fieldNames) { public static Set parseOrFieldsList(String fieldNames) { return Arrays.stream(fieldNames.split(FieldFactory.DELIMITER)) - .filter(StringUtil::isNotBlank) - .map(FieldFactory::parseOrFields) - .collect(Collectors.toCollection(LinkedHashSet::new)); + .filter(StringUtil::isNotBlank) + .map(FieldFactory::parseOrFields) + .collect(Collectors.toCollection(LinkedHashSet::new)); } public static Set parseFieldList(String fieldNames) { return Arrays.stream(fieldNames.split(FieldFactory.DELIMITER)) - .filter(StringUtil::isNotBlank) - .map(FieldFactory::parseField) - .collect(Collectors.toCollection(LinkedHashSet::new)); + .filter(StringUtil::isNotBlank) + .map(FieldFactory::parseField) + .collect(Collectors.toCollection(LinkedHashSet::new)); } public static String serializeFieldsList(Collection fields) { return fields.stream() - .map(Field::getName) - .collect(Collectors.joining(DELIMITER)); + .map(Field::getName) + .collect(Collectors.joining(DELIMITER)); } public static Field parseField(String fieldName) { @@ -138,8 +138,8 @@ public static Set getPersonNameFields() { private static Set getFieldsFiltered(Predicate selector) { return getAllFields().stream() - .filter(selector) - .collect(Collectors.toSet()); + .filter(selector) + .collect(Collectors.toSet()); } private static Set getAllFields() { From 34880e67ca19e4f52ee7a1e49fc0a9b59adc0fad Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Fri, 7 May 2021 23:34:12 +0800 Subject: [PATCH 05/14] fix: Random order of fields --- .../org/jabref/model/entry/field/FieldFactory.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 36d8eef4840..85b36f1729b 100644 --- a/src/main/java/org/jabref/model/entry/field/FieldFactory.java +++ b/src/main/java/org/jabref/model/entry/field/FieldFactory.java @@ -30,8 +30,8 @@ public static String serializeOrFields(Field... fields) { public static String serializeOrFields(OrFields fields) { return fields.stream() - .map(Field::getName) - .collect(Collectors.joining(FIELD_OR_SEPARATOR)); + .map(Field::getName) + .collect(Collectors.joining(FIELD_OR_SEPARATOR)); } public static String serializeOrFieldsList(Set fields) { @@ -48,9 +48,9 @@ public static List getIdentifierFieldNames() { public static OrFields parseOrFields(String fieldNames) { Set fields = Arrays.stream(fieldNames.split(FieldFactory.FIELD_OR_SEPARATOR)) - .filter(StringUtil::isNotBlank) - .map(FieldFactory::parseField) - .collect(Collectors.toCollection(LinkedHashSet::new)); + .filter(StringUtil::isNotBlank) + .map(FieldFactory::parseField) + .collect(Collectors.toCollection(LinkedHashSet::new)); return new OrFields(fields); } From 33da5f22db2ec4e54fff5ed486ea3d0644c90c76 Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Fri, 7 May 2021 23:42:55 +0800 Subject: [PATCH 06/14] fix: change CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15ff79e8072..5fdd8d41770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -550,7 +550,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where the XMP Importer would incorrectly return an empty default entry when importing pdfs [#6577](https://github.com/JabRef/jabref/issues/6577) - We fixed an issue where opening the menu 'Library properties' marked the library as modified [#6451](https://github.com/JabRef/jabref/issues/6451) - We fixed an issue when importing resulted in an exception [#7343](https://github.com/JabRef/jabref/issues/7343) - +- We fixed an issue Some fields are in random order [#7710](https://github.com/JabRef/jabref/issues/7710) ### Removed - The feature to "mark entries" was removed and merged with the groups functionality. For migration, a group is created for every value of the `__markedentry` field and the entry is added to this group. From 743d00732b2e941e7f3b0a3ce05db3781967312f Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Sat, 8 May 2021 01:24:14 +0800 Subject: [PATCH 07/14] modify code in ViewModel. --- .../FieldFormatterCleanupsPanelViewModel.java | 6 ++++++ .../java/org/jabref/model/entry/field/FieldFactory.java | 8 +------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java b/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java index b5169b5b69d..57fe9dc33d5 100644 --- a/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java +++ b/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java @@ -28,6 +28,12 @@ public class FieldFormatterCleanupsPanelViewModel { private final ObjectProperty selectedFormatterProperty = new SimpleObjectProperty<>(); public FieldFormatterCleanupsPanelViewModel() { + availableFieldsProperty.sort((field1, field2) -> { + if (field1.getDisplayName().equals(field2.getDisplayName())) { + return 0; + } + return field1.getDisplayName().compareTo(field2.getDisplayName()) > 0 ? 1 : -1; + }); } public void resetToRecommended() { 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 85b36f1729b..b1c2f3b99b9 100644 --- a/src/main/java/org/jabref/model/entry/field/FieldFactory.java +++ b/src/main/java/org/jabref/model/entry/field/FieldFactory.java @@ -6,7 +6,6 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.LinkedHashSet; -import java.util.TreeSet; import java.util.List; import java.util.Set; import java.util.function.Predicate; @@ -101,12 +100,7 @@ public static Set getJournalNameFields() { public static Set getCommonFields() { EnumSet allFields = EnumSet.allOf(StandardField.class); - TreeSet publicAndInternalFields = new TreeSet<>((field1, field2) -> { - if (field1.getDisplayName().equals(field2.getDisplayName())) - return 0; - return field1.getDisplayName().compareTo(field2.getDisplayName()) > 0 ? 1 : -1; - } - ); + LinkedHashSet publicAndInternalFields = new LinkedHashSet<>(allFields.size() + 3); publicAndInternalFields.add(InternalField.INTERNAL_ALL_FIELD); publicAndInternalFields.add(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD); publicAndInternalFields.add(InternalField.KEY_FIELD); From a7ffb9b612bb21bc0f6705a2a1649a5b05be128a Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Sat, 8 May 2021 01:39:47 +0800 Subject: [PATCH 08/14] Add a blank line for passing checkstyle. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fdd8d41770..e9db4fbdf0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -551,6 +551,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where opening the menu 'Library properties' marked the library as modified [#6451](https://github.com/JabRef/jabref/issues/6451) - We fixed an issue when importing resulted in an exception [#7343](https://github.com/JabRef/jabref/issues/7343) - We fixed an issue Some fields are in random order [#7710](https://github.com/JabRef/jabref/issues/7710) + ### Removed - The feature to "mark entries" was removed and merged with the groups functionality. For migration, a group is created for every value of the `__markedentry` field and the entry is added to this group. From b6adbc487409a7df56578285e3ed72f58c74eeca Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Sat, 8 May 2021 02:25:41 +0800 Subject: [PATCH 09/14] Make code logic simpler. --- CHANGELOG.md | 2 +- .../FieldFormatterCleanupsPanelViewModel.java | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9db4fbdf0d..8606dfa7ed8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -550,7 +550,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where the XMP Importer would incorrectly return an empty default entry when importing pdfs [#6577](https://github.com/JabRef/jabref/issues/6577) - We fixed an issue where opening the menu 'Library properties' marked the library as modified [#6451](https://github.com/JabRef/jabref/issues/6451) - We fixed an issue when importing resulted in an exception [#7343](https://github.com/JabRef/jabref/issues/7343) -- We fixed an issue Some fields are in random order [#7710](https://github.com/JabRef/jabref/issues/7710) +- We fixed an issue where the field in the Field formatter dropdown selection were sorted in random order. [#7710](https://github.com/JabRef/jabref/issues/7710) ### Removed diff --git a/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java b/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java index 57fe9dc33d5..fba3c190b43 100644 --- a/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java +++ b/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java @@ -17,6 +17,8 @@ import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; +import java.util.Comparator; + public class FieldFormatterCleanupsPanelViewModel { private final BooleanProperty cleanupsDisableProperty = new SimpleBooleanProperty(); @@ -28,12 +30,7 @@ public class FieldFormatterCleanupsPanelViewModel { private final ObjectProperty selectedFormatterProperty = new SimpleObjectProperty<>(); public FieldFormatterCleanupsPanelViewModel() { - availableFieldsProperty.sort((field1, field2) -> { - if (field1.getDisplayName().equals(field2.getDisplayName())) { - return 0; - } - return field1.getDisplayName().compareTo(field2.getDisplayName()) > 0 ? 1 : -1; - }); + availableFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); } public void resetToRecommended() { From 5e98e242a2054c9189be5d397ee01931bde8bc56 Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Sat, 8 May 2021 03:44:54 +0800 Subject: [PATCH 10/14] fix the order for import. --- .../FieldFormatterCleanupsPanelViewModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java b/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java index fba3c190b43..27f1a27caaa 100644 --- a/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java +++ b/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java @@ -1,5 +1,7 @@ package org.jabref.gui.commonfxcontrols; +import java.util.Comparator; + import javafx.beans.property.BooleanProperty; import javafx.beans.property.ListProperty; import javafx.beans.property.ObjectProperty; @@ -17,8 +19,6 @@ import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; -import java.util.Comparator; - public class FieldFormatterCleanupsPanelViewModel { private final BooleanProperty cleanupsDisableProperty = new SimpleBooleanProperty(); From 06943479afebcbc6cbcbcf3886c3d117806bc9f0 Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Sat, 8 May 2021 04:32:20 +0800 Subject: [PATCH 11/14] fix: use sortedList --- .../FieldFormatterCleanupsPanelViewModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java b/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java index 27f1a27caaa..64da5ba887d 100644 --- a/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java +++ b/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java @@ -9,6 +9,7 @@ import javafx.beans.property.SimpleListProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; +import javafx.collections.transformation.SortedList; import javafx.scene.control.SelectionModel; import org.jabref.gui.Globals; @@ -24,13 +25,12 @@ public class FieldFormatterCleanupsPanelViewModel { private final BooleanProperty cleanupsDisableProperty = new SimpleBooleanProperty(); private final ListProperty cleanupsListProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); private final ObjectProperty> selectedCleanupProperty = new SimpleObjectProperty<>(new NoSelectionModel<>()); - private final ListProperty availableFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList(FieldFactory.getCommonFields())); + private final ListProperty availableFieldsProperty = new SimpleListProperty<>(new SortedList<>(FXCollections.observableArrayList(FieldFactory.getCommonFields()), Comparator.comparing(Field::getDisplayName))); private final ObjectProperty selectedFieldProperty = new SimpleObjectProperty<>(); private final ListProperty availableFormattersProperty = new SimpleListProperty<>(FXCollections.observableArrayList(Cleanups.getBuiltInFormatters())); private final ObjectProperty selectedFormatterProperty = new SimpleObjectProperty<>(); public FieldFormatterCleanupsPanelViewModel() { - availableFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); } public void resetToRecommended() { From 07b5984c3e0e3d6d325366d33f92150a58b1f7ea Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Sat, 8 May 2021 21:49:51 +0800 Subject: [PATCH 12/14] sort some fields, formatters, ids and languages list --- src/main/java/org/jabref/gui/EntryTypeViewModel.java | 2 ++ .../FieldFormatterCleanupsPanelViewModel.java | 2 +- .../libraryproperties/LibraryPropertiesDialogViewModel.java | 5 +++++ .../org/jabref/gui/preferences/file/FileTabViewModel.java | 5 +++++ .../jabref/gui/preferences/general/GeneralTabViewModel.java | 5 ++++- .../jabref/gui/preferences/xmp/XmpPrivacyTabViewModel.java | 2 ++ 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index d8221b328e6..1e64e049cca 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -1,5 +1,6 @@ package org.jabref.gui; +import java.util.Comparator; import java.util.Optional; import javafx.beans.property.BooleanProperty; @@ -60,6 +61,7 @@ public EntryTypeViewModel(PreferencesService preferences, this.dialogService = dialogService; this.stateManager = stateManager; fetchers.addAll(WebFetchers.getIdBasedFetchers(preferences.getImportFormatPreferences())); + fetchers.sort(Comparator.comparing(IdBasedFetcher::getName)); selectedItemProperty.setValue(getLastSelectedFetcher()); idFieldValidator = new FunctionBasedValidator<>(idText, StringUtil::isNotBlank, ValidationMessage.error(Localization.lang("Required field \"%0\" is empty.", Localization.lang("ID")))); } diff --git a/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java b/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java index 64da5ba887d..21cea0eed10 100644 --- a/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java +++ b/src/main/java/org/jabref/gui/commonfxcontrols/FieldFormatterCleanupsPanelViewModel.java @@ -27,7 +27,7 @@ public class FieldFormatterCleanupsPanelViewModel { private final ObjectProperty> selectedCleanupProperty = new SimpleObjectProperty<>(new NoSelectionModel<>()); private final ListProperty availableFieldsProperty = new SimpleListProperty<>(new SortedList<>(FXCollections.observableArrayList(FieldFactory.getCommonFields()), Comparator.comparing(Field::getDisplayName))); private final ObjectProperty selectedFieldProperty = new SimpleObjectProperty<>(); - private final ListProperty availableFormattersProperty = new SimpleListProperty<>(FXCollections.observableArrayList(Cleanups.getBuiltInFormatters())); + private final ListProperty availableFormattersProperty = new SimpleListProperty<>(new SortedList<>(FXCollections.observableArrayList(Cleanups.getBuiltInFormatters()), Comparator.comparing(Formatter::getName))); private final ObjectProperty selectedFormatterProperty = new SimpleObjectProperty<>(); public FieldFormatterCleanupsPanelViewModel() { diff --git a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java index a05c2ef2c7c..769327edcdb 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java @@ -2,6 +2,7 @@ import java.nio.charset.Charset; import java.nio.file.Path; +import java.util.Comparator; import java.util.Optional; import java.util.Set; @@ -113,6 +114,10 @@ void setValues() { secondarySortFieldsProperty.addAll(fieldNames); tertiarySortFieldsProperty.addAll(fieldNames); + primarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); + secondarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); + tertiarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); + savePrimarySortSelectedValueProperty.setValue(initialSaveOrderConfig.getSortCriteria().get(0).field); saveSecondarySortSelectedValueProperty.setValue(initialSaveOrderConfig.getSortCriteria().get(1).field); saveTertiarySortSelectedValueProperty.setValue(initialSaveOrderConfig.getSortCriteria().get(2).field); diff --git a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java index c5de0f7fd63..b9be650db1f 100644 --- a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java @@ -1,5 +1,6 @@ package org.jabref.gui.preferences.file; +import java.util.Comparator; import java.util.Set; import javafx.beans.property.BooleanProperty; @@ -84,6 +85,10 @@ public void setValues() { secondarySortFieldsProperty.addAll(fieldNames); tertiarySortFieldsProperty.addAll(fieldNames); + primarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); + secondarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); + tertiarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); + savePrimarySortSelectedValueProperty.setValue(initialExportOrder.getSortCriteria().get(0).field); saveSecondarySortSelectedValueProperty.setValue(initialExportOrder.getSortCriteria().get(1).field); saveTertiarySortSelectedValueProperty.setValue(initialExportOrder.getSortCriteria().get(2).field); diff --git a/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java b/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java index af4488e85ef..252bbb147f4 100644 --- a/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java @@ -2,6 +2,7 @@ import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import javafx.beans.property.BooleanProperty; @@ -14,8 +15,10 @@ import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; +import javafx.collections.transformation.SortedList; import org.jabref.gui.DialogService; import org.jabref.gui.preferences.PreferenceTabViewModel; +import org.jabref.logic.cleanup.Formatter; import org.jabref.logic.l10n.Encodings; import org.jabref.logic.l10n.Language; import org.jabref.logic.l10n.Localization; @@ -66,7 +69,7 @@ public GeneralTabViewModel(DialogService dialogService, PreferencesService prefe } public void setValues() { - languagesListProperty.setValue(FXCollections.observableArrayList(Language.values())); + languagesListProperty.setValue(new SortedList<>(FXCollections.observableArrayList(Language.values()), Comparator.comparing(Language::getDisplayName))); selectedLanguageProperty.setValue(preferencesService.getLanguage()); encodingsListProperty.setValue(FXCollections.observableArrayList(Encodings.getCharsets())); diff --git a/src/main/java/org/jabref/gui/preferences/xmp/XmpPrivacyTabViewModel.java b/src/main/java/org/jabref/gui/preferences/xmp/XmpPrivacyTabViewModel.java index ba72edd4dcf..459545f6387 100644 --- a/src/main/java/org/jabref/gui/preferences/xmp/XmpPrivacyTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/xmp/XmpPrivacyTabViewModel.java @@ -1,5 +1,6 @@ package org.jabref.gui.preferences.xmp; +import java.util.Comparator; import java.util.HashSet; import javafx.beans.property.BooleanProperty; @@ -59,6 +60,7 @@ public void setValues() { availableFieldsProperty.clear(); availableFieldsProperty.addAll(FieldFactory.getCommonFields()); + availableFieldsProperty.sort((Comparator.comparing(Field::getDisplayName))); } @Override From 95ae925b1028a7c2b9502450dc620ce833d57dbb Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Sat, 8 May 2021 22:02:32 +0800 Subject: [PATCH 13/14] modify check style --- .../jabref/gui/preferences/general/GeneralTabViewModel.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java b/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java index 252bbb147f4..0bb78896bc9 100644 --- a/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java @@ -14,11 +14,10 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; - import javafx.collections.transformation.SortedList; + import org.jabref.gui.DialogService; import org.jabref.gui.preferences.PreferenceTabViewModel; -import org.jabref.logic.cleanup.Formatter; import org.jabref.logic.l10n.Encodings; import org.jabref.logic.l10n.Language; import org.jabref.logic.l10n.Localization; From 124b791925f709d12257ab04f12c59b70667bae2 Mon Sep 17 00:00:00 2001 From: dateri <263765432@qq.com> Date: Sat, 8 May 2021 23:08:31 +0800 Subject: [PATCH 14/14] revert id sorting and make code effectively --- src/main/java/org/jabref/gui/EntryTypeViewModel.java | 2 -- .../LibraryPropertiesDialogViewModel.java | 10 ++++------ .../jabref/gui/preferences/file/FileTabViewModel.java | 10 ++++------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index 1e64e049cca..d8221b328e6 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -1,6 +1,5 @@ package org.jabref.gui; -import java.util.Comparator; import java.util.Optional; import javafx.beans.property.BooleanProperty; @@ -61,7 +60,6 @@ public EntryTypeViewModel(PreferencesService preferences, this.dialogService = dialogService; this.stateManager = stateManager; fetchers.addAll(WebFetchers.getIdBasedFetchers(preferences.getImportFormatPreferences())); - fetchers.sort(Comparator.comparing(IdBasedFetcher::getName)); selectedItemProperty.setValue(getLastSelectedFetcher()); idFieldValidator = new FunctionBasedValidator<>(idText, StringUtil::isNotBlank, ValidationMessage.error(Localization.lang("Required field \"%0\" is empty.", Localization.lang("ID")))); } diff --git a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java index 769327edcdb..b70e582d80c 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java @@ -2,9 +2,10 @@ import java.nio.charset.Charset; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Comparator; +import java.util.List; import java.util.Optional; -import java.util.Set; import javafx.beans.property.BooleanProperty; import javafx.beans.property.ListProperty; @@ -107,17 +108,14 @@ void setValues() { saveInTableOrderProperty.setValue(true); } - Set fieldNames = FieldFactory.getCommonFields(); + List fieldNames = new ArrayList<>(FieldFactory.getCommonFields()); // allow entrytype field as sort criterion fieldNames.add(InternalField.TYPE_HEADER); + fieldNames.sort(Comparator.comparing(Field::getDisplayName)); primarySortFieldsProperty.addAll(fieldNames); secondarySortFieldsProperty.addAll(fieldNames); tertiarySortFieldsProperty.addAll(fieldNames); - primarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); - secondarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); - tertiarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); - savePrimarySortSelectedValueProperty.setValue(initialSaveOrderConfig.getSortCriteria().get(0).field); saveSecondarySortSelectedValueProperty.setValue(initialSaveOrderConfig.getSortCriteria().get(1).field); saveTertiarySortSelectedValueProperty.setValue(initialSaveOrderConfig.getSortCriteria().get(2).field); diff --git a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java index b9be650db1f..c4807ca05ec 100644 --- a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java @@ -1,7 +1,8 @@ package org.jabref.gui.preferences.file; +import java.util.ArrayList; import java.util.Comparator; -import java.util.Set; +import java.util.List; import javafx.beans.property.BooleanProperty; import javafx.beans.property.ListProperty; @@ -80,15 +81,12 @@ public void setValues() { saveInTableOrderProperty.setValue(true); } - Set fieldNames = FieldFactory.getCommonFields(); + List fieldNames = new ArrayList<>(FieldFactory.getCommonFields()); + fieldNames.sort(Comparator.comparing(Field::getDisplayName)); primarySortFieldsProperty.addAll(fieldNames); secondarySortFieldsProperty.addAll(fieldNames); tertiarySortFieldsProperty.addAll(fieldNames); - primarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); - secondarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); - tertiarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName)); - savePrimarySortSelectedValueProperty.setValue(initialExportOrder.getSortCriteria().get(0).field); saveSecondarySortSelectedValueProperty.setValue(initialExportOrder.getSortCriteria().get(1).field); saveTertiarySortSelectedValueProperty.setValue(initialExportOrder.getSortCriteria().get(2).field);