Example usage for com.vaadin.v7.data Validator Validator

List of usage examples for com.vaadin.v7.data Validator Validator

Introduction

In this page you can find the example usage for com.vaadin.v7.data Validator Validator.

Prototype

Validator

Source Link

Usage

From source file:de.symeda.sormas.ui.symptoms.SymptomsForm.java

License:Open Source License

public void initializeSymptomRequirementsForVisit(OptionGroup visitStatus) {
    FieldHelper.addSoftRequiredStyleWhen(getFieldGroup(), visitStatus,
            Arrays.asList(SymptomsDto.TEMPERATURE, SymptomsDto.TEMPERATURE_SOURCE),
            Arrays.asList(VisitStatus.COOPERATIVE), disease);
    addSoftRequiredStyleWhenSymptomaticAndCooperative(getFieldGroup(), SymptomsDto.ONSET_DATE,
            unconditionalSymptomFieldIds, Arrays.asList(SymptomState.YES), visitStatus);
    addSoftRequiredStyleWhenSymptomaticAndCooperative(getFieldGroup(), SymptomsDto.ONSET_SYMPTOM,
            unconditionalSymptomFieldIds, Arrays.asList(SymptomState.YES), visitStatus);
    getFieldGroup().getField(SymptomsDto.FEVER).addValidator(new Validator() {
        @Override//  ww w. j a  v a 2s  .  c o m
        public void validate(Object value) throws InvalidValueException {
            if (getFieldGroup().getField(SymptomsDto.TEMPERATURE).getValue() != null) {
                if ((Float) (getFieldGroup().getField(SymptomsDto.TEMPERATURE).getValue()) >= 38.0f) {
                    if (value != SymptomState.YES) {
                        throw new InvalidValueException(
                                I18nProperties.getString(Strings.errorSetFeverRequired));
                    }
                }
            }
        }
    });
}

From source file:de.symeda.sormas.ui.symptoms.SymptomsForm.java

License:Open Source License

private void initializeSymptomRequirementsForClinicalVisit() {
    getFieldGroup().getField(SymptomsDto.FEVER).addValidator(new Validator() {
        @Override//  ww  w.  j  a  va  2  s .c om
        public void validate(Object value) throws InvalidValueException {
            if (getFieldGroup().getField(SymptomsDto.TEMPERATURE).getValue() != null) {
                if ((Float) (getFieldGroup().getField(SymptomsDto.TEMPERATURE).getValue()) >= 38.0f) {
                    if (value != SymptomState.YES) {
                        throw new InvalidValueException(
                                I18nProperties.getString(Strings.errorSetFeverRequired));
                    }
                }
            }
        }
    });
}

From source file:de.symeda.sormas.ui.visit.VisitEditForm.java

License:Open Source License

@Override
protected void addFields() {

    if (disease == null) {
        // workaround to stop initialization until disease is set 
        return;//from   www.j a  va 2s.co  m
    }

    addField(VisitDto.VISIT_DATE_TIME, DateTimeField.class);
    addField(VisitDto.VISIT_STATUS, OptionGroup.class);
    addField(VisitDto.VISIT_REMARKS, TextField.class);

    symptomsForm = new SymptomsForm(null, disease, person, SymptomsContext.VISIT, UserRight.VISIT_EDIT, null);
    getFieldGroup().bind(symptomsForm, VisitDto.SYMPTOMS);
    getContent().addComponent(symptomsForm, VisitDto.SYMPTOMS);

    setRequired(true, VisitDto.VISIT_DATE_TIME, VisitDto.VISIT_STATUS);

    if (contact != null) {
        getField(VisitDto.VISIT_DATE_TIME).addValidator(new Validator() {
            @Override
            public void validate(Object value) throws InvalidValueException {
                Date visitDateTime = (Date) getFieldGroup().getField(VisitDto.VISIT_DATE_TIME).getValue();
                Date contactReferenceDate = contact.getLastContactDate() != null ? contact.getLastContactDate()
                        : contact.getReportDateTime();
                if (visitDateTime.before(contactReferenceDate) && DateHelper.getDaysBetween(visitDateTime,
                        contactReferenceDate) > VisitDto.ALLOWED_CONTACT_DATE_OFFSET) {
                    if (contact.getLastContactDate() != null) {
                        throw new InvalidValueException(I18nProperties.getValidationError(
                                Validations.visitBeforeLastContactDate, VisitDto.ALLOWED_CONTACT_DATE_OFFSET));
                    } else {
                        throw new InvalidValueException(I18nProperties.getValidationError(
                                Validations.visitBeforeContactReport, VisitDto.ALLOWED_CONTACT_DATE_OFFSET));
                    }
                }
                if (contact.getFollowUpUntil() != null && visitDateTime.after(contact.getFollowUpUntil())
                        && DateHelper.getDaysBetween(contact.getFollowUpUntil(),
                                visitDateTime) > VisitDto.ALLOWED_CONTACT_DATE_OFFSET) {
                    throw new InvalidValueException(I18nProperties.getValidationError(
                            Validations.visitAfterFollowUp, VisitDto.ALLOWED_CONTACT_DATE_OFFSET));
                }
            }
        });
    }

    symptomsForm.initializeSymptomRequirementsForVisit(
            (OptionGroup) getFieldGroup().getField(VisitDto.VISIT_STATUS));
}

From source file:org.jpos.qi.components.BigDecimalField.java

License:Open Source License

private Validator getValidator() {
    return new Validator() {
        private boolean isValid(Object value) {
            try {
                if (value != null && !((String) value).isEmpty()) {
                    new BigDecimal((String) value);
                }//from w  w w . ja  va2  s . co  m
                return true;
            } catch (NumberFormatException e) {
                return false;
            }
        }

        @Override
        public void validate(Object value) throws com.vaadin.v7.data.Validator.InvalidValueException {
            if (!isValid(value)) {
                throw new Validator.InvalidValueException(
                        QI.getQI().getMessage("errorMessage.NaN", getCaption()));
            }
        }
    };
}