dsto.dfc.swing.forms
Class BasicForm

java.lang.Object
  extended by dsto.dfc.swing.forms.BasicFormEditorEventSource
      extended by dsto.dfc.swing.forms.BasicForm
All Implemented Interfaces:
Form, FormEditor, FormEditorListener, Copyable, Disposable, PropertyChangeListener, Serializable, Cloneable, EventListener

public class BasicForm
extends BasicFormEditorEventSource
implements Form, Disposable, FormEditorListener, PropertyChangeListener

Basic implementation of the Form interface. Designed to be used either as a base as a delegate.

Version:
$Revision$
Author:
Matthew
See Also:
Serialized Form

Nested Class Summary
protected static class BasicForm.EditorEntry
           
 
Field Summary
 boolean directEdit
           
 
Constructor Summary
BasicForm()
           
 
Method Summary
 void addEditor(String property, FormEditor editor)
           
 void addEditor(String property, FormEditor editor, ValueConverter converter)
          Add an editor for a given property of the form value.
protected  void commitChildren()
           
 void commitEdits()
          Commit any changes not already committed into the value of this editor (eg a text editor will attempt to perform any uncommitted text conversions at this point).
 void dispose()
          Dispose of the object (unregister listeners, close open resources etc).
 void editCommitRequested(ChangeEvent e)
          Signals that the editor is ready to commit a value into the model.
 void editCommitted(ChangeEvent e)
          Signals that an edit has been committed into the model.
protected  BasicForm.EditorEntry findEntry(FormEditor editor)
           
 Component getEditorComponent()
          Get the component, if any, that acts as a UI for this editor.
 int getEditorCount()
           
 String getEditorDescription()
          Get a short description of the value being edited for this editor (eg 'host name').
 Object getEditorValue()
          Get the current value from the form editor.
 Class getPreferredValueType()
          The preferred type of value for the editor.
static void handleCommitError(IllegalFormatException ex)
           
 boolean isDeferredCommit()
          True if editor commit requests from child editors are deferred until commitEdits () is explicitly called on this form.
 boolean isDirectEdit()
          True if the editor directly edits the value passed in with setValue ().
protected  void loadEditor(BasicForm.EditorEntry entry)
           
protected  void loadEditors()
           
 void propertyChange(PropertyChangeEvent e)
           
 boolean removeEditor(FormEditor editor)
          Remove a bound form editor.
 void setDeferredCommit(boolean newValue)
           
 void setDirectEdit(boolean newValue)
          Set whether this editor works in direct edit (default) mode, or indirect.
 void setEditorValue(Object newValue)
          Sets the value to be displayed/edited by the form editor.
 void setPreferredValueType(Class newValueType)
           
protected  void unloadEditor(BasicForm.EditorEntry entry)
           
protected  void unloadEditors()
           
 
Methods inherited from class dsto.dfc.swing.forms.BasicFormEditorEventSource
addFormEditorListener, clone, fireEditComitted, fireEditCommitRequested, fireEditCommitted, removeFormEditorListener, setFormEditorEventSource
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface dsto.dfc.swing.forms.FormEditor
addFormEditorListener, removeFormEditorListener
 

Field Detail

directEdit

public boolean directEdit
Constructor Detail

BasicForm

public BasicForm()
Method Detail

dispose

public void dispose()
Description copied from interface: Disposable
Dispose of the object (unregister listeners, close open resources etc). It should be safe to call this method more than once. Note for beans that support client event listeners: if there are listeners registered when this is called, this method should do nothing.

Specified by:
dispose in interface Disposable

isDirectEdit

public boolean isDirectEdit()
Description copied from interface: FormEditor
True if the editor directly edits the value passed in with setValue (). If false, the parent editor will be reponsible for retrieving the value from the editor and storing it.

Specified by:
isDirectEdit in interface FormEditor

setDirectEdit

public void setDirectEdit(boolean newValue)
Set whether this editor works in direct edit (default) mode, or indirect. In indirect mode, a copy of the editor value passed to setEditorValue () is edited and returned from getEditorValue ().


getPreferredValueType

public Class getPreferredValueType()
Description copied from interface: FormEditor
The preferred type of value for the editor. Values conforming to this type may be safely passed to FormEditor.setEditorValue(java.lang.Object). May return java.lang.Object to indictate no preferred type.

Specified by:
getPreferredValueType in interface FormEditor

setPreferredValueType

public void setPreferredValueType(Class newValueType)

getEditorDescription

public String getEditorDescription()
Description copied from interface: FormEditor
Get a short description of the value being edited for this editor (eg 'host name'). May be null.

Specified by:
getEditorDescription in interface FormEditor

isDeferredCommit

public boolean isDeferredCommit()
Description copied from interface: Form
True if editor commit requests from child editors are deferred until commitEdits () is explicitly called on this form. This can be used to implement forms where the user can apply changes via commitEdits () or cancel edits by simply not calling commitEdits () without having to copy the value being edited by the form. When in deferred commit mode, the form will copy values before passing them to setValue () on "direct edit" child FormEditor's and handle editCommitRequested events from sub-editors by calling commit () but not storing the subeditor's value.

Specified by:
isDeferredCommit in interface Form

setDeferredCommit

public void setDeferredCommit(boolean newValue)
Specified by:
setDeferredCommit in interface Form

addEditor

public void addEditor(String property,
                      FormEditor editor)
Specified by:
addEditor in interface Form

addEditor

public void addEditor(String property,
                      FormEditor editor,
                      ValueConverter converter)
Description copied from interface: Form
Add an editor for a given property of the form value.

Specified by:
addEditor in interface Form
Parameters:
property - The property name.
editor - The editor for the property.
converter - The value converter that will be used to convert values into the editor's format (determined by FormEditor.getPreferredValueType() and from the editor back to the property value. May be null for no conversion.
See Also:
Form.removeEditor(dsto.dfc.swing.forms.FormEditor)

removeEditor

public boolean removeEditor(FormEditor editor)
Description copied from interface: Form
Remove a bound form editor.

Specified by:
removeEditor in interface Form
Returns:
True if the editor was removed.
See Also:
Form.addEditor(java.lang.String, dsto.dfc.swing.forms.FormEditor)

getEditorCount

public int getEditorCount()

findEntry

protected BasicForm.EditorEntry findEntry(FormEditor editor)

loadEditors

protected void loadEditors()
                    throws IllegalFormatException
Throws:
IllegalFormatException

unloadEditors

protected void unloadEditors()
                      throws IllegalFormatException
Throws:
IllegalFormatException

loadEditor

protected void loadEditor(BasicForm.EditorEntry entry)
                   throws IllegalFormatException
Throws:
IllegalFormatException

unloadEditor

protected void unloadEditor(BasicForm.EditorEntry entry)
                     throws IllegalFormatException
Throws:
IllegalFormatException

commitChildren

protected void commitChildren()
                       throws IllegalFormatException
Throws:
IllegalFormatException

commitEdits

public void commitEdits()
                 throws IllegalFormatException
Description copied from interface: FormEditor
Commit any changes not already committed into the value of this editor (eg a text editor will attempt to perform any uncommitted text conversions at this point). Only editors that need support editing in non-atomic sessions (such as text fields) will generally do anything when this method is called. If commit is made that has not been signalled with a previous editCommitted event, the editor should fire an editCommitted event at this point. Composite editors, such as forms, will generally forward this request to their child editors.

Specified by:
commitEdits in interface FormEditor
Throws:
IllegalFormatException - if the commit failed because of an illegal input or other error. The source specified by the exception should be the FormEditor instance that caused the error (ie either this editor or a child).

setEditorValue

public void setEditorValue(Object newValue)
                    throws IllegalFormatException
Description copied from interface: FormEditor
Sets the value to be displayed/edited by the form editor.

Specified by:
setEditorValue in interface FormEditor
Parameters:
newValue - The value to display.
Throws:
IllegalFormatException - if the value was not in the correct format for display by this editor. The source specified by the exception should be this FormEditor instance or a child.

getEditorValue

public Object getEditorValue()
Description copied from interface: FormEditor
Get the current value from the form editor. At least one call to setValue () must be made beforehand.

Specified by:
getEditorValue in interface FormEditor

getEditorComponent

public Component getEditorComponent()
Description copied from interface: FormEditor
Get the component, if any, that acts as a UI for this editor. May return null if not associated with a component.

Specified by:
getEditorComponent in interface FormEditor

editCommitRequested

public void editCommitRequested(ChangeEvent e)
Description copied from interface: FormEditorListener
Signals that the editor is ready to commit a value into the model. Parent editors monitor will invoke commitEdits () on the the requesting editor if appropriate.

Specified by:
editCommitRequested in interface FormEditorListener

editCommitted

public void editCommitted(ChangeEvent e)
Description copied from interface: FormEditorListener
Signals that an edit has been committed into the model.

Specified by:
editCommitted in interface FormEditorListener

handleCommitError

public static void handleCommitError(IllegalFormatException ex)

propertyChange

public void propertyChange(PropertyChangeEvent e)
Specified by:
propertyChange in interface PropertyChangeListener


Copyright © 2008 Commonwealth of Australia