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 exception when adding field formatter in 'Cleanup entries' dialog #5224

Merged
merged 1 commit into from
Aug 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Formatter> availableFormatters;
private FieldFormatterCleanups fieldFormatterCleanups;
private ListView<FieldFormatterCleanup> actionsList;
private ComboBox<Formatter> formattersCombobox;
private ComboBox<Field> selectFieldCombobox;
private ComboBox<String> selectFieldCombobox;
private Button addButton;
private Label descriptionAreaText;
private Button removeButton;
private Button resetButton;
private Button recommendButton;

private final FieldFormatterCleanups defaultFormatters;
private final List<Formatter> availableFormatters;
private ObservableList<FieldFormatterCleanup> actions;

public FieldFormatterCleanupsPanel(String description, FieldFormatterCleanups defaultFormatters) {
Expand Down Expand Up @@ -104,7 +105,7 @@ private void buildLayout() {
actionsList = new ListView<>(actions);
actionsList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
new ViewModelListCellFactory<FieldFormatterCleanup>()
.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);
Expand Down Expand Up @@ -164,7 +165,8 @@ private GridPane getSelectorPanel() {
GridPane builder = new GridPane();
Set<Field> fields = FieldFactory.getCommonFields();
fields.add(InternalField.KEY_FIELD);
selectFieldCombobox = new ComboBox<>(FXCollections.observableArrayList(fields));
Set<String> 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);

Expand Down Expand Up @@ -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);
}

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

}