Although free text may be appropriate for some types of preferences, for others, choosing from a set of values may be more appropriate. ComboFieldEditor
can be used to present the user with a selection, which can be used to represent the user's favourite TimeZone
. The combo dropdown is built from an array of pairs of strings. The first string is the displayed label in the dropdown, while the second value is the string identifier that will be persisted to (and loaded from) the preferences store. Perform the following steps:
In the
createFieldEditors()
method of theClockPreferencePage class
, add the following code to populate aComboFieldEditor
with the list ofTimeZone
IDs:protected void createFieldEditors() {String[][] data;String[] ids = TimeZone.getAvailableIDs(); Arrays.sort(ids); data = new String[ids.length][]; for (int i = 0; i < ids.length; i++) { data[i] = new String[] { ids[i], ids[i] }; } addField(new ComboFieldEditor("favourite...