org.beanfabrics.model
Class DatePM

java.lang.Object
  extended by org.beanfabrics.AbstractBean
      extended by org.beanfabrics.ValidatableBean
          extended by org.beanfabrics.model.AbstractPM
              extended by org.beanfabrics.model.AbstractValuePM
                  extended by org.beanfabrics.model.TextPM
                      extended by org.beanfabrics.model.DatePM
All Implemented Interfaces:
Bean, ContextOwner, HasComparable, IDatePM, ITextPM, IValuePM, PresentationModel, Supportable, Validatable

public class DatePM
extends TextPM
implements IDatePM

The DatePM is a PresentationModel that contains a Date value.

The date format used for formatting and pasring can be set by calling setFormat(DateFormat). The default text format is Locale dependent.


Nested Class Summary
static class DatePM.DateFormatProvider
          The DatePM.DateFormatProvider is a factory for the default DateFormat used by newly created DatePM instances.
 class DatePM.DateValidationRule
          This rule evaluates to invalid if the PM's value can't be converted into a Date.
 
Nested classes/interfaces inherited from class org.beanfabrics.model.TextPM
TextPM.DefaultOptionsValidationRule, TextPM.TextComparable
 
Nested classes/interfaces inherited from class org.beanfabrics.model.AbstractValuePM
AbstractValuePM.MandatoryValidationRule
 
Nested classes/interfaces inherited from class org.beanfabrics.model.AbstractPM
AbstractPM.PropertiesValidationRule
 
Field Summary
protected static java.lang.String KEY_MESSAGE_INVALID_DATE
           
 
Fields inherited from class org.beanfabrics.model.TextPM
KEY_MESSAGE_VALUE_NOT_AN_OPTION
 
Fields inherited from class org.beanfabrics.model.AbstractValuePM
KEY_MESSAGE_MANDATORY
 
Fields inherited from class org.beanfabrics.model.AbstractPM
KEY_MESSAGE_ONE_OR_MORE_INVALID
 
Constructor Summary
DatePM()
          Constructs a DatePM using the default format.
 
Method Summary
 java.lang.Comparable<?> getComparable()
          Returns the comparable substitute.
 java.util.Date getDate()
          Returns the value of this PM as a Date.
static DatePM.DateFormatProvider getDefaultDateFormatProvider()
          Returns the DatePM.DateFormatProvider that is used to create the default DateFormat used by newly created DatePM instances.
protected  java.text.DateFormat getDefaultFormat()
          Returns a DateFormat for formatting a Date to a String and converting a String to a Date.
 java.text.DateFormat getFormat()
          Returns the date format used for parsing and converting between the text and date value.
 void setDate(java.util.Date date)
          Sets the value of this PM to the given Date.
 void setDefaultDate(java.util.Date date)
          Sets the default value of this PM to the given Date value.
static void setDefaultDateFormatProvider(DatePM.DateFormatProvider provider)
          Sets the DatePM.DateFormatProvider that is used to create the default DateFormat used by newly created DatePM instances.
 void setFormat(java.text.DateFormat newFormat)
          Sets the date format used for parsing and converting between the text and date value.
 
Methods inherited from class org.beanfabrics.model.TextPM
getDefaultText, getOptions, getText, getText, isEmpty, isModified, isRestrictedToOptions, preset, reformat, reset, setDefaultText, setOptions, setRestrictedToOptions, setText
 
Methods inherited from class org.beanfabrics.model.AbstractValuePM
getDescription, getTitle, isEditable, isMandatory, revalidate, setDescription, setEditable, setMandatory, setTitle
 
Methods inherited from class org.beanfabrics.model.AbstractPM
getContext, getSupportMap, revalidateProperties
 
Methods inherited from class org.beanfabrics.ValidatableBean
getValidationState, getValidator, isValid, setValidationState
 
Methods inherited from class org.beanfabrics.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, equals, getPropertyChangeSupport, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.beanfabrics.model.ITextPM
getOptions, getText, isModified, preset, reformat, reset, setOptions, setText
 
Methods inherited from interface org.beanfabrics.model.IValuePM
getDescription, getTitle, isEditable, isEmpty, isMandatory, setDescription, setEditable, setMandatory, setTitle
 
Methods inherited from interface org.beanfabrics.Bean
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeSupport, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from interface org.beanfabrics.validation.Validatable
getValidationState, getValidator, isValid, revalidate
 
Methods inherited from interface org.beanfabrics.support.Supportable
getSupportMap
 
Methods inherited from interface org.beanfabrics.context.ContextOwner
getContext
 

Field Detail

KEY_MESSAGE_INVALID_DATE

protected static final java.lang.String KEY_MESSAGE_INVALID_DATE
See Also:
Constant Field Values
Constructor Detail

DatePM

public DatePM()
Constructs a DatePM using the default format.

See Also:
getDefaultFormat()
Method Detail

getDefaultDateFormatProvider

public static DatePM.DateFormatProvider getDefaultDateFormatProvider()
Returns the DatePM.DateFormatProvider that is used to create the default DateFormat used by newly created DatePM instances.

Returns:
the DatePM.DateFormatProvider

setDefaultDateFormatProvider

public static void setDefaultDateFormatProvider(DatePM.DateFormatProvider provider)
Sets the DatePM.DateFormatProvider that is used to create the default DateFormat used by newly created DatePM instances.

Parameters:
provider -

getDefaultFormat

protected java.text.DateFormat getDefaultFormat()
Returns a DateFormat for formatting a Date to a String and converting a String to a Date.

Returns:
a localized DateFormat for formatting and parsing this PM's value

getFormat

public java.text.DateFormat getFormat()
Returns the date format used for parsing and converting between the text and date value. This format is used for validation also.

Specified by:
getFormat in interface IDatePM
Returns:
the date format used for parsing and converting

setFormat

public void setFormat(java.text.DateFormat newFormat)
Sets the date format used for parsing and converting between the text and date value. This format is used for validation also.

For example, to set a format with date and time component do:

 DateFormat format = DateFormat.getDateTimeInstance();
 format.setLenient(false);
 pm.setFormat(format);
 

Implementors must try to reformat the content to match the new format.

Specified by:
setFormat in interface IDatePM
Parameters:
newFormat - the new format

getDate

public java.util.Date getDate()
                       throws ConversionException
Returns the value of this PM as a Date.

Specified by:
getDate in interface IDatePM
Returns:
the value of this PM as a Date
Throws:
ConversionException - if the text value of this PM cannot be converted to a Date using the defined format

setDate

public void setDate(java.util.Date date)
Sets the value of this PM to the given Date.

Specified by:
setDate in interface IDatePM
Parameters:
date - the date value

setDefaultDate

public void setDefaultDate(java.util.Date date)
Sets the default value of this PM to the given Date value.

Parameters:
date - the default value

getComparable

public java.lang.Comparable<?> getComparable()
Returns the comparable substitute. This substitute can be used for comparison of this object with another.

Override this method to control how instances of this class are sorted by a Sorter.

The default implementation returns a TextPM.TextComparable or one of its subclasses.

Specified by:
getComparable in interface HasComparable
Overrides:
getComparable in class TextPM
Returns:
the comparable substitute