Creating a formatter

To create a new formatter, subclass from the abstract class com.ibm.dse.gui.Converter and implement the following methods:

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:

  1. Create a FormatterPanel subclass.
  2. In the Visual Composition Editor, specify as panel constraints WIDTH=216 and HEIGHT=173.
  3. Implement a getJavaInitializationString() method. It should return a String that builds an instance of the formatter associated with the panel, and the panel fields will contain the appropriate values.
  4. Implement a getValue() method. It should return an instance of the formatter associated with the panel, with the appropriate values in the panel fields. Use the getErrorMessage() and getConvertible() methods (if appropriate) to obtain the error message and whether the value is convertible.
  5. Implement a withErrorMessage() method. It should return a boolean that indicates whether the errorMessage entry field in the formatter editor must be enabled.
  6. 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, as follows:
  7. Implement a getFormatterName() method. It should return a String that is the name of the formatter associated with the panel.
  8. Implement a setValue(Object) method. It should update the values in the formatter editor panel according to the values in the formatter instance that is passed as an argument. Note that the values for errorMessage and isConvertible will be managed by the ConverterEditor.

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.