In free-form text fields, it's sometimes possible to enter a value that isn't valid. For example, when asking for an e-mail address, it might be necessary to validate it against some kind of regular expression such as .+@.+
to provide a simple check.
To test the default validation, run the target Eclipse instance and go to the Clock preference page. Type some text in the numeric field. A warning message, Value must be an integer, will be displayed:
To add validation, create a new field called
offset
that allows values between-14
and+12
(by default,IntegerFieldEditor
validates against the0..MAX_INT
range). Add the following to thecreateFieldEditors
method:IntegerFieldEditor offset = new IntegerFieldEditor("offset","Current offset from GMT", getFieldEditorParent());offset.setValidRange(-14, +12);addField(offset);
Run the target Eclipse instance, go to the Clock preference page, and type in an invalid value: