To create a new formatter, subclass from the abstract class com.ibm.dse.gui.Converter
and implement the following methods:
- boolean validate (String input): Gets as input the data entered by the
user, and is responsible for validating this input and returning a boolean
indicating whether the data is valid.
- String validateWithError(String userInput): Gets data entered by the user,
and is responsible for validating this input. If the string is valid, this
method will return null. If the string is not valid, an error message is returned
and may be displayed in an error bean.
- boolean validateKey(String UserInput, java.awt.event.KeyEvent keyEvent):
Checks if the keystroke value contained in the key event is valid, given the
user input text string. The user input text string may store the previous
keystrokes, and this method may then validate if the next keystroke is a valid
value. Returns true if the keystroke is valid.
- Object formatAsConversionType (String input): Gets as input the data entered
by the user, and is responsible for changing the format of this data from
a string to an instance of the appropriate class (for example, in DateFormatter,
the text is formatted as an instance of Date).
- String formatFromConversionType (Object input): Gets as input the data
entered by the user, and is responsible for changing the format of this data
from an instance of the appropriate class to a string (for example, in DateFormatter,
the date is formatted as a String).
The formatter is used in a property editor, and consequently must
be serializable. Therefore, you must specify a value for the "private static
final long serialVersionUID" attribute, which will be the same in all the
class versions.
A new formatter requires a panel to allow the user to
specify parameters. If no parameters are necessary, create a simple panel
with no values. To create the panel, complete the following steps:
Add the class name of the new formatter class as well as the associated
panel in the formatters.properties file. After the toolkit development environment
is set up, and com.ibm.dse.guibeans.zip installed, this file is located in
the bin\dsegb.jar file under the com.ibm.dse.guibeans plug-in installation
directory. This properties file is necessary during development and contains
the list of user-defined formatter classes. Classes specified in this file
are displayed by the formatter editor in the formatter choices list. The formatter
editor is used in the formatter property of SpTextField, SpLabel, and SpTable.
Once
a new formatter is created, it is integrated into the list of available formatters,
and can be selected by the user to format and validate data. The toolkit formatters
implementation provides some reference examples.