use of com.vaadin.v7.data.Validator in project SORMAS-Project by hzi-braunschweig.
the class HospitalizationForm method addFields.
@SuppressWarnings("deprecation")
@Override
protected void addFields() {
if (caze == null || viewMode == null) {
return;
}
Label hospitalizationHeadingLabel = new Label(I18nProperties.getString(Strings.headingHospitalization));
hospitalizationHeadingLabel.addStyleName(H3);
getContent().addComponent(hospitalizationHeadingLabel, HOSPITALIZATION_HEADING_LOC);
Label previousHospitalizationsHeadingLabel = new Label(I18nProperties.getString(Strings.headingPreviousHospitalizations));
previousHospitalizationsHeadingLabel.addStyleName(H3);
getContent().addComponent(previousHospitalizationsHeadingLabel, PREVIOUS_HOSPITALIZATIONS_HEADING_LOC);
TextField facilityField = addCustomField(HEALTH_FACILITY, FacilityReferenceDto.class, TextField.class);
FacilityReferenceDto healthFacility = caze.getHealthFacility();
final boolean noneFacility = healthFacility == null || healthFacility.getUuid().equalsIgnoreCase(FacilityDto.NONE_FACILITY_UUID);
facilityField.setValue(noneFacility || !FacilityType.HOSPITAL.equals(caze.getFacilityType()) ? null : healthFacility.toString());
facilityField.setReadOnly(true);
final NullableOptionGroup admittedToHealthFacilityField = addField(HospitalizationDto.ADMITTED_TO_HEALTH_FACILITY, NullableOptionGroup.class);
final DateField admissionDateField = addField(HospitalizationDto.ADMISSION_DATE, DateField.class);
final DateField dischargeDateField = addDateField(HospitalizationDto.DISCHARGE_DATE, DateField.class, 7);
intensiveCareUnit = addField(HospitalizationDto.INTENSIVE_CARE_UNIT, NullableOptionGroup.class);
intensiveCareUnitStart = addField(HospitalizationDto.INTENSIVE_CARE_UNIT_START, DateField.class);
intensiveCareUnitStart.setVisible(false);
intensiveCareUnitEnd = addField(HospitalizationDto.INTENSIVE_CARE_UNIT_END, DateField.class);
intensiveCareUnitEnd.setVisible(false);
FieldHelper.setVisibleWhen(intensiveCareUnit, Arrays.asList(intensiveCareUnitStart, intensiveCareUnitEnd), Arrays.asList(YesNoUnknown.YES), true);
final Field isolationDateField = addField(HospitalizationDto.ISOLATION_DATE);
final TextArea descriptionField = addField(HospitalizationDto.DESCRIPTION, TextArea.class);
descriptionField.setRows(4);
final NullableOptionGroup isolatedField = addField(HospitalizationDto.ISOLATED, NullableOptionGroup.class);
final NullableOptionGroup leftAgainstAdviceField = addField(HospitalizationDto.LEFT_AGAINST_ADVICE, NullableOptionGroup.class);
final ComboBox hospitalizationReason = addField(HospitalizationDto.HOSPITALIZATION_REASON);
final TextField otherHospitalizationReason = addField(HospitalizationDto.OTHER_HOSPITALIZATION_REASON, TextField.class);
NullableOptionGroup hospitalizedPreviouslyField = addField(HospitalizationDto.HOSPITALIZED_PREVIOUSLY, NullableOptionGroup.class);
CssStyles.style(hospitalizedPreviouslyField, CssStyles.ERROR_COLOR_PRIMARY);
PreviousHospitalizationsField previousHospitalizationsField = addField(HospitalizationDto.PREVIOUS_HOSPITALIZATIONS, PreviousHospitalizationsField.class);
FieldHelper.setEnabledWhen(admittedToHealthFacilityField, Arrays.asList(YesNoUnknown.YES, YesNoUnknown.NO, YesNoUnknown.UNKNOWN), Arrays.asList(facilityField, admissionDateField, dischargeDateField, intensiveCareUnit, intensiveCareUnitStart, intensiveCareUnitEnd, isolationDateField, descriptionField, isolatedField, leftAgainstAdviceField, hospitalizationReason, otherHospitalizationReason), false);
initializeVisibilitiesAndAllowedVisibilities();
initializeAccessAndAllowedAccesses();
if (isVisibleAllowed(HospitalizationDto.ISOLATION_DATE)) {
FieldHelper.setVisibleWhen(getFieldGroup(), HospitalizationDto.ISOLATION_DATE, HospitalizationDto.ISOLATED, Arrays.asList(YesNoUnknown.YES), true);
}
if (isVisibleAllowed(HospitalizationDto.PREVIOUS_HOSPITALIZATIONS)) {
FieldHelper.setVisibleWhen(getFieldGroup(), HospitalizationDto.PREVIOUS_HOSPITALIZATIONS, HospitalizationDto.HOSPITALIZED_PREVIOUSLY, Arrays.asList(YesNoUnknown.YES), true);
}
FieldHelper.setVisibleWhen(getFieldGroup(), HospitalizationDto.OTHER_HOSPITALIZATION_REASON, HospitalizationDto.HOSPITALIZATION_REASON, Collections.singletonList(HospitalizationReasonType.OTHER), true);
// Validations
// Add a visual-only validator to check if symptomonsetdate<admissiondate, as saving should be possible either way
admissionDateField.addValueChangeListener(event -> {
if (caze.getSymptoms().getOnsetDate() != null && DateTimeComparator.getDateOnlyInstance().compare(admissionDateField.getValue(), caze.getSymptoms().getOnsetDate()) < 0) {
admissionDateField.setComponentError(new ErrorMessage() {
@Override
public ErrorLevel getErrorLevel() {
return ErrorLevel.INFO;
}
@Override
public String getFormattedHtmlMessage() {
return I18nProperties.getValidationError(Validations.afterDateSoft, admissionDateField.getCaption(), I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ONSET_DATE));
}
});
} else {
// remove all invalidity-indicators and re-evaluate field
admissionDateField.setComponentError(null);
admissionDateField.markAsDirty();
}
// re-evaluate validity of dischargeDate (necessary because discharge has to be after admission)
dischargeDateField.markAsDirty();
});
admissionDateField.addValidator(new DateComparisonValidator(admissionDateField, dischargeDateField, true, false, I18nProperties.getValidationError(Validations.beforeDate, admissionDateField.getCaption(), dischargeDateField.getCaption())));
dischargeDateField.addValidator(new DateComparisonValidator(dischargeDateField, admissionDateField, false, false, I18nProperties.getValidationError(Validations.afterDate, dischargeDateField.getCaption(), admissionDateField.getCaption())));
// re-evaluate admission date for consistent validation of all fields
dischargeDateField.addValueChangeListener(event -> admissionDateField.markAsDirty());
intensiveCareUnitStart.addValidator(new DateComparisonValidator(intensiveCareUnitStart, admissionDateField, false, false, I18nProperties.getValidationError(Validations.afterDate, intensiveCareUnitStart.getCaption(), admissionDateField.getCaption())));
intensiveCareUnitStart.addValidator(new DateComparisonValidator(intensiveCareUnitStart, intensiveCareUnitEnd, true, false, I18nProperties.getValidationError(Validations.beforeDate, intensiveCareUnitStart.getCaption(), intensiveCareUnitEnd.getCaption())));
intensiveCareUnitEnd.addValidator(new DateComparisonValidator(intensiveCareUnitEnd, intensiveCareUnitStart, false, false, I18nProperties.getValidationError(Validations.afterDate, intensiveCareUnitEnd.getCaption(), intensiveCareUnitStart.getCaption())));
intensiveCareUnitEnd.addValidator(new DateComparisonValidator(intensiveCareUnitEnd, dischargeDateField, true, false, I18nProperties.getValidationError(Validations.beforeDate, intensiveCareUnitEnd.getCaption(), dischargeDateField.getCaption())));
intensiveCareUnitStart.addValueChangeListener(event -> intensiveCareUnitEnd.markAsDirty());
intensiveCareUnitEnd.addValueChangeListener(event -> intensiveCareUnitStart.markAsDirty());
hospitalizedPreviouslyField.addValueChangeListener(e -> updatePrevHospHint(hospitalizedPreviouslyField, previousHospitalizationsField));
previousHospitalizationsField.addValueChangeListener(e -> updatePrevHospHint(hospitalizedPreviouslyField, previousHospitalizationsField));
}
use of com.vaadin.v7.data.Validator in project SORMAS-Project by hzi-braunschweig.
the class ResizableTextAreaWrapper method wrap.
@Override
public ComponentContainer wrap(T textField, String caption, boolean withMargin) {
this.textField = textField;
this.caption = caption;
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(false);
layout.setMargin(false);
layout.setWidth(100, Sizeable.Unit.PERCENTAGE);
if (withMargin) {
layout.addStyleName(CssStyles.FIELD_WRAPPER);
}
textField.setWidth(100, Sizeable.Unit.PERCENTAGE);
textField.addStyleName(CssStyles.RESIZABLE);
textField.setNullRepresentation("");
textField.setTextChangeTimeout(200);
Stream<Validator> maxLengthValidatorStream = textField.getValidators().stream().filter(v -> v instanceof MaxLengthValidator);
if (withMaxLength) {
maxLengthValidatorStream.findFirst().map(v -> ((MaxLengthValidator) v).getMaxLength()).ifPresent(textField::setMaxLength);
labelField = new Label(buildLabelMessage(textField.getValue(), textField, caption));
labelField.setId(textField.getId() + "_label");
labelField.setWidth(100, Sizeable.Unit.PERCENTAGE);
labelField.addStyleNames(CssStyles.ALIGN_RIGHT, CssStyles.FIELD_EXTRA_INFO, CssStyles.LABEL_ITALIC);
layout.addComponents(labelField);
} else {
maxLengthValidatorStream.iterator().forEachRemaining(v -> textField.removeValidator(v));
}
textField.addTextChangeListener(e -> {
updateTextfieldAppearance();
});
textField.addValueChangeListener(e -> {
updateTextfieldAppearance();
});
layout.addComponents(textField);
if (withMaxLength) {
layout.addComponents(labelField);
}
return layout;
}
use of com.vaadin.v7.data.Validator in project opencms-core by alkacon.
the class CmsEditSiteForm method setupValidatorAliase.
/**
* Setup for the aliase validator.<p>
*/
void setupValidatorAliase() {
for (I_CmsEditableGroupRow row : m_aliasGroup.getRows()) {
FormLayout layout = (FormLayout) (row.getComponent());
TextField field = (TextField) layout.getComponent(0);
field.removeAllValidators();
field.addValidator(new AliasValidator());
}
}
use of com.vaadin.v7.data.Validator in project opencms-core by alkacon.
the class CmsDbSynchronizationView method removeEmptyResourceFields.
/**
* Removes empty resource fields.<p>
*/
protected void removeEmptyResourceFields() {
Set<Component> componentsToRemove = new HashSet<Component>();
int count = 0;
Component lastElement = null;
for (Component c : m_resources) {
if (c instanceof CmsRemovableFormRow<?>) {
count++;
AbstractField<?> field = (AbstractField<?>) ((CmsRemovableFormRow) c).getInput();
String value = (String) (field.getValue());
if (value.isEmpty()) {
componentsToRemove.add(c);
lastElement = c;
}
}
}
// if all fields are empty -> keep one of them to attach validator to
if (componentsToRemove.size() == count) {
componentsToRemove.remove(lastElement);
}
if (count == 0) {
addResource("");
}
for (Component c : componentsToRemove) {
m_resources.removeComponent(c);
m_componentsToValidate.remove(c);
}
}
use of com.vaadin.v7.data.Validator in project SORMAS-Project by hzi-braunschweig.
the class PersonContactDetailEditForm method addFields.
@SuppressWarnings("deprecation")
@Override
protected void addFields() {
addField(PersonContactDetailDto.THIRD_PARTY, CheckBox.class).setCaption(I18nProperties.getCaption(Captions.personContactDetailThirdParty));
addField(PersonContactDetailDto.THIRD_PARTY_ROLE, TextField.class);
addField(PersonContactDetailDto.THIRD_PARTY_NAME, TextField.class);
addField(PersonContactDetailDto.PERSON_CONTACT_DETAILS_TYPE);
addField(PersonContactDetailDto.PHONE_NUMBER_TYPE);
addField(PersonContactDetailDto.DETAILS, TextField.class);
addField(PersonContactDetailDto.CONTACT_INFORMATION, TextField.class);
addField(PersonContactDetailDto.ADDITIONAL_INFORMATION, TextField.class);
addField(PersonContactDetailDto.PRIMARY_CONTACT, CheckBox.class);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(PersonContactDetailDto.THIRD_PARTY_ROLE, PersonContactDetailDto.THIRD_PARTY_NAME), PersonContactDetailDto.THIRD_PARTY, true, true);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(PersonContactDetailDto.DETAILS), PersonContactDetailDto.PERSON_CONTACT_DETAILS_TYPE, PersonContactDetailType.OTHER, false);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(PersonContactDetailDto.DETAILS), PersonContactDetailDto.PHONE_NUMBER_TYPE, PhoneNumberType.OTHER, false);
FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(PersonContactDetailDto.PHONE_NUMBER_TYPE), PersonContactDetailDto.PERSON_CONTACT_DETAILS_TYPE, PersonContactDetailType.PHONE, false);
addFieldListeners(PersonContactDetailDto.PERSON_CONTACT_DETAILS_TYPE, e -> {
final Field<?> contactInformationField = getFieldGroup().getField(PersonContactDetailDto.CONTACT_INFORMATION);
final PersonContactDetailType value = (PersonContactDetailType) e.getProperty().getValue();
for (Validator validator : contactInformationField.getValidators()) {
contactInformationField.removeValidator(validator);
}
if (value == PersonContactDetailType.PHONE) {
contactInformationField.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, contactInformationField.getCaption())));
} else if (value == PersonContactDetailType.EMAIL) {
contactInformationField.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, contactInformationField.getCaption())));
}
});
}
Aggregations