to.etc.domui.component.form
Class TabularFormBuilder

java.lang.Object
  extended by to.etc.domui.component.form.FormBuilderBase
      extended by to.etc.domui.component.form.GenericFormBuilder
          extended by to.etc.domui.component.form.GenericTableFormBuilder
              extended by to.etc.domui.component.form.TabularFormBuilder

public class TabularFormBuilder
extends GenericTableFormBuilder

This is a helper class to generate tabular forms. It lays out the form by creating a table and adding labels and input controls in separate table cells in a row. If nothing else is done this creates a form in the layout of:

First name
Last name
Address
A form builder is not a component by itself; it is a helper class which creates DomUI nodes AND a ModelBindings instance containing the bindings of the created components to their class instance and properties. After use you can discard the FormBuilder, provided you retain the bindings if you need them. A formbuilder is highly stateful during use.

There are ways to play around with the layout by using format directives before fields are added. Usually layout directives take effect for the next control that is added. There are two kinds of layout directives. Permanent ones change the settting, well, permanently until it is explicitly changed again. Permanent layout directives start with "set" in the call. There are also temporary layout directives, these have no "set" in their name. These take effect for the next the control or the next run of controls if they are added with a single call to the form builder, for instance using addProps(String... names). When the control or controls are added the layout directive returns to it's default setting.

Layout directives

The following layout directives are available: See the wiki for more details. FIXME Names for adding either property-based or control-based new additions are very unclear.

Author:
Frits Jalvingh Created on Aug 19, 2008

Field Summary
 
Fields inherited from class to.etc.domui.component.form.FormBuilderBase
LOG
 
Constructor Summary
TabularFormBuilder()
           
TabularFormBuilder(java.lang.Class<T> clz, IReadOnlyModel<T> mdl)
           
TabularFormBuilder(T instance)
           
 
Method Summary
 void addContent(NodeBase label, NodeBase[] control, boolean editable)
           
 void addControl(NodeBase label, NodeBase labelnode, NodeBase[] list, boolean mandatory, boolean editable, PropertyMetaModel<?> pmm)
           
 void addControl(java.lang.String label, NodeBase labelnode, NodeBase[] list, boolean mandatory, boolean editable, PropertyMetaModel<?> pmm)
          Adds a control plus a label at the current location.
protected  IControl<?>[] addListOfProperties(boolean editable, java.lang.String... names)
          Handle placement of a list of property names, all obeying the current mode in effect.
 TabularFormBuilder append()
          Append the next field, then return to the current mode.
 TabularFormBuilder col(int x)
          Add the next fields in a set to the specified column.
 TabularFormBuilder colspan(int cells)
          Sets the colspan for the next component set.
 NodeContainer finish()
          Reset variables after finish.
 TabularFormBuilder into()
          Add the next pair into the last cell of the last row added, then return to the current mode.
 TabularFormBuilder into(java.lang.String separator)
          Add the next pair into the last cell of the last row added using the specified string to separate them, then return to the current mode.
protected  void modeAddAppend(NodeBase l, NodeBase[] c, boolean editable)
          This "appends" the new set to the "current" row.
protected  void modeAddNormal(NodeBase l, NodeBase[] c, boolean editable)
          Adds a node normally.
protected  void modeAppendInto(NodeBase l, NodeBase[] c, boolean editable)
          Appends the control to the last cell of the last row used.
 TabularFormBuilder norm()
          Add the next field in "normal" mode, then return to the current mode.
 TabularFormBuilder setCol(int x)
          Make column(x) the "current" column where things are added to, until another call is done.
 void setModeAppend()
           
 void setModeAppendInto()
           
 void setModeAppendInto(java.lang.String sepa)
           
 void setModeNorm()
          Sets the default mode to NORMAL, causing each field to occupy it's own row containing 2 cells for label and input control.
 
Methods inherited from class to.etc.domui.component.form.GenericTableFormBuilder
addCell, addCell, addRow, addRowAndCell, addRowAndCell, getLastUsedRow, getTable, getTBody, internalClearLocation, newBody, onBodyAdded, onRowAdded, onTableAdded, reset, row, selectRow, setLastUsedCell, setLastUsedRow, setTable, setTBody, table, tbody
 
Methods inherited from class to.etc.domui.component.form.GenericFormBuilder
addContent, addContent, addDisplayProp, addDisplayProp, addDisplayProp, addDisplayProps, addLabelAndControl, addLabelAndControl, addProp, addProp, addProp, addProp, addProp, addProp, addProp, addPropertyAndControl, addPropertyControl, addProps
 
Methods inherited from class to.etc.domui.component.form.FormBuilderBase
createControlFor, createControlFor, getBindings, getBuilder, getClassMeta, getContext, getControlLabelFactory, getCurrentInputClass, getModel, resolveProperty, rights, setBindings, setClassModel, setContext, setControlLabelFactory, setInstance, setMetaModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TabularFormBuilder

public TabularFormBuilder()

TabularFormBuilder

public TabularFormBuilder(java.lang.Class<T> clz,
                          IReadOnlyModel<T> mdl)

TabularFormBuilder

public TabularFormBuilder(T instance)
Method Detail

finish

public NodeContainer finish()
Reset variables after finish. Cannot be done when table is created!

Overrides:
finish in class GenericTableFormBuilder
Returns:

addListOfProperties

protected IControl<?>[] addListOfProperties(boolean editable,
                                            java.lang.String... names)
Handle placement of a list of property names, all obeying the current mode in effect. This one handles mode maintenance while placing the individual controls so the entire list added here obeys the "current" mode setting, not just the 1st control added.

Specified by:
addListOfProperties in class GenericFormBuilder

addControl

public void addControl(java.lang.String label,
                       NodeBase labelnode,
                       NodeBase[] list,
                       boolean mandatory,
                       boolean editable,
                       PropertyMetaModel<?> pmm)
Adds a control plus a label at the current location.

Specified by:
addControl in class GenericFormBuilder
Parameters:
label -
labelnode - The node to connect the Label to (for=)
mandatory -
editable - T when the node is editable, needed by the label factory

addControl

public void addControl(NodeBase label,
                       NodeBase labelnode,
                       NodeBase[] list,
                       boolean mandatory,
                       boolean editable,
                       PropertyMetaModel<?> pmm)
Specified by:
addControl in class GenericFormBuilder

addContent

public void addContent(NodeBase label,
                       NodeBase[] control,
                       boolean editable)
Specified by:
addContent in class GenericFormBuilder

norm

public TabularFormBuilder norm()
Add the next field in "normal" mode, then return to the current mode. All fields added after this will be added on their own row, with two cells per field (for label and control). This is the default mode.

Returns:
self (chained)

append

public TabularFormBuilder append()
Append the next field, then return to the current mode. This adds the next pair as two cells added to the current row.

Returns:
self (chained)

into

public TabularFormBuilder into()
Add the next pair into the last cell of the last row added, then return to the current mode. This merges >1 control in a single cell, causing them to be close together.

Returns:
self (chained)

into

public TabularFormBuilder into(java.lang.String separator)
Add the next pair into the last cell of the last row added using the specified string to separate them, then return to the current mode. This merges >1 control in a single cell, causing them to be close together.

Returns:
self (chained)

col

public TabularFormBuilder col(int x)
Add the next fields in a set to the specified column. After the fields return to the "previous" current column. FIXME This changes the (col, row) position of the "COL" mode without resetting it to it's previous position after the call. This violates the interface. I do not fix this now since I expect this not to be a problem.

Parameters:
x -
Returns:

setCol

public TabularFormBuilder setCol(int x)
Make column(x) the "current" column where things are added to, until another call is done. Move to column (x) and add this to the first free thingy there. This calculates a new row position by finding the first row where the column is not yet set. After the call this returns to the current mode.

Parameters:
x -
Returns:

colspan

public TabularFormBuilder colspan(int cells)
Sets the colspan for the next component set. When the set has been added the value returns to 1.

Parameters:
cells -
Returns:

setModeNorm

public void setModeNorm()
Sets the default mode to NORMAL, causing each field to occupy it's own row containing 2 cells for label and input control.


setModeAppend

public void setModeAppend()

setModeAppendInto

public void setModeAppendInto()

setModeAppendInto

public void setModeAppendInto(java.lang.String sepa)

modeAddNormal

protected void modeAddNormal(NodeBase l,
                             NodeBase[] c,
                             boolean editable)
Adds a node normally. If the current column is 0 this just adds a row and two cells, else it will locate the "current" row in the specified column and add cells there.

Parameters:
l -
c -

modeAddAppend

protected void modeAddAppend(NodeBase l,
                             NodeBase[] c,
                             boolean editable)
This "appends" the new set to the "current" row. It adds another two cells to the row. If there is no "current row" it gets created.

Parameters:
l -
c -

modeAppendInto

protected void modeAppendInto(NodeBase l,
                              NodeBase[] c,
                              boolean editable)
Appends the control to the last cell of the last row used.

Parameters:
l -
c -