Skip to content

Commit a76b8f3

Browse files
authored
Merge pull request #5224 from davidemdot/fix-5220
Fix exception when adding field formatter in 'Cleanup entries' dialog
2 parents 4656533 + a0af540 commit a76b8f3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.util.Objects;
55
import java.util.Optional;
66
import java.util.Set;
7+
import java.util.TreeSet;
8+
import java.util.stream.Collectors;
79

810
import javafx.beans.value.ChangeListener;
911
import javafx.beans.value.ObservableValue;
@@ -40,18 +42,17 @@ public class FieldFormatterCleanupsPanel extends GridPane {
4042

4143
private static final String DESCRIPTION = Localization.lang("Description") + ": ";
4244
private final CheckBox cleanupEnabled;
45+
private final FieldFormatterCleanups defaultFormatters;
46+
private final List<Formatter> availableFormatters;
4347
private FieldFormatterCleanups fieldFormatterCleanups;
4448
private ListView<FieldFormatterCleanup> actionsList;
4549
private ComboBox<Formatter> formattersCombobox;
46-
private ComboBox<Field> selectFieldCombobox;
50+
private ComboBox<String> selectFieldCombobox;
4751
private Button addButton;
4852
private Label descriptionAreaText;
4953
private Button removeButton;
5054
private Button resetButton;
5155
private Button recommendButton;
52-
53-
private final FieldFormatterCleanups defaultFormatters;
54-
private final List<Formatter> availableFormatters;
5556
private ObservableList<FieldFormatterCleanup> actions;
5657

5758
public FieldFormatterCleanupsPanel(String description, FieldFormatterCleanups defaultFormatters) {
@@ -104,7 +105,7 @@ private void buildLayout() {
104105
actionsList = new ListView<>(actions);
105106
actionsList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
106107
new ViewModelListCellFactory<FieldFormatterCleanup>()
107-
.withText(action -> action.getField() + ": " + action.getFormatter().getName())
108+
.withText(action -> action.getField().getDisplayName() + ": " + action.getFormatter().getName())
108109
.withStringTooltip(action -> action.getFormatter().getDescription())
109110
.install(actionsList);
110111
add(actionsList, 1, 1, 3, 1);
@@ -164,7 +165,8 @@ private GridPane getSelectorPanel() {
164165
GridPane builder = new GridPane();
165166
Set<Field> fields = FieldFactory.getCommonFields();
166167
fields.add(InternalField.KEY_FIELD);
167-
selectFieldCombobox = new ComboBox<>(FXCollections.observableArrayList(fields));
168+
Set<String> fieldsString = fields.stream().map(Field::getDisplayName).sorted().collect(Collectors.toCollection(TreeSet::new));
169+
selectFieldCombobox = new ComboBox<>(FXCollections.observableArrayList(fieldsString));
168170
selectFieldCombobox.setEditable(true);
169171
builder.add(selectFieldCombobox, 1, 1);
170172

@@ -217,7 +219,7 @@ public boolean isDefaultSaveActions() {
217219

218220
private FieldFormatterCleanup getFieldFormatterCleanup() {
219221
Formatter selectedFormatter = formattersCombobox.getValue();
220-
Field field = selectFieldCombobox.getValue();
222+
Field field = FieldFactory.parseField(selectFieldCombobox.getSelectionModel().getSelectedItem());
221223
return new FieldFormatterCleanup(field, selectedFormatter);
222224
}
223225

@@ -242,5 +244,4 @@ public void changed(ObservableValue<? extends T> observable, T oldValue, T newVa
242244
setStatus(cleanupEnabled.isSelected());
243245
}
244246
}
245-
246247
}

0 commit comments

Comments
 (0)