Class DefaultFormatterFactory

java.lang.Object
org.eclipse.nebula.widgets.formattedtext.DefaultFormatterFactory

public abstract class DefaultFormatterFactory
extends java.lang.Object
Factory for the default formatters.

This factory is called by FormattedText when a value is setted and no formatter has been provided by constructor or setFormatter(). The default formatter is based on the class of the value. The cache is searched first for the exact value's class. If no formatter is found, then it is searched for any class that is an ancestor of the value's class. The cache is a HashMap and the order of search cannot be garanteed. The first valid ancestor found is returned.

Default formatters provided by the factory are:

  • DateFormatter for Date values
  • NumberFormatter for Number values
Other formatters can be added with the register() method. Each formatter class must implement ITextFormatter and must have a default constructor.

This class is not intended to be instanciated.

  • Method Summary

    Modifier and Type Method Description
    static ITextFormatter createFormatter​(java.lang.Class<? extends java.lang.Object> c)
    Creates a new default formatter for the given class.
    static ITextFormatter createFormatter​(java.lang.Object value)
    Creates a new default formatter for the given value.
    static void register​(java.lang.Class<?> c, java.lang.Class<?> f)
    Registers a new formatter class for a given class of values.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • createFormatter

      public static ITextFormatter createFormatter​(java.lang.Object value)
      Creates a new default formatter for the given value. The formatter is based on the value's class.
      Parameters:
      value - Value for which to create a formatter
      Returns:
      New formatter corresponding to the value's class, or null if the class is unknown.
    • createFormatter

      public static ITextFormatter createFormatter​(java.lang.Class<? extends java.lang.Object> c)
      Creates a new default formatter for the given class.
      Parameters:
      c - Class for which to create a formatter
      Returns:
      New formatter corresponding to the class, or null if the class is unknown.
    • register

      public static void register​(java.lang.Class<?> c, java.lang.Class<?> f)
      Registers a new formatter class for a given class of values. The formatter class must implement the ITextFormatter interface.
      Parameters:
      c - Class of values
      f - Class of the formatter