Jump to: navigation, search

Difference between revisions of "JFace Data Binding/Converter"

m (Converter moved to JFace Data Binding/Converter: Moving all JFace Data Binding pages to be children of the main page.)
(No difference)

Revision as of 19:21, 5 September 2007

In JFace Data Binding converters are used to convert from one value type to another.

JFace Data Binding
How to Contribute

Converters, implementations of org.eclipse.core.databinding.conversion.IConverter, are a basic yet core part of the binding pipeline. They allow for the conversion between data types. This conversion can be as basic as converting from a primitive (e.g. boolean.class) to a boxed type (e.g. Boolean.class) or as complex as converting a String to an int.

Implementation Design Principles

  1. It's best for the converter to be immutable. This will allow for greater reuse of the instance especially across threads.
  2. Synchronize during convert(...) if necessary. A good example of this is using com.ibm.icu.text.NumberFormat in a converter. NumberFormat expects to be externally synchronized as the state of NumberFormat changes during formatting and parsing. In order to be used across threads access to the internal NumberFormat must be synchronized.
  3. If the converter is converting to a primitive from an object ensure null is handled.