/**
 *
 */
package com.rjconsultores.ventaboletos.web.utilerias;

import java.math.BigDecimal;

import org.zkoss.util.resource.Labels;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Constraint;

/**
 * @author Thiago
 *
 */
public class ConstraintPorcentagemAllowNull implements Constraint {

	@Override
	public void validate(Component comp, Object value) throws WrongValueException {
		if (value != null) {
			if (((BigDecimal) value).doubleValue() > 100) {
				throw new WrongValueException(comp,
						Labels.getLabel("MSG.CONSTRAINT.PORCENTAGEM"));
			} else if (((BigDecimal) value).doubleValue() < 0) {
				throw new WrongValueException(comp,
						Labels.getLabel("MSG.CONSTRAINT.PORCENTAGEM"));
			}
		}
	}

}
