4
4
import java .util .Objects ;
5
5
import java .util .Optional ;
6
6
import java .util .Set ;
7
+ import java .util .TreeSet ;
8
+ import java .util .stream .Collectors ;
7
9
8
10
import javafx .beans .value .ChangeListener ;
9
11
import javafx .beans .value .ObservableValue ;
@@ -40,18 +42,17 @@ public class FieldFormatterCleanupsPanel extends GridPane {
40
42
41
43
private static final String DESCRIPTION = Localization .lang ("Description" ) + ": " ;
42
44
private final CheckBox cleanupEnabled ;
45
+ private final FieldFormatterCleanups defaultFormatters ;
46
+ private final List <Formatter > availableFormatters ;
43
47
private FieldFormatterCleanups fieldFormatterCleanups ;
44
48
private ListView <FieldFormatterCleanup > actionsList ;
45
49
private ComboBox <Formatter > formattersCombobox ;
46
- private ComboBox <Field > selectFieldCombobox ;
50
+ private ComboBox <String > selectFieldCombobox ;
47
51
private Button addButton ;
48
52
private Label descriptionAreaText ;
49
53
private Button removeButton ;
50
54
private Button resetButton ;
51
55
private Button recommendButton ;
52
-
53
- private final FieldFormatterCleanups defaultFormatters ;
54
- private final List <Formatter > availableFormatters ;
55
56
private ObservableList <FieldFormatterCleanup > actions ;
56
57
57
58
public FieldFormatterCleanupsPanel (String description , FieldFormatterCleanups defaultFormatters ) {
@@ -104,7 +105,7 @@ private void buildLayout() {
104
105
actionsList = new ListView <>(actions );
105
106
actionsList .getSelectionModel ().setSelectionMode (SelectionMode .SINGLE );
106
107
new ViewModelListCellFactory <FieldFormatterCleanup >()
107
- .withText (action -> action .getField () + ": " + action .getFormatter ().getName ())
108
+ .withText (action -> action .getField (). getDisplayName () + ": " + action .getFormatter ().getName ())
108
109
.withStringTooltip (action -> action .getFormatter ().getDescription ())
109
110
.install (actionsList );
110
111
add (actionsList , 1 , 1 , 3 , 1 );
@@ -164,7 +165,8 @@ private GridPane getSelectorPanel() {
164
165
GridPane builder = new GridPane ();
165
166
Set <Field > fields = FieldFactory .getCommonFields ();
166
167
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 ));
168
170
selectFieldCombobox .setEditable (true );
169
171
builder .add (selectFieldCombobox , 1 , 1 );
170
172
@@ -217,7 +219,7 @@ public boolean isDefaultSaveActions() {
217
219
218
220
private FieldFormatterCleanup getFieldFormatterCleanup () {
219
221
Formatter selectedFormatter = formattersCombobox .getValue ();
220
- Field field = selectFieldCombobox .getValue ( );
222
+ Field field = FieldFactory . parseField ( selectFieldCombobox .getSelectionModel (). getSelectedItem () );
221
223
return new FieldFormatterCleanup (field , selectedFormatter );
222
224
}
223
225
@@ -242,5 +244,4 @@ public void changed(ObservableValue<? extends T> observable, T oldValue, T newVa
242
244
setStatus (cleanupEnabled .isSelected ());
243
245
}
244
246
}
245
-
246
247
}
0 commit comments