// loop by all form items
for (int i = 0; i < items.length; i++) {
// this is local variable, that will contains new data control
// instance
IBindableDataControl addedControl = null;
// Created control depends on form item interface type. Descendant
// interfaces checked first.
// If item is action.
if (items[i] instanceof IActionFormItem) {
// Item type casting.
IActionFormItem actionFormItem = (IActionFormItem) items[i];
// If controls must be small.
if (actionFormItem.getSize() == FormItemSize.Small) {
// Creating control.
ActionButtonControl ctrl = new ActionButtonControl(
this.parentWindow, actionFormItem.getAction(),
this.updateControlListenerer);
// Binding row to control.
ctrl.bind(dataRow, null);
addedControl = ctrl;
} else {
// Creating control.
ActionSliderControl ctrl = new ActionSliderControl(
this.parentWindow, actionFormItem.getAction(),
this.updateControlListenerer);
// Binding row to control.
ctrl.bind(dataRow, null);
addedControl = ctrl;
}
} else
// If item is selector.
if (items[i] instanceof ISelectorFormItem) {
// Interface type cast.
ISelectorFormItem item = (ISelectorFormItem) items[i];
// Creating control.
SelectorControl ctrl = new SelectorControl(this.parentWindow,
item.getSelector());
// Binding row and column to control.
ctrl.bind(dataRow, item.getShownColumn());
addedControl = ctrl;
} else
// If item is enumeration selector.
if (items[i] instanceof IEditEnumColumnFormItem) {
// Interface type cast.
IEditEnumColumnFormItem item = (IEditEnumColumnFormItem) items[i];
// Creating control.
EnumComboBoxDataControl ctrl = new EnumComboBoxDataControl(item
.getEnum());
// Binding row and column to control.
ctrl.bind(dataRow, item.getDataColumn());
addedControl = ctrl;
} else
// If this is range edit item.
if (items[i] instanceof IEditRangeFormItem) {
// Interface type cast.
IEditRangeFormItem item = (IEditRangeFormItem) items[i];
// Getting values for DB type detecting.
IDBValue valueLow = dataRow.getCell(item
.getLowBoundDataColumn());
IDBValue valueHigh = dataRow.getCell(item
.getHighBoundDataColumn());
// If this is date range.
if (valueLow instanceof DBDate && valueHigh instanceof DBDate) {
DateRangeControl ctrl = new DateRangeControl();
ctrl.bind(dataRow, item.getLowBoundDataColumn(), item
.getHighBoundDataColumn());
addedControl = ctrl;
}
// If this is floats range.
else if (valueLow instanceof DBFloat
&& valueHigh instanceof DBFloat) {
FloatRangeControl ctrl = new FloatRangeControl();
ctrl.bind(dataRow, item.getLowBoundDataColumn(), item
.getHighBoundDataColumn());
addedControl = ctrl;
}
// If this is time range.
else if (valueLow instanceof DBStringTime
&& valueHigh instanceof DBStringTime) {
TimeRangeControl ctrl = new TimeRangeControl();
ctrl.bind(dataRow, item.getLowBoundDataColumn(), item
.getHighBoundDataColumn());
addedControl = ctrl;
} else
throw new NotImplementedFeatureException(
"There is no implementation to edit range of types "
+ GWT.getTypeName(valueLow) + " and "
+ GWT.getTypeName(valueHigh) + ".");
} else
// If this is simple editable column.
if (items[i] instanceof IEditColumnFormItem) {
// Interface type cast.
IEditColumnFormItem item = (IEditColumnFormItem) items[i];
// Getting value for DB type detecting.
IDBValue value = dataRow.getCell(item.getDataColumn());
ISingleColumnBind ctrl = null;
// If this is multiline edited item.
if (item instanceof IMultilineEditFormItem
&& value instanceof DBString) {
ctrl = new TextAreaDataControl(
((IMultilineEditFormItem) item).getRowsCount());
} else {
// Creating control depending on retrieved value type.
if (value instanceof DBHTMLString)
ctrl = new RichTextAreaDataControl();
if (value instanceof DBString)
ctrl = new TextBoxDataControl();
else if (value instanceof DBInteger)
ctrl = new IntegerDataControl();
else if (value instanceof DBBoolean) {
if (item.isRequired())
ctrl = new BooleanDataControl();
else
ctrl = new BooleanComboBoxDataControl();
} else if (value instanceof DBBigInt)
ctrl = new IntegerDataControl();
else if (value instanceof DBDate)
ctrl = new CalendarDataControl();
else if (value instanceof DBStringTime)
ctrl = new TextBoxDataControl();
else if (value instanceof DBFloat)
ctrl = new FloatDataControl();
}
// Binding row and column to control.
ctrl.bind(dataRow, item.getDataColumn());
addedControl = (IBindableDataControl) ctrl;
}
// If this is read only information enumeration item.
else if (items[i] instanceof IInfoEnumColumnFormItem) {
// Creating control.
InfoDataControl ctrl = new InfoDataControl(
((IInfoEnumColumnFormItem) items[i]).getEnum());
// Binding row and column to control.
ctrl.bind(dataRow, ((IInfoFormItem) items[i]).getDataColumn());
addedControl = ctrl;
} else
// If this is read only information item.
if (items[i] instanceof IInfoFormItem) {
// Creating control.
InfoDataControl ctrl = new InfoDataControl();
// Binding row and column to control.
ctrl.bind(dataRow, ((IInfoFormItem) items[i]).getDataColumn());
addedControl = ctrl;
} else
// Throwing exception for unknown item type.
throw new NotImplementedFeatureException(
"Can't build control for type "
+ GWT.getTypeName(items[i]) + ".");
// Throwing exception if no control created.
if (addedControl == null)
throw new NullPointerException(
"Can`t find user control for item type "
+ GWT.getTypeName(items[i]) + ".");
// if control and item supports required staus.
if (items[i] instanceof IEditFormItem
&& addedControl instanceof IEditableDataControl)
((IEditableDataControl) addedControl)
.setRequired(((IEditFormItem) items[i]).isRequired());
// Check authorization for action controls.
if (addedControl instanceof ActionButtonControl) {
if (!((ActionButtonControl) addedControl).isAuth()) {
continue;
}
}
if (addedControl instanceof ActionSliderControl) {
if (!((ActionSliderControl) addedControl).isAuth()) {
continue;
}
}
// Adding controls to controls list.
controls.add(addedControl);
if (addedControl instanceof ActionSliderControl) {
this.slidersPanel.add((ActionSliderControl) addedControl);
} else {
// Resizing grid.
controlsGrid.resizeRows(controlsGrid.getRowCount() + 1);
// Adding item caption to firsh column.
HTML itemCaption = new HTML(items[i].getCaption());
itemCaption.setStyleName("pf-form-items-widget-item-caption");
controlsGrid.setWidget(controlsGrid.getRowCount() - 1, 0,
itemCaption);
// Adding created control to second column.
controlsGrid.setWidget(controlsGrid.getRowCount() - 1, 1,
(Widget) addedControl);
// Setting style.
controlsGrid.getRowFormatter().setStyleName(
controlsGrid.getRowCount() - 1,
"pf-form-items-widget-row");
}
// Adding keyboard listener.
if (addedControl instanceof SourcesKeyboardEvents)
((SourcesKeyboardEvents) addedControl)
.addKeyboardListener(keyboardListener);
// Reading data from row to control.
addedControl.readData();
}
}