int unitCount = unitModel.getUnitCount();
Field[] unitFields = new Field[unitCount];
for (int i = 0; i < unitCount; i++) {
final int unitNumber = unitModel.getUnitNumber(i);
String unitName = unitModel.getUnitName(i);
UnitControl unitCondition = (unitModel.getUnitCondition(i) != UnitControl.OFF) ? UnitControl.ON : UnitControl.OFF;
EnumLabel unitConditionLabel = EnumLabel.getEnumLabel(UNIT_CONDITIONS, unitCondition);
Execution exec = new Execution() {
public boolean execute(Object selection) {
UnitControl selectedUnitCondition = (UnitControl) ((EnumLabel) selection).getEnumValue();
return unitModel.setUnitControl(unitNumber, selectedUnitCondition);
}
};
Field unitField = createLabelAndChoiceField(MessageFormat.format(OmniLinkBBClient.getString(OmniLinkClientResource.UNIT_NAME), new Object[] {new Integer(unitNumber), unitName}), UNIT_CONDITIONS, unitConditionLabel, exec);
unitFields[i] = unitField;