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, IDatePM, ITextPM, IValuePM, PresentationModel, Supportable, Validatable

public class DatePM
extends TextPM
implements IDatePM

The DatePM is a presentation model for Date objects. The text format is locale dependent but can be changed manually by calling setFormat(DateFormat).

Author:
Max Gensthaler, Michael Karneim

Nested Class Summary
protected  class DatePM.DefaultValidationRule
           
 
Nested classes/interfaces inherited from class org.beanfabrics.model.TextPM
TextPM.DefaultOptionsValidationRule, TextPM.TextComparable
 
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
 
Constructor Summary
DatePM()
          Constructs a new instance with the default format (just showing the date, not the time).
 
Method Summary
protected  java.text.DateFormat createDefaultFormat()
          This returns a localized DateFormat for converting a Date to a String and vice versa.
 java.lang.Comparable getComparable()
           
 java.util.Date getDate()
          Return the date represented by this object.
static java.text.DateFormat getDateFormat(java.util.Locale locale)
           
 java.text.DateFormat getFormat()
          Return the format to be used by this object to check the input and convert the input to a Date and vice versa.
 void setDate(java.util.Date date)
          Set the Date to be represented by this object.
 void setDefaultDate(java.util.Date date)
           
 void setFormat(java.text.DateFormat newFormat)
          Set the format to be used by this object to check the input and convert the input to a Date and vice versa.
 
Methods inherited from class org.beanfabrics.model.TextPM
getDefaultText, getOptions, getText, getText, isEmpty, isModified, isRestrictedToOptions, preset, reformat, reset, setDefaultText, setOptions, setRestrictedToOptions, setText, toString
 
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
createPropertiesValidationRule, 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, 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 new instance with the default format (just showing the date, not the time).

Method Detail

getFormat

public java.text.DateFormat getFormat()
Return the format to be used by this object to check the input and convert the input to a Date and vice versa.

Specified by:
getFormat in interface IDatePM

setFormat

public void setFormat(java.text.DateFormat newFormat)
Set the format to be used by this object to check the input and convert the input to a Date and vice versa.

I.e. to set a format showing date and time do:

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

Specified by:
setFormat in interface IDatePM
Parameters:
newFormat - format to use for Date-String conversion

createDefaultFormat

protected java.text.DateFormat createDefaultFormat()
This returns a localized DateFormat for converting a Date to a String and vice versa.


getDate

public java.util.Date getDate()
                       throws ConversionException
Return the date represented by this object.

Specified by:
getDate in interface IDatePM
Throws:
ConversionException - thrown if the text of this object cannot be parsed as date by the given format

setDate

public void setDate(java.util.Date date)
Set the Date to be represented by this object.

Specified by:
setDate in interface IDatePM
Parameters:
date - Date to set

setDefaultDate

public void setDefaultDate(java.util.Date date)

getComparable

public java.lang.Comparable getComparable()
Specified by:
getComparable in interface IValuePM
Overrides:
getComparable in class TextPM

getDateFormat

public static java.text.DateFormat getDateFormat(java.util.Locale locale)


© 2010 by Michael Karneim, http://www.beanfabrics.org