org.springframework.richclient.form
Class AbstractMasterForm

java.lang.Object
  extended by org.springframework.richclient.application.support.ApplicationServicesAccessor
      extended by org.springframework.richclient.factory.AbstractControlFactory
          extended by org.springframework.richclient.form.AbstractForm
              extended by org.springframework.richclient.form.AbstractMasterForm
All Implemented Interfaces:
CommitListener, ControlFactory, Form
Direct Known Subclasses:
AbstractTableMasterForm

public abstract class AbstractMasterForm
extends AbstractForm

Abstract base for the Master form of a Master/Detail pair. Derived types must implement two methods:

createDetailForm(org.springframework.binding.form.HierarchicalFormModel, org.springframework.binding.value.ValueModel, org.springframework.binding.value.support.ObservableList)
To construct the detail half of this master/detail pair
getSelectionModel()
To return the selection model of the object rendering the list

Important note: Any subclass that implements AbstractForm.createControl() MUST call configure() prior to its work in order to have the detail form properly prepared.

Author:
Larry Streepy
See Also:
AbstractDetailForm, creatingNewObject()

Nested Class Summary
protected  class AbstractMasterForm.ListSelectionHandler
          Inner class to handle the list selection and installing the selection into the detail form.
 
Field Summary
static String IS_CREATING_PROPERTY
          Property name for indicating changes in our "is creating new object" state.
static String SELECTION_INDEX_PROPERTY
          Property name for indicating changes in our selected index.
 
Fields inherited from class org.springframework.richclient.application.support.ApplicationServicesAccessor
logger
 
Constructor Summary
protected AbstractMasterForm(HierarchicalFormModel parentFormModel, String property, String formId, Class detailType)
          Construct a new AbstractMasterForm using the given parent form model and property path.
 
Method Summary
protected  void configure()
          Configure this master form's data and prepare the detail form.
protected  JComponent createButtonBar()
          Return a standardized row of command buttons, right-justified and all of the same size, with OK as the default button, and no mnemonics used, as per the Java Look and Feel guidelines.
protected  JButton createDeleteButton()
          Construct the button to invoke the delete command.
protected  ActionCommand createDeleteCommand()
          Create the "delete object" command.
protected abstract  AbstractDetailForm createDetailForm(HierarchicalFormModel parentFormModel, ValueModel valueHolder, ObservableList masterList)
          Construct the detail half of this master/detail pair.
protected  ActionCommand createNewFormObjectCommand()
          Create the "new detail object" command.
 void creatingNewObject()
          Indicates that we are creating a new detail object.
protected  void deleteSelectedItems()
          Delete the detail item at the specified index.
 ValueModel getCollectionValueModel()
          Get the value model representing the collection we are managing.
protected  CommandGroup getCommandGroup()
          Get the command group for the master table (the add and delete commands).
protected  String getConfirmDeleteMessage()
          Get the message to present to the user when confirming the delete of selected detail items.
 ActionCommand getDeleteCommand()
          Return the command to delete the currently selected item in the master set.
protected  String getDeleteCommandId()
          Construct the "delete detail object" command id as delete[DetailTypeName]Command
protected  AbstractDetailForm getDetailForm()
           
protected  ValidatingFormModel getDetailFormModel()
           
protected  Class getDetailType()
           
 List getFormData()
          Get the form data we are operating upon.
protected  Class getMasterCollectionType(ValueModel collectionPropertyVM)
          Determine the type of the collection holding the detail items.
 ObservableEventList getMasterEventList()
          Get the master EventList (which proxies the real form data).
 ActionCommand getNewFormObjectCommand()
          Get the action command to creating a new detail object.
protected  String getNewFormObjectCommandId()
          Construct the "new detail object" command id as new[detailTypeName]Command
protected  JPopupMenu getPopupMenu()
          Get the popup menu for the master table.
protected  ca.odell.glazedlists.EventList getRootEventList()
          Get the root event list for this model.
protected  ListSelectionListener getSelectionHandler()
          Get the selection handler for the master list.
protected abstract  ListSelectionModel getSelectionModel()
          Get the selection model for the master list representation.
protected  void handleExternalRootEventListChange()
          Handle the root event list being changed externally.
protected  void installEventList(ca.odell.glazedlists.EventList eventList)
          Install an EventList for use as our master list data.
protected  void installSelectionHandler()
          Install our selection handler.
 boolean isConfirmDelete()
          Return confirm delete setting.
protected  void maybeCreateNewObject()
          Deal with the user invoking a "new object" command.
protected  void maybeDeleteSelectedItems()
          Maybe delete the selected items.
 ValidationResultsReporter newSingleLineResultsReporter(Messagable messageReceiver)
          When the results reporter is setup on the master form, we need to capture it and forward it on to the detail form as well.
 void setConfirmDelete(boolean confirmDelete)
          Set confirm delete.
protected  void setDetailForm(AbstractDetailForm form)
           
protected  void setDetailType(Class type)
           
protected  void uninstallSelectionHandler()
          Uninstall our selection handler.
protected  void updateControlsForState()
          Update our controls based on our state.
 
Methods inherited from class org.springframework.richclient.form.AbstractForm
addChildForm, addFormObjectChangeListener, addFormValueChangeListener, addGuarded, addGuarded, addValidationListener, addValidationResultsReporter, attachFormErrorGuard, attachFormGuard, commit, constructSecurityControllerId, createCommitButton, createControl, createFormControl, createNewFormObjectButton, createNewObject, detachFormGuard, getBindingFactory, getChildForm, getCommitCommand, getCommitCommandFaceDescriptorId, getCommitSecurityControllerId, getDefaultButton, getEditableFormObject, getEditingFormObjectIndex, getFormModel, getFormObject, getId, getNewFormObjectSecurityControllerId, getParent, getRevertCommand, getRevertCommandFaceDescriptorId, getValidationResultsReporters, getValue, getValueModel, handleEnabledChange, hasErrors, init, isDirty, isEditingNewFormObject, isEnabled, postCommit, preCommit, removeChildForm, removeFormObjectChangeListener, removeFormValueChangeListener, removeGuarded, removeValidationListener, removeValidationResultsReporter, reset, revert, setClearFormOnCommit, setDefaultButton, setEditableFormObjects, setEditingFormObjectIndexHolder, setEditingFormObjectIndexSilently, setEditingNewFormObject, setEnabled, setFormModel, setFormModelDefaultEnabledState, setFormObject, setId
 
Methods inherited from class org.springframework.richclient.factory.AbstractControlFactory
createControlIfNecessary, getControl, isControlCreated, isSingleton, setSingleton
 
Methods inherited from class org.springframework.richclient.application.support.ApplicationServicesAccessor
getActiveWindow, getApplication, getApplicationContext, getApplicationName, getApplicationServices, getCommandConfigurer, getComponentFactory, getConversionService, getIconSource, getImageSource, getMessage, getMessage, getMessage, getMessage, getMessages, getMessageSource, getObjectConfigurer, getService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.richclient.factory.ControlFactory
getControl
 

Field Detail

SELECTION_INDEX_PROPERTY

public static final String SELECTION_INDEX_PROPERTY
Property name for indicating changes in our selected index.

See Also:
Constant Field Values

IS_CREATING_PROPERTY

public static final String IS_CREATING_PROPERTY
Property name for indicating changes in our "is creating new object" state.

See Also:
Constant Field Values
Constructor Detail

AbstractMasterForm

protected AbstractMasterForm(HierarchicalFormModel parentFormModel,
                             String property,
                             String formId,
                             Class detailType)
Construct a new AbstractMasterForm using the given parent form model and property path. The form model for this class will be constructed by getting the value model of the specified property from the parent form model and constructing a DeepCopyBufferedCollectionValueModel on top of it.

Parameters:
parentFormModel - Parent form model to access for this form's data
property - containing this forms data (must be a collection or an array)
formId - Id of this form
detailType - Type of detail object managed by this master form
Method Detail

getCollectionValueModel

public ValueModel getCollectionValueModel()
Get the value model representing the collection we are managing. This value model can be used to register vlue change listeners and to update the collection contents.

You must use this method to get the value model since calling getValueModel on the parent form model will not get you what you want.

Returns:
collection value model

getMasterCollectionType

protected Class getMasterCollectionType(ValueModel collectionPropertyVM)
Determine the type of the collection holding the detail items. This will be used to create the value model for the collection.

Note to Hibernate users: You will most likely need to override this method in order to force the use of a simple List class instead of the default implementation that would return PersistentList. Creating a new instance of this type would result in a somewhat misleading error regarding lazy instantiation since the new PersistentList instance would not have been properly initialized by Hibernate.

Parameters:
collectionPropertyVM - ValueModel holding the master collection
Returns:
Type of collection to use

configure

protected void configure()
Configure this master form's data and prepare the detail form.


createDetailForm

protected abstract AbstractDetailForm createDetailForm(HierarchicalFormModel parentFormModel,
                                                       ValueModel valueHolder,
                                                       ObservableList masterList)
Construct the detail half of this master/detail pair.

Parameters:
parentFormModel -
valueHolder - BufferedValueModel holding an object of the type configured for this master form.
masterList - The ObservableList of data to from the master form (this will constitute the editable object list for the detail form).

installEventList

protected void installEventList(ca.odell.glazedlists.EventList eventList)
Install an EventList for use as our master list data. The event list must have been created on top of the event list obtained from getRootEventList() so that all changes are propery proxied onto the actual form data. The event list provided will be wrapped in a ObservableEventList.

Parameters:
eventList - new EventList to install

getRootEventList

protected ca.odell.glazedlists.EventList getRootEventList()
Get the root event list for this model. This event list will be constructed from the form objects value (assumed to be an EventList). Any subclasses that are installing additional transformed lists should use this method to obtain the original event list on top of which all the other lists are constructed.


handleExternalRootEventListChange

protected void handleExternalRootEventListChange()
Handle the root event list being changed externally. This is normally invoked when the value model holding this forms source property has changed (which can occur when the parent form object is changed). This method is normally invoked from the parent form object listener.

See Also:
parentFormPropertyChangeHandler

getFormData

public List getFormData()
Get the form data we are operating upon. The form object must be castable to List for this to work.

Returns:
List The form object's value

getMasterEventList

public ObservableEventList getMasterEventList()
Get the master EventList (which proxies the real form data).

Returns:
EventList

getSelectionModel

protected abstract ListSelectionModel getSelectionModel()
Get the selection model for the master list representation.

Returns:
selection model

installSelectionHandler

protected void installSelectionHandler()
Install our selection handler.


uninstallSelectionHandler

protected void uninstallSelectionHandler()
Uninstall our selection handler.


creatingNewObject

public void creatingNewObject()
Indicates that we are creating a new detail object. Default behavior is to just clear the selection on the master set.


getSelectionHandler

protected ListSelectionListener getSelectionHandler()
Get the selection handler for the master list. Default implementation.

Returns:
listener to handle master table selection events

getCommandGroup

protected CommandGroup getCommandGroup()
Get the command group for the master table (the add and delete commands).

Returns:
command group

createButtonBar

protected JComponent createButtonBar()
Return a standardized row of command buttons, right-justified and all of the same size, with OK as the default button, and no mnemonics used, as per the Java Look and Feel guidelines.


getPopupMenu

protected JPopupMenu getPopupMenu()
Get the popup menu for the master table. This is built from the command group returned from getCommandGroup().

Returns:
popup menu

getNewFormObjectCommand

public ActionCommand getNewFormObjectCommand()
Get the action command to creating a new detail object. Note that we have to override this method in order to call our own createNewDetailObjectCommand method since the AbstractForm's implementation of createNewFormObjectCommand is private!

Overrides:
getNewFormObjectCommand in class AbstractForm

createNewFormObjectCommand

protected ActionCommand createNewFormObjectCommand()
Create the "new detail object" command. This will encapsulate the action from our detail forms AbstractForm.getNewFormObjectCommand() as well as controlling the state of the detail form.

Returns:
command

getNewFormObjectCommandId

protected String getNewFormObjectCommandId()
Construct the "new detail object" command id as new[detailTypeName]Command

Overrides:
getNewFormObjectCommandId in class AbstractForm
Returns:
constructed command id

getDeleteCommand

public ActionCommand getDeleteCommand()
Return the command to delete the currently selected item in the master set.

Returns:
command, created on demand

createDeleteCommand

protected ActionCommand createDeleteCommand()
Create the "delete object" command.

Returns:
command

getConfirmDeleteMessage

protected String getConfirmDeleteMessage()
Get the message to present to the user when confirming the delete of selected detail items. This default implementation just obtains the message with key <formId>.confirmDelete.message or masterForm.confirmDelete.message. Subclasses can use the selected item(s) to construct a more meaningful message.


maybeDeleteSelectedItems

protected void maybeDeleteSelectedItems()
Maybe delete the selected items. If we are configured to confirm the delete, then do so. If the user confirms, then delete the selected items.


deleteSelectedItems

protected void deleteSelectedItems()
Delete the detail item at the specified index.


createDeleteButton

protected JButton createDeleteButton()
Construct the button to invoke the delete command.

Returns:
button

getDeleteCommandId

protected String getDeleteCommandId()
Construct the "delete detail object" command id as delete[DetailTypeName]Command

Returns:
constructed command id

getDetailForm

protected AbstractDetailForm getDetailForm()
Returns:
Returns the detailForm.

setDetailForm

protected void setDetailForm(AbstractDetailForm form)
Parameters:
form - The detailForm to set.

getDetailFormModel

protected ValidatingFormModel getDetailFormModel()
Returns:
Returns the detailFormModel.

getDetailType

protected Class getDetailType()
Returns:
Returns the detailType.

setDetailType

protected void setDetailType(Class type)
Parameters:
type - The detailType to set.

isConfirmDelete

public boolean isConfirmDelete()
Return confirm delete setting.

Returns:
confirm delete setting.

setConfirmDelete

public void setConfirmDelete(boolean confirmDelete)
Set confirm delete. If this is true then the master form will confirm with the user prior to deleting a detail item.

Parameters:
confirmDelete -

maybeCreateNewObject

protected void maybeCreateNewObject()
Deal with the user invoking a "new object" command. If we have unsaved changes, then we need to query the user to ensure they want to really make the change.


updateControlsForState

protected void updateControlsForState()
Update our controls based on our state.


newSingleLineResultsReporter

public ValidationResultsReporter newSingleLineResultsReporter(Messagable messageReceiver)
When the results reporter is setup on the master form, we need to capture it and forward it on to the detail form as well.

Specified by:
newSingleLineResultsReporter in interface Form
Overrides:
newSingleLineResultsReporter in class AbstractForm
Parameters:
messageReceiver - the message receiver used by the created resultsReporter.
Returns:
a new ResultsReporter.


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.