From a0af540d7d0c6bbe8d855da157febce18a019642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20M=C3=A9ndez?= Date: Sun, 25 Aug 2019 01:32:42 +0200 Subject: [PATCH] Fix exception when adding field formatter in 'Cleanup entries' dialog --- .../cleanup/FieldFormatterCleanupsPanel.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java b/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java index 12cd47ccf92..23917990ebe 100644 --- a/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java +++ b/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java @@ -4,6 +4,8 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; @@ -40,18 +42,17 @@ public class FieldFormatterCleanupsPanel extends GridPane { private static final String DESCRIPTION = Localization.lang("Description") + ": "; private final CheckBox cleanupEnabled; + private final FieldFormatterCleanups defaultFormatters; + private final List availableFormatters; private FieldFormatterCleanups fieldFormatterCleanups; private ListView actionsList; private ComboBox formattersCombobox; - private ComboBox selectFieldCombobox; + private ComboBox selectFieldCombobox; private Button addButton; private Label descriptionAreaText; private Button removeButton; private Button resetButton; private Button recommendButton; - - private final FieldFormatterCleanups defaultFormatters; - private final List availableFormatters; private ObservableList actions; public FieldFormatterCleanupsPanel(String description, FieldFormatterCleanups defaultFormatters) { @@ -104,7 +105,7 @@ private void buildLayout() { actionsList = new ListView<>(actions); actionsList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); new ViewModelListCellFactory() - .withText(action -> action.getField() + ": " + action.getFormatter().getName()) + .withText(action -> action.getField().getDisplayName() + ": " + action.getFormatter().getName()) .withStringTooltip(action -> action.getFormatter().getDescription()) .install(actionsList); add(actionsList, 1, 1, 3, 1); @@ -164,7 +165,8 @@ private GridPane getSelectorPanel() { GridPane builder = new GridPane(); Set fields = FieldFactory.getCommonFields(); fields.add(InternalField.KEY_FIELD); - selectFieldCombobox = new ComboBox<>(FXCollections.observableArrayList(fields)); + Set fieldsString = fields.stream().map(Field::getDisplayName).sorted().collect(Collectors.toCollection(TreeSet::new)); + selectFieldCombobox = new ComboBox<>(FXCollections.observableArrayList(fieldsString)); selectFieldCombobox.setEditable(true); builder.add(selectFieldCombobox, 1, 1); @@ -217,7 +219,7 @@ public boolean isDefaultSaveActions() { private FieldFormatterCleanup getFieldFormatterCleanup() { Formatter selectedFormatter = formattersCombobox.getValue(); - Field field = selectFieldCombobox.getValue(); + Field field = FieldFactory.parseField(selectFieldCombobox.getSelectionModel().getSelectedItem()); return new FieldFormatterCleanup(field, selectedFormatter); } @@ -242,5 +244,4 @@ public void changed(ObservableValue observable, T oldValue, T newVa setStatus(cleanupEnabled.isSelected()); } } - }