Form
Method:
Init ->
method
public void init()
{
DictTable
dictTable;
FormBuildDataSource fds;
FormBuildDesign
formBuildDesign;
#DEFINE.FormWidth(500)
#DEFINE.FormHeight(300)
this.dictTable = new DictTable(tableNum(<TableName>));
this.fds = this.form().dataSource(formDataSourceStr(<FormName>,<TableName>));
formBuildDesign = this.form().design();
formBuildDesign.widthMode(-1);
formBuildDesign.widthValue(#FormWidth);
formBuildDesign.heightMode(-1);
formBuildDesign.heightValue(#FormHeight);
FormBuildGroupControl tabGroupCtrl = formBuildDesign.control(‘GroupName’);
tabGroupCtrl.dataSource(fds.id());
tabGroupCtrl.allowEdit(true);
tabGroupCtrl.hideIfEmpty(false);
//We can loop it as well, if requires
for all fields
this.addField(dictTable.id(), fieldName2Id(dictTable.id(),
configFields.FieldName), fds, tabGroupCtrl, true);
super(); //All build control should generate before init super call
}
Addfield -> method
protected void addField(tableId _tableId,
fieldId _fieldId,
FormBuildDataSource _formBuildDataSource,
FormBuildGroupControl _formBuildGroupControl,
boolean _allowControlEdit)
{
FormBuildStringControl formBuildStringControl;
FormBuildInt64Control formBuildInt64Control;
FormBuildIntControl formBuildIntControl;
FormBuildComboBoxControl formBuildComboBoxControl;
FormBuildCheckBoxControl formBuildCheckBoxControl;
FormBuildTimeControl formBuildTimeControl;
FormBuildDateControl formBuildDateControl;
FormBuildGuidControl formBuildGuidControl;
FormBuildDateTimeControl formBuildDateTimeControl;
FormBuildRealControl formBuildRealControl;
FormBuildSegmentedEntryControl formBuildSegmentedEntryControl;
FormBuildReferenceGroupControl formBuildReferenceGroupControl;
FormBuildControl formBuildControl;
SysDictField dictField;
int j;
tableId rootTableId;
str controlName;
UtilElementName utilElmName;
Types baseType;
dictField = new SysDictField(_tableId, _fieldId);
if(dictField.isSystem())
{
//System
fields are only stored on the root table, so get the information from there.
rootTableId = SysDictTable::getRootTable(_tableId);
dictField = new SysDictField(rootTableId, _fieldId);
}
if (dictField.saveContents())
{
for(j = 1;j <=
dictField.arraySize(); j++)
{
formBuildControl = null;
controlName =
strfmt('%1_%2', dictField.name(), j);
baseType =
dictField.baseType();
utilElmName =
dictField.typeName();
switch (baseType)
{
case Types::String:
case Types::RString:
case Types::VarString:
formBuildStringControl
= _formBuildGroupControl.addDataField(_formBuildDataSource.id(), _fieldId, j);
formBuildStringControl.autoDeclaration(true);
formBuildStringControl.label(dictField.name());
formBuildStringControl.displayHeightMode(0);
formBuildStringControl.displayHeightValue(1);
formBuildControl =
formBuildStringControl;
break;
case Types::Integer:
if (Global::isTypeTime(utilElmName))
{
formBuildTimeControl =
_formBuildGroupControl.addDataField(_formBuildDataSource.id(), _fieldId, j);
formBuildTimeControl.autoDeclaration(true);
formBuildTimeControl.label(dictField.name());
formBuildControl =
formBuildTimeControl;
}
else
{
formBuildIntControl
= _formBuildGroupControl.addDataField(_formBuildDataSource.id(), _fieldId, j);
formBuildIntControl.autoDeclaration(true);
formBuildIntControl.label(dictField.name());
formBuildControl =
formBuildIntControl;
}
break;
case Types::Int64:
// Reference
Controls are created by default for surrogate foreign keys. However, the raw
64-bit
// integer should always be displayed. Force all Int64 type fields
to use an Int64 Control.
formBuildControl =
_formBuildGroupControl.addDataField(_formBuildDataSource.id(), _fieldId, j);
formBuildInt64Control =
formBuildControl as formBuildInt64Control;
if (formBuildInt64Control != null)
{
formBuildInt64Control.autoDeclaration(true);
formBuildInt64Control.label(dictField.name());
formBuildControl =
formBuildInt64Control;
}
else
{
formBuildReferenceGroupControl = formbuildControl as FormBuildReferenceGroupControl;
if (formBuildReferenceGroupControl != null)
{
formBuildReferenceGroupControl.autoDeclaration(true);
formBuildReferenceGroupControl.label(dictField.name());
formBuildControl
= formBuildReferenceGroupControl;
}
else
{
formBuildSegmentedEntryControl = formBuildControl as formBuildSegmentedEntryControl;
if (formBuildSegmentedEntryControl != null)
{
formBuildSegmentedEntryControl.autoDeclaration(true);
formBuildSegmentedEntryControl.label(dictField.name());
formBuildControl = formBuildSegmentedEntryControl;
}
}
}
break;
case Types::Enum:
formBuildControl =
_formBuildGroupControl.addDataField(_formBuildDataSource.id(), _fieldId, j);
formBuildComboBoxControl = formBuildControl as formBuildComboBoxControl;
if (formBuildComboBoxControl != null)
{
formBuildComboBoxControl.autoDeclaration(true);
formBuildComboBoxControl.label(dictField.name());
formBuildControl =
formBuildComboBoxControl;
}
else
{
formBuildCheckBoxControl = formBuildControl as FormBuildCheckBoxControl;
if (formBuildCheckBoxControl != null)
{
formBuildCheckBoxControl.autoDeclaration(true);
formBuildCheckBoxControl.label(dictField.name());
formBuildControl = formBuildCheckBoxControl;
}
}
break;
case Types::Real:
formBuildRealControl =
_formBuildGroupControl.addDataField(_formBuildDataSource.id(), _fieldId, j);
formBuildRealControl.autoDeclaration(true);
formBuildRealControl.label(dictField.name());
formBuildControl =
formBuildComboBoxControl;
break;
case Types::Guid:
formBuildGuidControl =
_formBuildGroupControl.addDataField(_formBuildDataSource.id(), _fieldId, j);
formBuildGuidControl.autoDeclaration(true);
formBuildGuidControl.label(dictField.name());
formBuildControl =
formBuildGuidControl;
break;
case Types::Date:
formBuildDateControl =
_formBuildGroupControl.addDataField(_formBuildDataSource.id(), _fieldId, j);
formBuildDateControl.autoDeclaration(true);
formBuildDateControl.label(dictField.name());
formBuildControl =
formBuildDateControl;
break;
case Types::UtcDateTime:
formBuildDateTimeControl = _formBuildGroupControl.addDataField(_formBuildDataSource.id(),
_fieldId, j);
formBuildDateTimeControl.autoDeclaration(true);
formBuildDateTimeControl.label(dictField.name());
formBuildControl =
formBuildDateTimeControl;
break;
}
if (formbuildControl != null)
{
formbuildControl.name(controlName);
formbuildControl.helpText(dictField.label());
formBuildSegmentedEntryControl = formBuildControl as FormBuildSegmentedEntryControl;
if (formBuildSegmentedEntryControl != null)
{
// Segmented Entry controls should never be editable in the Table
Browser.
// There is no way to specify a Controller class so the user would
see errors.
formBuildSegmentedEntryControl.allowEdit(false);
}
else
{
formbuildControl.allowEdit(_allowControlEdit);
}
}
}
}
}