return new Constraint() {
@Override
public void validate(Component comp, Object value)
throws WrongValueException {
QualityFormItem item = (QualityFormItem) ((Row) comp
.getParent()).getValue();
BigDecimal newPercentage = (BigDecimal) value;
item.setPercentage(newPercentage);
if (newPercentage == null) {
item.setPercentage(null);
throw new WrongValueException(comp, _("cannot be empty"));
}
if (qualityFormModel
.checkConstraintOutOfRangeQualityFormItemPercentage(item)) {
item.setPercentage(null);
throw new WrongValueException(comp,
_("percentage should be between 1 and 100"));
}
if (!qualityFormModel
.checkConstraintUniqueQualityFormItemPercentage()) {
item.setPercentage(null);
throw new WrongValueException(comp,
_("percentage must be unique"));
}
}
};