Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make more fields, fomatters, ids and languages sorted by alphabetical order #7717

Merged
merged 17 commits into from
May 10, 2021
Merged
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/EntryTypeViewModel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui;

import java.util.Comparator;
import java.util.Optional;

import javafx.beans.property.BooleanProperty;
Expand Down Expand Up @@ -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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in a comment I don't think it's useful to sort by alphatical order here. DOI fetcher should always be on top because it's the most important one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So please revert that

selectedItemProperty.setValue(getLastSelectedFetcher());
idFieldValidator = new FunctionBasedValidator<>(idText, StringUtil::isNotBlank, ValidationMessage.error(Localization.lang("Required field \"%0\" is empty.", Localization.lang("ID"))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FieldFormatterCleanupsPanelViewModel {
private final ObjectProperty<SelectionModel<FieldFormatterCleanup>> selectedCleanupProperty = new SimpleObjectProperty<>(new NoSelectionModel<>());
private final ListProperty<Field> availableFieldsProperty = new SimpleListProperty<>(new SortedList<>(FXCollections.observableArrayList(FieldFactory.getCommonFields()), Comparator.comparing(Field::getDisplayName)));
private final ObjectProperty<Field> selectedFieldProperty = new SimpleObjectProperty<>();
private final ListProperty<Formatter> availableFormattersProperty = new SimpleListProperty<>(FXCollections.observableArrayList(Cleanups.getBuiltInFormatters()));
private final ListProperty<Formatter> availableFormattersProperty = new SimpleListProperty<>(new SortedList<>(FXCollections.observableArrayList(Cleanups.getBuiltInFormatters()), Comparator.comparing(Formatter::getName)));
private final ObjectProperty<Formatter> selectedFormatterProperty = new SimpleObjectProperty<>();

public FieldFormatterCleanupsPanelViewModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.preferences.file;

import java.util.Comparator;
import java.util.Set;

import javafx.beans.property.BooleanProperty;
Expand Down Expand Up @@ -84,6 +85,10 @@ public void setValues() {
secondarySortFieldsProperty.addAll(fieldNames);
tertiarySortFieldsProperty.addAll(fieldNames);

primarySortFieldsProperty.sort(Comparator.comparing(Field::getDisplayName));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple solution but not effective. You are essentially doing the same sort 3 times.
I would create: List<Field> fieldNames = new ArrayList<>(FieldFactory.getCommonFields())
Then sort it and add it to the properties

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,6 +14,7 @@
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;
Expand Down Expand Up @@ -66,7 +68,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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.preferences.xmp;

import java.util.Comparator;
import java.util.HashSet;

import javafx.beans.property.BooleanProperty;
Expand Down Expand Up @@ -59,6 +60,7 @@ public void setValues() {

availableFieldsProperty.clear();
availableFieldsProperty.addAll(FieldFactory.getCommonFields());
availableFieldsProperty.sort((Comparator.comparing(Field::getDisplayName)));
}

@Override
Expand Down