com.partnersoft.gui.forms
Class Form

java.lang.Object
  extended by com.partnersoft.gui.forms.Form

public class Form
extends java.lang.Object

A Form is a classic form-like GUI editor for data.

Generally, forms feature data entry fields, buttons, tabs, tables, etc. The Forms framework handles layout, data editing, events, and other tedious tasks.

Forms can be driven from a CogSchema, deriving much of their behavior from the schema and eliminating even more tedium.

Copyright 2005-2009 Partner Software, Inc.

Version:
$Id$
Author:
Paul Reavis

Constructor Summary
Form(java.awt.Container gui)
           
 
Method Summary
 void addField(java.lang.String name, FormField field)
          Add a field to the form, assigned to the given field name.
 void addFieldListener(FormFieldListener nosey)
          Add a listener for field changes.
 void apply()
          This applies the current values in the FormField objects to the underlying data model.
 ActionBureau getActionBureau()
           
 Cog getEditedCog()
          Gets the currently-edited Cog.
 java.lang.Object getEditedFieldValue(java.lang.String field)
          This can be used to get things after editing without invoking a CogHeader or other object.
 java.lang.Object getEditedObject()
          Converts the currently-edited Cog to an object and returns the result.
 CogType getEditedType()
          Gets the edited CogType for the form.
 java.awt.Container getGui()
          Return the top-level container for all components in this form.
 CogSchema getSchema()
          Gets the CogSchema used by this Form.
 boolean isDisabled()
           
 java.util.List<FormField> listFields()
          Return a newly-constructed copy of the field list.
 Naming<FormField> nameFields()
          Return a newly-constructed copy of the fields, indexed by name.
 void removeFieldListener(FormFieldListener nosey)
          Remove a listener for field changes.
 FormField replaceField(java.lang.String name, FormField field)
          This swaps out the FormField assigned to the given field name, returning the FormField previously assigned to it.
 void reset()
          Resets the form by putting the field values from the underlying model into the FormField objects, discarding any changes that have been made in the GUI since the last apply().
 void setDisabled(boolean disabled)
          If true, disables the form (no input allowed).
 void setEditedCog(Cog newEdited)
          Set the currently-edited Cog.
 void setEditedFieldValue(java.lang.String field, java.lang.Object value)
          This can be used to set things to edit without creating a CogHeader or other object.
 void setEditedObject(java.lang.Object newEdited)
          Sets an object to be edited.
 void setEditedType(CogType newType)
          Sets the edited CogType for the form.
 void setSchema(CogSchema newSchema)
          Sets a custom CogSchema for this Form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Form

public Form(java.awt.Container gui)
Method Detail

getSchema

public CogSchema getSchema()
Gets the CogSchema used by this Form.


setSchema

public void setSchema(CogSchema newSchema)
Sets a custom CogSchema for this Form. The CogBootstrapSchema is used by default.


getEditedCog

public Cog getEditedCog()
Gets the currently-edited Cog. This is the actual data model used by the Form.

Returns:

setEditedCog

public void setEditedCog(Cog newEdited)
Set the currently-edited Cog. This becomes the actual data model used by the Form.

Parameters:
newEdited -

getEditedObject

public java.lang.Object getEditedObject()
Converts the currently-edited Cog to an object and returns the result.

Returns:

setEditedObject

public void setEditedObject(java.lang.Object newEdited)
Sets an object to be edited. This is then converted to Cog, so the object you pass in will not actually be modified by editing. A simple example of this would be to create a Naming of field name-to-field value, then use setEditedObject() to put those values into the field.


setEditedFieldValue

public void setEditedFieldValue(java.lang.String field,
                                java.lang.Object value)
This can be used to set things to edit without creating a CogHeader or other object. Just issue a series of these with the field values you want to set.

Parameters:
field -
value -

getEditedFieldValue

public java.lang.Object getEditedFieldValue(java.lang.String field)
This can be used to get things after editing without invoking a CogHeader or other object. Just call this for every field value you want to get.

Parameters:
field -

apply

public void apply()
This applies the current values in the FormField objects to the underlying data model. Unless this is called, the underlying data will not be changed and e.g. getEditedFieldValue("foo") will not return the currently-edited version of the "foo" field.


reset

public void reset()
Resets the form by putting the field values from the underlying model into the FormField objects, discarding any changes that have been made in the GUI since the last apply().


getActionBureau

public ActionBureau getActionBureau()

nameFields

public Naming<FormField> nameFields()
Return a newly-constructed copy of the fields, indexed by name.

Returns:

listFields

public java.util.List<FormField> listFields()
Return a newly-constructed copy of the field list.

Returns:

getGui

public java.awt.Container getGui()
Return the top-level container for all components in this form.

Returns:

addFieldListener

public void addFieldListener(FormFieldListener nosey)
Add a listener for field changes. The listener will receive events for all fields in the form.

Parameters:
nosey -

removeFieldListener

public void removeFieldListener(FormFieldListener nosey)
Remove a listener for field changes.

Parameters:
nosey -

addField

public void addField(java.lang.String name,
                     FormField field)
Add a field to the form, assigned to the given field name. Note that you should usually use a FormBuilder to construct a form; this is provided both for FormBuilder to use and for cases where for some reason you need to work around or outside of FormBuilder.

Parameters:
name -
field -

replaceField

public FormField replaceField(java.lang.String name,
                              FormField field)
This swaps out the FormField assigned to the given field name, returning the FormField previously assigned to it. Use this when you need to make individual changes to an auto-generated layout by e.g. FormBuilder.

Parameters:
name -
field -
Returns:

setEditedType

public void setEditedType(CogType newType)
Sets the edited CogType for the form. You only need to use this if you want the form to be tightly coupled to a specific CogType.

Parameters:
newType -

getEditedType

public CogType getEditedType()
Gets the edited CogType for the form.


setDisabled

public void setDisabled(boolean disabled)
If true, disables the form (no input allowed). Default is enabled.


isDisabled

public boolean isDisabled()