de.mguennewig.pobjform
Class AbstractPObjForm

java.lang.Object
  extended by de.mguennewig.pobjform.AbstractPObjForm
All Implemented Interfaces:
PObjForm
Direct Known Subclasses:
PObjHtmlForm, PObjSwingForm

public abstract class AbstractPObjForm
extends java.lang.Object
implements PObjForm

Abstract base class for rendering forms based on meta-data from the PObject library.

Author:
Michael Günnewig
See Also:
FormDecl, Messages

Field Summary
static java.lang.String ERROR_INVALID_VALUE
          Message key that specifies that the value is invalid.
static java.lang.String ERROR_MANDATORY
          Message key that specifies that the value is mandatory.
 
Constructor Summary
AbstractPObjForm(Container container)
          Creates a new PObject-enhanced form.
 
Method Summary
 void addErrorMessage(java.lang.String messageId, java.lang.Object... params)
          Adds a success message to the set of global messages.
 void addInvalidValueMessage(java.lang.String property, java.lang.Object... params)
          Adds an error message for the specified property that the value invalid.
 void addMandatoryMessage(java.lang.String property)
          Adds an error message for the specified property that the value is mandatory.
 void addMessage(java.lang.String property, Message msg)
          Add a message to the set of messages for the specified property.
 void addSuccessMessage(java.lang.String messageId, java.lang.Object... params)
          Adds a success message to the set of global messages.
 void clearMessage(java.lang.String property, java.lang.String msgKey)
          Removes a specific message for the given property.
 void clearMessages()
          Clear all messages recorded by this object.
 void dumpMessages(java.io.PrintStream ps, java.util.ResourceBundle bundle)
           
static java.lang.Integer[] extractIndexes(java.lang.String property)
           
 Container getContainer()
          Returns the database connection which the form uses.
static java.lang.String getElementLabelKey(FormElement element)
          Returns the message resource key for the given element.
 java.util.List<FormElement> getElements()
          
 int getMessageCount()
          Return the number of messages recorded for all properties (including global messages).
 int getMessageCount(java.lang.String property)
          Return the number of messages associated with the specified property.
 java.util.Iterator<java.lang.String> getMessageProperties()
          Return the set of property names for which at least one message has been recorded.
 Messages getMessages()
          
 java.util.Iterator<Message> getMessages(java.lang.String property)
          Return the set of messages related to a specific property.
 boolean hasChanged()
          Tests whether any element in the form has been changed.
 boolean hasChanged(FormEntry entry)
          Tests whether the value of the element for the given entry has changed.
 boolean hasChanged(java.lang.String entryName)
          Tests whether the value of the element with the given name has changed.
 boolean hasMessages()
          Return true if there are no messages recorded in this object, or false otherwise.
 void populateForm(Record record, FormEntry[] entries)
          Populates the specified form entries with the data from the record.
 void populateForm(Record record, FormEntry[] entries, boolean setCurrentAsInitial)
          Populates the specified form entries with the data from the record.
 void populateObject(FormEntry[] entries, Record record)
          Populates the record with the data from the form elements of the corresponding form entries.
 void populateObject(FormEntry[] entries, Record record, boolean transferUnchangedValues)
          Populates the record with the data from the form elements of the corresponding form entries.
 void setContainer(Container container)
          
 void setCurrentAsInitialState()
          
 void validate()
          
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.mguennewig.pobjform.PObjForm
createFormElement, getElement, getFormDecl
 

Field Detail

ERROR_INVALID_VALUE

public static final java.lang.String ERROR_INVALID_VALUE
Message key that specifies that the value is invalid.

See Also:
Constant Field Values

ERROR_MANDATORY

public static final java.lang.String ERROR_MANDATORY
Message key that specifies that the value is mandatory.

See Also:
Constant Field Values
Constructor Detail

AbstractPObjForm

public AbstractPObjForm(Container container)
Creates a new PObject-enhanced form.

Parameters:
container - The database connection, which should be used.
Method Detail

addMessage

public final void addMessage(java.lang.String property,
                             Message msg)
Add a message to the set of messages for the specified property.

Specified by:
addMessage in interface PObjForm

addInvalidValueMessage

public final void addInvalidValueMessage(java.lang.String property,
                                         java.lang.Object... params)
Adds an error message for the specified property that the value invalid.

Specified by:
addInvalidValueMessage in interface PObjForm
See Also:
PObjForm.addMessage(String,Message)

addMandatoryMessage

public final void addMandatoryMessage(java.lang.String property)
Adds an error message for the specified property that the value is mandatory.

Specified by:
addMandatoryMessage in interface PObjForm
See Also:
PObjForm.addMessage(String,Message)

addErrorMessage

public final void addErrorMessage(java.lang.String messageId,
                                  java.lang.Object... params)
Adds a success message to the set of global messages.

Specified by:
addErrorMessage in interface PObjForm

addSuccessMessage

public final void addSuccessMessage(java.lang.String messageId,
                                    java.lang.Object... params)
Adds a success message to the set of global messages.

Specified by:
addSuccessMessage in interface PObjForm

clearMessages

public final void clearMessages()
Clear all messages recorded by this object.

Specified by:
clearMessages in interface PObjForm

clearMessage

public final void clearMessage(java.lang.String property,
                               java.lang.String msgKey)
Removes a specific message for the given property.

Specified by:
clearMessage in interface PObjForm

getMessageCount

public final int getMessageCount()
Return the number of messages recorded for all properties (including global messages).

Specified by:
getMessageCount in interface PObjForm

getMessageCount

public final int getMessageCount(java.lang.String property)
Return the number of messages associated with the specified property.

Specified by:
getMessageCount in interface PObjForm

getMessageProperties

public final java.util.Iterator<java.lang.String> getMessageProperties()
Return the set of property names for which at least one message has been recorded.

Specified by:
getMessageProperties in interface PObjForm

getMessages

public final Messages getMessages()

Specified by:
getMessages in interface PObjForm

getMessages

public final java.util.Iterator<Message> getMessages(java.lang.String property)
Return the set of messages related to a specific property.

Specified by:
getMessages in interface PObjForm

hasMessages

public final boolean hasMessages()
Return true if there are no messages recorded in this object, or false otherwise.

Specified by:
hasMessages in interface PObjForm

getElements

public final java.util.List<FormElement> getElements()

Specified by:
getElements in interface PObjForm

getContainer

public final Container getContainer()
Returns the database connection which the form uses.

Specified by:
getContainer in interface PObjForm

setContainer

public final void setContainer(Container container)

Specified by:
setContainer in interface PObjForm

hasChanged

public boolean hasChanged()
Tests whether any element in the form has been changed.

Specified by:
hasChanged in interface PObjForm

hasChanged

public final boolean hasChanged(java.lang.String entryName)
Tests whether the value of the element with the given name has changed.

Specified by:
hasChanged in interface PObjForm

hasChanged

public final boolean hasChanged(FormEntry entry)
Tests whether the value of the element for the given entry has changed.

Specified by:
hasChanged in interface PObjForm
See Also:
PObjForm.hasChanged(String)

populateForm

public void populateForm(Record record,
                         FormEntry[] entries,
                         boolean setCurrentAsInitial)
Populates the specified form entries with the data from the record.

For the current value of the corresponding form element for each form entry will the set to the value of the column with the same name within the record.

Specified by:
populateForm in interface PObjForm
Parameters:
record - The record which should be populated into the form.
entries - The form entries whose current values will be set to the data read from the record.
setCurrentAsInitial - if true the new current value of the changed form elements will also be used as the initial one.
See Also:
PObjForm.getElement(FormEntry)

populateForm

public final void populateForm(Record record,
                               FormEntry[] entries)
Populates the specified form entries with the data from the record.

This method ensures that the new value is also used as initial one.

Specified by:
populateForm in interface PObjForm
Parameters:
record - The record which should be populated into the form.
entries - The form entries whose current values will be set to the data read from the record.
See Also:
PObjForm.populateForm(Record,FormEntry[],boolean)

populateObject

public void populateObject(FormEntry[] entries,
                           Record record,
                           boolean transferUnchangedValues)
Populates the record with the data from the form elements of the corresponding form entries.

For each specified form entry the current value of the corresponding form element will be written to the column with the same name in the record.

Specified by:
populateObject in interface PObjForm
Parameters:
entries - The form entries whose current values will be set to the data read from the record.
record - The record which should be populated into the form.
transferUnchangedValues - if false only the values of form elements that have been changed are copied into the record.
See Also:
PObjForm.getElement(FormEntry)

populateObject

public final void populateObject(FormEntry[] entries,
                                 Record record)
Populates the record with the data from the form elements of the corresponding form entries.

This method only transfers changed values into the record.

Specified by:
populateObject in interface PObjForm
Parameters:
entries - The form entries whose current values will be set to the data read from the record.
record - The record which should be populated into the form.
See Also:
PObjForm.populateObject(FormEntry[],Record,boolean)

setCurrentAsInitialState

public void setCurrentAsInitialState()

Specified by:
setCurrentAsInitialState in interface PObjForm

validate

public void validate()

Specified by:
validate in interface PObjForm

dumpMessages

public final void dumpMessages(java.io.PrintStream ps,
                               java.util.ResourceBundle bundle)

getElementLabelKey

public static java.lang.String getElementLabelKey(FormElement element)
Returns the message resource key for the given element.

The resource key has the format [<pkgName>.]<formName>.<elementProperty>, where

pkgName
is the last segment of the package the elements form belongs to. If the form class does not belong to a package then this is left out.
formName
is the form name as specified in its declaration.
elementProperty
is the element property without any array indices.

For example for the form a.test.Form and element name the message key would be test.Form.name. Note that if one uses has different form interfaces for a.test.Form then name will remains as it for all interfaces.


extractIndexes

public static java.lang.Integer[] extractIndexes(java.lang.String property)