/**
* Validates the control's contents.
* @return the validation status
*/
public ValidationStatus validate() {
ValidationStatus status = OK_STATUS;
String errorMessage = null;
String hoursText = hoursTextField.getText().trim();
String minutesText = minutesTextField.getText().trim();
String secondsText = secondsTextField.getText().trim();
// Only process the time if a time has been entered.
if (hoursText.length() > 0 ||
minutesText.length() > 0 ||
secondsText.length() > 0) {
hoursText = hoursText.length() == 0 ? TWO_LEADING_ZEROES : hoursText;
minutesText =
minutesText.length() == 0 ? TWO_LEADING_ZEROES : minutesText;
secondsText =
secondsText.length() == 0 ? TWO_LEADING_ZEROES : secondsText;
status = hoursValidator.validate(hoursText);
if (status.isOK()) {
status = minutesValidator.validate(minutesText);
if (status.isOK()) {
status = secondsValidator.validate(secondsText);
if (!status.isOK()) {
errorMessage = validationMessageBuilder.
buildValidationMessage("invalidSecond",
null, new String[]{secondsText});
}
} else {
errorMessage = validationMessageBuilder.
buildValidationMessage("invalidMinute",
null, new String[]{minutesText});
}
} else {
errorMessage = validationMessageBuilder.
buildValidationMessage("invalidHour",
null, new String[]{hoursText});
}
if (status.isOK() && !(isNonZero(hoursText) ||
isNonZero(minutesText) ||
isNonZero(secondsText))) {
errorMessage = validationMessageBuilder.
buildValidationMessage("zeroTime", null, null);
}
if (errorMessage != null) {
status =new ValidationStatus(ValidationStatus.ERROR, errorMessage);
}
}
return status;
}