Although free text may be appropriate for some types of preference, choosing from a set of values may be more appropriate for other types. A ComboFieldEditor
instance can be used to present the user with a selection of time zones, from which the user can set their favorite ZoneId
. The combo drop-down is built from an array of pairs of strings; the first string in each pair is the display label, while the second value in each pair is the string identifier that will be persisted in the preferences store.
In the
ClockPreferencePage
methodcreateFieldEditors
, add the following code to populate aComboFieldEditor
with the list ofZoneId
elements:protected void createFieldEditors() {// ... String[][] data = ZoneId.getAvailableZoneIds() // .stream().sorted().map(s -> new String[] { s, s }) // .collect(Collectors.toList()).toArray(new String[][] {});addField(new ComboFieldEditor("favorite","Favorite time zone", data, getFieldEditorParent()));}
Run the...