Search in sources :

Example 11 with Field

use of com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.

the class CaseFilterForm method addMoreFilters.

public void addMoreFilters(CustomLayout moreFiltersContainer) {
    ComboBox presentConditionField = addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseCriteria.PRESENT_CONDITION, 140));
    presentConditionField.setInputPrompt(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.PRESENT_CONDITION));
    UserDto user = currentUserDto();
    ComboBox regionField = null;
    if (user.getRegion() == null) {
        regionField = addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseDataDto.REGION, 140));
        regionField.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    }
    ComboBox districtField = addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseDataDto.DISTRICT, 140));
    districtField.setDescription(I18nProperties.getDescription(Descriptions.descDistrictFilter));
    addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseDataDto.COMMUNITY, 140));
    if (!UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
        ComboBox typeGroup = addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseCriteria.FACILITY_TYPE_GROUP, 140));
        typeGroup.setInputPrompt(I18nProperties.getCaption(Captions.Facility_typeGroup));
        typeGroup.removeAllItems();
        FieldHelper.updateEnumData(typeGroup, FacilityTypeGroup.getAccomodationGroups());
        ComboBox type = addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseCriteria.FACILITY_TYPE, 140));
        type.setInputPrompt(I18nProperties.getPrefixCaption(FacilityDto.I18N_PREFIX, FacilityDto.TYPE));
        type.removeAllItems();
        ComboBox facilityField = addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseDataDto.HEALTH_FACILITY, 140));
        facilityField.setDescription(I18nProperties.getDescription(Descriptions.descFacilityFilter));
    }
    if (UserProvider.getCurrent().hasUserRight(UserRight.PORT_HEALTH_INFO_VIEW)) {
        ComboBox pointOfEntryField = addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseDataDto.POINT_OF_ENTRY, 140));
        pointOfEntryField.setDescription(I18nProperties.getDescription(Descriptions.descPointOfEntryFilter));
    }
    ComboBox officerField = addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseDataDto.SURVEILLANCE_OFFICER, 140));
    Disease selectedDisease = (Disease) getField(CaseIndexDto.DISEASE).getValue();
    officerField.addItems(FacadeProvider.getUserFacade().getUsersByRegionAndRights(user.getRegion(), selectedDisease, UserRight.CASE_RESPONSIBLE));
    if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.CASE_FOLLOWUP)) {
        Field<?> followUpUntilTo = addField(moreFiltersContainer, FieldConfiguration.withCaptionAndPixelSized(CaseCriteria.FOLLOW_UP_UNTIL_TO, I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.FOLLOW_UP_UNTIL), 200));
        followUpUntilTo.removeAllValidators();
        addField(moreFiltersContainer, FieldConfiguration.withCaptionAndPixelSized(CaseCriteria.SYMPTOM_JOURNAL_STATUS, I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.SYMPTOM_JOURNAL_STATUS), 240));
    }
    addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseCriteria.VACCINATION_STATUS, 140));
    if (isConfiguredServer(CountryHelper.COUNTRY_CODE_GERMANY)) {
        addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseCriteria.REINFECTION_STATUS, 140));
    }
    addField(moreFiltersContainer, FieldConfiguration.withCaptionAndPixelSized(CaseCriteria.REPORTING_USER_ROLE, I18nProperties.getString(Strings.reportedBy), 140));
    TextField reportingUserField = addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseCriteria.REPORTING_USER_LIKE, 200));
    reportingUserField.setNullRepresentation("");
    reportingUserField.setInputPrompt(I18nProperties.getPrefixCaption(propertyI18nPrefix, CaseDataDto.REPORTING_USER));
    addField(moreFiltersContainer, FieldConfiguration.withCaptionAndPixelSized(CaseCriteria.QUARANTINE_TYPE, I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.QUARANTINE), 200));
    Field<?> quarantineTo = addField(moreFiltersContainer, FieldConfiguration.pixelSized(CaseDataDto.QUARANTINE_TO, 200));
    quarantineTo.removeAllValidators();
    ComboBox birthDateYYYY = addField(moreFiltersContainer, CaseCriteria.BIRTHDATE_YYYY, ComboBox.class);
    birthDateYYYY.setInputPrompt(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE_YYYY));
    birthDateYYYY.setWidth(140, Unit.PIXELS);
    birthDateYYYY.addItems(DateHelper.getYearsToNow());
    birthDateYYYY.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID_TOSTRING);
    ComboBox birthDateMM = addField(moreFiltersContainer, CaseCriteria.BIRTHDATE_MM, ComboBox.class);
    birthDateMM.setInputPrompt(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE_MM));
    birthDateMM.setWidth(140, Unit.PIXELS);
    birthDateMM.addItems(DateHelper.getMonthsInYear());
    ComboBox birthDateDD = addField(moreFiltersContainer, CaseCriteria.BIRTHDATE_DD, ComboBox.class);
    birthDateDD.setInputPrompt(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE_DD));
    birthDateDD.setWidth(140, Unit.PIXELS);
    addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.MUST_HAVE_NO_GEO_COORDINATES, I18nProperties.getCaption(Captions.caseFilterWithoutGeo), I18nProperties.getDescription(Descriptions.descCaseFilterWithoutGeo), CssStyles.CHECKBOX_FILTER_INLINE));
    if (UserProvider.getCurrent().hasUserRight(UserRight.PORT_HEALTH_INFO_VIEW)) {
        addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.MUST_BE_PORT_HEALTH_CASE_WITHOUT_FACILITY, I18nProperties.getCaption(Captions.caseFilterPortHealthWithoutFacility), I18nProperties.getDescription(Descriptions.descCaseFilterPortHealthWithoutFacility), CssStyles.CHECKBOX_FILTER_INLINE));
    }
    if (UserProvider.getCurrent().hasUserRight(UserRight.CLINICAL_COURSE_VIEW) || UserProvider.getCurrent().hasUserRight(UserRight.THERAPY_VIEW)) {
        addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.MUST_HAVE_CASE_MANAGEMENT_DATA, I18nProperties.getCaption(Captions.caseFilterCasesWithCaseManagementData), I18nProperties.getDescription(Descriptions.descCaseFilterCasesWithCaseManagementData), CssStyles.CHECKBOX_FILTER_INLINE));
    }
    addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.WITHOUT_RESPONSIBLE_OFFICER, I18nProperties.getCaption(Captions.caseFilterWithoutResponsibleUser), I18nProperties.getDescription(Descriptions.descCaseFilterWithoutResponsibleUser), CssStyles.CHECKBOX_FILTER_INLINE));
    addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.WITH_EXTENDED_QUARANTINE, I18nProperties.getCaption(Captions.caseFilterWithExtendedQuarantine), I18nProperties.getDescription(Descriptions.descCaseFilterWithExtendedQuarantine), CssStyles.CHECKBOX_FILTER_INLINE));
    addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.WITH_REDUCED_QUARANTINE, I18nProperties.getCaption(Captions.caseFilterWithReducedQuarantine), I18nProperties.getDescription(Descriptions.descCaseFilterWithReducedQuarantine), CssStyles.CHECKBOX_FILTER_INLINE));
    addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.ONLY_QUARANTINE_HELP_NEEDED, I18nProperties.getCaption(Captions.caseFilterOnlyQuarantineHelpNeeded), null, CssStyles.CHECKBOX_FILTER_INLINE));
    addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.ONLY_CASES_WITH_EVENTS, I18nProperties.getCaption(Captions.caseFilterRelatedToEvent), I18nProperties.getDescription(Descriptions.descCaseFilterRelatedToEvent), CssStyles.CHECKBOX_FILTER_INLINE));
    addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.ONLY_CONTACTS_FROM_OTHER_INSTANCES, I18nProperties.getCaption(Captions.caseFilterOnlyFromOtherInstances), I18nProperties.getDescription(Descriptions.descCaseFilterOnlyFromOtherInstances), CssStyles.CHECKBOX_FILTER_INLINE));
    if (isConfiguredServer(CountryHelper.COUNTRY_CODE_GERMANY)) {
        addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.ONLY_CASES_WITH_REINFECTION, I18nProperties.getCaption(Captions.caseFilterCasesWithReinfection), I18nProperties.getDescription(Descriptions.descCaseFilterCasesWithReinfection), CssStyles.CHECKBOX_FILTER_INLINE));
        addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.ONLY_SHOW_CASES_WITH_FULFILLED_REFERENCE_DEFINITION, I18nProperties.getCaption(Captions.caseFilterOnlyCasesWithFulfilledReferenceDefinition), I18nProperties.getDescription(Descriptions.descCaseFilterOnlyCasesWithFulfilledReferenceDefinition), CssStyles.CHECKBOX_FILTER_INLINE));
    }
    final JurisdictionLevel userJurisdictionLevel = UserRole.getJurisdictionLevel(UserProvider.getCurrent().getUserRoles());
    if (userJurisdictionLevel != JurisdictionLevel.NATION && userJurisdictionLevel != JurisdictionLevel.NONE) {
        addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.INCLUDE_CASES_FROM_OTHER_JURISDICTIONS, I18nProperties.getCaption(Captions.caseFilterInludeCasesFromOtherJurisdictions), I18nProperties.getDescription(Descriptions.descCaseFilterIncludeCasesFromOtherJurisdictions), CssStyles.CHECKBOX_FILTER_INLINE));
    }
    boolean isExternalShareEnabled = FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled();
    if (isExternalShareEnabled) {
        addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.ONLY_ENTITIES_NOT_SHARED_WITH_EXTERNAL_SURV_TOOL, I18nProperties.getCaption(Captions.caseFilterOnlyCasesNotSharedWithExternalSurvTool), null, CssStyles.CHECKBOX_FILTER_INLINE));
        addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.ONLY_ENTITIES_SHARED_WITH_EXTERNAL_SURV_TOOL, I18nProperties.getCaption(Captions.caseFilterOnlyCasesSharedWithExternalSurvToo), null, CssStyles.CHECKBOX_FILTER_INLINE));
        addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.ONLY_ENTITIES_CHANGED_SINCE_LAST_SHARED_WITH_EXTERNAL_SURV_TOOL, I18nProperties.getCaption(Captions.caseFilterOnlyCasesChangedSinceLastSharedWithExternalSurvTool), null, CssStyles.CHECKBOX_FILTER_INLINE));
        addField(moreFiltersContainer, CheckBox.class, FieldConfiguration.withCaptionAndStyle(CaseCriteria.ONLY_CASES_WITH_DONT_SHARE_WITH_EXTERNAL_SURV_TOOL, I18nProperties.getCaption(Captions.caseFilterOnlyCasesWithDontShareWithExternalSurvTool), null, CssStyles.CHECKBOX_FILTER_INLINE));
    }
    moreFiltersContainer.addComponent(buildWeekAndDateFilter(isExternalShareEnabled), WEEK_AND_DATE_FILTER);
}
Also used : Disease(de.symeda.sormas.api.Disease) ComboBox(com.vaadin.v7.ui.ComboBox) UserDto(de.symeda.sormas.api.user.UserDto) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) TextField(com.vaadin.v7.ui.TextField)

Example 12 with Field

use of com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.

the class PersonEditForm method addFields.

@Override
protected void addFields() {
    personInformationHeadingLabel = new Label(I18nProperties.getString(Strings.headingPersonInformation));
    personInformationHeadingLabel.addStyleName(H3);
    getContent().addComponent(personInformationHeadingLabel, PERSON_INFORMATION_HEADING_LOC);
    addField(PersonDto.UUID).setReadOnly(true);
    firstNameField = addField(PersonDto.FIRST_NAME, TextField.class);
    lastNameField = addField(PersonDto.LAST_NAME, TextField.class);
    addFields(PersonDto.SALUTATION, PersonDto.OTHER_SALUTATION);
    FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.OTHER_SALUTATION, PersonDto.SALUTATION, Salutation.OTHER, true);
    ComboBox sex = addField(PersonDto.SEX, ComboBox.class);
    addField(PersonDto.BIRTH_NAME, TextField.class);
    addField(PersonDto.NICKNAME, TextField.class);
    addField(PersonDto.MOTHERS_MAIDEN_NAME, TextField.class);
    addFields(PersonDto.MOTHERS_NAME, PersonDto.FATHERS_NAME);
    addFields(PersonDto.NAMES_OF_GUARDIANS);
    ComboBox presentCondition = addField(PersonDto.PRESENT_CONDITION, ComboBox.class);
    birthDateDay = addField(PersonDto.BIRTH_DATE_DD, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateDay.setNullSelectionAllowed(true);
    birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
    birthDateDay.setCaption("");
    ComboBox birthDateMonth = addField(PersonDto.BIRTH_DATE_MM, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateMonth.setNullSelectionAllowed(true);
    birthDateMonth.addItems(DateHelper.getMonthsInYear());
    birthDateMonth.setPageLength(12);
    birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
    birthDateMonth.setCaption("");
    setItemCaptionsForMonths(birthDateMonth);
    ComboBox birthDateYear = addField(PersonDto.BIRTH_DATE_YYYY, ComboBox.class);
    birthDateYear.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE));
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateYear.setNullSelectionAllowed(true);
    birthDateYear.addItems(DateHelper.getYearsToNow());
    birthDateYear.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
    birthDateYear.setInputPrompt(I18nProperties.getString(Strings.year));
    birthDateDay.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) birthDateMonth.getValue(), (Integer) e));
    birthDateMonth.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) e, (Integer) birthDateDay.getValue()));
    birthDateYear.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) e, (Integer) birthDateMonth.getValue(), (Integer) birthDateDay.getValue()));
    DateField deathDate = addField(PersonDto.DEATH_DATE, DateField.class);
    TextField approximateAgeField = addField(PersonDto.APPROXIMATE_AGE, TextField.class);
    approximateAgeField.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, approximateAgeField.getCaption()));
    ComboBox approximateAgeTypeField = addField(PersonDto.APPROXIMATE_AGE_TYPE, ComboBox.class);
    addField(PersonDto.APPROXIMATE_AGE_REFERENCE_DATE, DateField.class);
    approximateAgeField.addValidator(new ApproximateAgeValidator(approximateAgeField, approximateAgeTypeField, I18nProperties.getValidationError(Validations.softApproximateAgeTooHigh)));
    TextField tfGestationAgeAtBirth = addField(PersonDto.GESTATION_AGE_AT_BIRTH, TextField.class);
    tfGestationAgeAtBirth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfGestationAgeAtBirth.getCaption()));
    TextField tfBirthWeight = addField(PersonDto.BIRTH_WEIGHT, TextField.class);
    tfBirthWeight.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfBirthWeight.getCaption()));
    AbstractSelect deathPlaceType = addField(PersonDto.DEATH_PLACE_TYPE, ComboBox.class);
    deathPlaceType.setNullSelectionAllowed(true);
    TextField deathPlaceDesc = addField(PersonDto.DEATH_PLACE_DESCRIPTION, TextField.class);
    DateField burialDate = addField(PersonDto.BURIAL_DATE, DateField.class);
    TextField burialPlaceDesc = addField(PersonDto.BURIAL_PLACE_DESCRIPTION, TextField.class);
    ComboBox burialConductor = addField(PersonDto.BURIAL_CONDUCTOR, ComboBox.class);
    addressForm = addField(PersonDto.ADDRESS, LocationEditForm.class);
    addressForm.setCaption(null);
    addField(PersonDto.ADDRESSES, LocationsField.class).setCaption(null);
    PersonContactDetailsField personContactDetailsField = addField(PersonDto.PERSON_CONTACT_DETAILS, PersonContactDetailsField.class);
    personContactDetailsField.setThisPerson(getValue());
    personContactDetailsField.setCaption(null);
    personContactDetailsField.setPseudonymized(isPseudonymized);
    addFields(PersonDto.OCCUPATION_TYPE, PersonDto.OCCUPATION_DETAILS, PersonDto.ARMED_FORCES_RELATION_TYPE, PersonDto.EDUCATION_TYPE, PersonDto.EDUCATION_DETAILS);
    List<CountryReferenceDto> countries = FacadeProvider.getCountryFacade().getAllActiveAsReference();
    addInfrastructureField(PersonDto.BIRTH_COUNTRY).addItems(countries);
    addInfrastructureField(PersonDto.CITIZENSHIP).addItems(countries);
    addFields(PersonDto.PASSPORT_NUMBER, PersonDto.NATIONAL_HEALTH_ID);
    Field externalId = addField(PersonDto.EXTERNAL_ID);
    if (FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled()) {
        externalId.setEnabled(false);
    }
    TextField externalTokenField = addField(PersonDto.EXTERNAL_TOKEN);
    Label externalTokenWarningLabel = new Label(I18nProperties.getString(Strings.messagePersonExternalTokenWarning));
    externalTokenWarningLabel.addStyleNames(VSPACE_3, LABEL_WHITE_SPACE_NORMAL);
    getContent().addComponent(externalTokenWarningLabel, EXTERNAL_TOKEN_WARNING_LOC);
    addField(PersonDto.INTERNAL_TOKEN);
    addField(PersonDto.HAS_COVID_APP).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
    addField(PersonDto.COVID_CODE_DELIVERED).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
    if (personContext != PersonContext.CASE) {
        setVisible(false, PersonDto.HAS_COVID_APP, PersonDto.COVID_CODE_DELIVERED);
    }
    ComboBox cbPlaceOfBirthRegion = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_REGION);
    ComboBox cbPlaceOfBirthDistrict = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_DISTRICT);
    ComboBox cbPlaceOfBirthCommunity = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_COMMUNITY);
    ComboBox placeOfBirthFacilityType = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_TYPE);
    FieldHelper.removeItems(placeOfBirthFacilityType);
    placeOfBirthFacilityType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
    placeOfBirthFacilityType.addItems(FacilityType.getPlaceOfBirthTypes());
    cbPlaceOfBirthFacility = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_FACILITY);
    TextField tfPlaceOfBirthFacilityDetails = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_DETAILS, TextField.class);
    causeOfDeathField = addField(PersonDto.CAUSE_OF_DEATH, ComboBox.class);
    causeOfDeathDiseaseField = addDiseaseField(PersonDto.CAUSE_OF_DEATH_DISEASE, true);
    causeOfDeathDetailsField = addField(PersonDto.CAUSE_OF_DEATH_DETAILS, TextField.class);
    // Set requirements that don't need visibility changes and read only status
    setReadOnly(true, PersonDto.APPROXIMATE_AGE_REFERENCE_DATE);
    setRequired(true, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX);
    setVisible(false, PersonDto.OCCUPATION_DETAILS, PersonDto.DEATH_DATE, PersonDto.DEATH_PLACE_TYPE, PersonDto.DEATH_PLACE_DESCRIPTION, PersonDto.BURIAL_DATE, PersonDto.BURIAL_PLACE_DESCRIPTION, PersonDto.BURIAL_CONDUCTOR, PersonDto.CAUSE_OF_DEATH, PersonDto.CAUSE_OF_DEATH_DETAILS, PersonDto.CAUSE_OF_DEATH_DISEASE);
    FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.EDUCATION_DETAILS, PersonDto.EDUCATION_TYPE, Arrays.asList(EducationType.OTHER), true);
    FieldHelper.addSoftRequiredStyle(presentCondition, sex, deathDate, deathPlaceDesc, deathPlaceType, causeOfDeathField, causeOfDeathDiseaseField, causeOfDeathDetailsField, burialDate, burialPlaceDesc, burialConductor);
    // Set initial visibilities
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    if (!getField(PersonDto.OCCUPATION_TYPE).isVisible() && !getField(PersonDto.ARMED_FORCES_RELATION_TYPE).isVisible() && !getField(PersonDto.EDUCATION_TYPE).isVisible())
        occupationHeader.setVisible(false);
    if (!getField(PersonDto.ADDRESS).isVisible())
        addressHeader.setVisible(false);
    if (!getField(PersonDto.ADDRESSES).isVisible())
        addressesHeader.setVisible(false);
    // Add listeners
    FieldHelper.setRequiredWhenNotNull(getFieldGroup(), PersonDto.APPROXIMATE_AGE, PersonDto.APPROXIMATE_AGE_TYPE);
    addFieldListeners(PersonDto.APPROXIMATE_AGE, e -> {
        @SuppressWarnings("unchecked") Field<ApproximateAgeType> ageTypeField = (Field<ApproximateAgeType>) getField(PersonDto.APPROXIMATE_AGE_TYPE);
        if (!ageTypeField.isReadOnly()) {
            if (e.getProperty().getValue() == null) {
                ageTypeField.clear();
            } else {
                if (ageTypeField.isEmpty()) {
                    ageTypeField.setValue(ApproximateAgeType.YEARS);
                }
            }
        }
    });
    addFieldListeners(PersonDto.BIRTH_DATE_DD, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });
    addFieldListeners(PersonDto.BIRTH_DATE_MM, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });
    addFieldListeners(PersonDto.BIRTH_DATE_YYYY, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });
    addFieldListeners(PersonDto.DEATH_DATE, e -> updateApproximateAge());
    addFieldListeners(PersonDto.OCCUPATION_TYPE, e -> {
        updateOccupationFieldCaptions();
        toggleOccupationMetaFields();
    });
    addListenersToInfrastructureFields(cbPlaceOfBirthRegion, cbPlaceOfBirthDistrict, cbPlaceOfBirthCommunity, placeOfBirthFacilityType, cbPlaceOfBirthFacility, tfPlaceOfBirthFacilityDetails, true);
    cbPlaceOfBirthRegion.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    this.presentConditionChangeListener = new PresentConditionChangeListener();
    addFieldListeners(PersonDto.PRESENT_CONDITION, presentConditionChangeListener);
    causeOfDeathField.addValueChangeListener(e -> {
        boolean causeOfDeathVisible = presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != PresentCondition.UNKNOWN && presentCondition.getValue() != null;
        toggleCauseOfDeathFields(causeOfDeathVisible);
    });
    causeOfDeathDiseaseField.addValueChangeListener(e -> {
        boolean causeOfDeathVisible = presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != PresentCondition.UNKNOWN && presentCondition.getValue() != null;
        toggleCauseOfDeathFields(causeOfDeathVisible);
    });
    addValueChangeListener(e -> fillDeathAndBurialFields(deathPlaceType, deathPlaceDesc, burialPlaceDesc));
    deathDate.addValidator(new DateComparisonValidator(deathDate, this::calcBirthDateValue, false, false, I18nProperties.getValidationError(Validations.afterDate, deathDate.getCaption(), birthDateYear.getCaption())));
    deathDate.addValidator(new DateComparisonValidator(deathDate, burialDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, deathDate.getCaption(), burialDate.getCaption())));
    deathDate.addValueChangeListener(value -> {
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    burialDate.addValidator(new DateComparisonValidator(burialDate, this::calcBirthDateValue, false, false, I18nProperties.getValidationError(Validations.afterDate, burialDate.getCaption(), birthDateYear.getCaption())));
    burialDate.addValidator(new DateComparisonValidator(burialDate, deathDate, false, false, I18nProperties.getValidationError(Validations.afterDate, burialDate.getCaption(), deathDate.getCaption())));
    burialDate.addValueChangeListener(b -> {
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    // Update the list of days according to the selected month and year
    birthDateYear.addValueChangeListener(e -> {
        updateListOfDays((Integer) e.getProperty().getValue(), (Integer) birthDateMonth.getValue());
        birthDateMonth.markAsDirty();
        birthDateDay.markAsDirty();
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    birthDateMonth.addValueChangeListener(e -> {
        updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
        birthDateYear.markAsDirty();
        birthDateDay.markAsDirty();
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    birthDateDay.addValueChangeListener(e -> {
        birthDateYear.markAsDirty();
        birthDateMonth.markAsDirty();
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    addValueChangeListener((e) -> {
        ValidationUtils.initComponentErrorValidator(externalTokenField, getValue().getExternalToken(), Validations.duplicateExternalToken, externalTokenWarningLabel, (externalToken) -> FacadeProvider.getPersonFacade().doesExternalTokenExist(externalToken, getValue().getUuid()));
        personContactDetailsField.setThisPerson((PersonDto) e.getProperty().getValue());
    });
    Label generalCommentLabel = new Label(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS));
    generalCommentLabel.addStyleName(H3);
    getContent().addComponent(generalCommentLabel, GENERAL_COMMENT_LOC);
    TextArea additionalDetails = addField(PersonDto.ADDITIONAL_DETAILS, TextArea.class, new ResizableTextAreaWrapper<>(false));
    additionalDetails.setRows(6);
    additionalDetails.setDescription(I18nProperties.getPrefixDescription(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    CssStyles.style(additionalDetails, CssStyles.CAPTION_HIDDEN);
}
Also used : TextArea(com.vaadin.v7.ui.TextArea) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) ApproximateAgeValidator(de.symeda.sormas.ui.utils.ApproximateAgeValidator)

Example 13 with Field

use of com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.

the class AbstractSampleForm method addValidators.

protected void addValidators() {
    // Validators
    final DateTimeField sampleDateField = (DateTimeField) getField(SampleDto.SAMPLE_DATE_TIME);
    final DateField shipmentDate = (DateField) getField(SampleDto.SHIPMENT_DATE);
    final DateField receivedDate = (DateField) getField(SampleDto.RECEIVED_DATE);
    sampleDateField.addValidator(new DateComparisonValidator(sampleDateField, shipmentDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, sampleDateField.getCaption(), shipmentDate.getCaption())));
    sampleDateField.addValidator(new DateComparisonValidator(sampleDateField, receivedDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, sampleDateField.getCaption(), receivedDate.getCaption())));
    shipmentDate.addValidator(new DateComparisonValidator(shipmentDate, sampleDateField, false, false, I18nProperties.getValidationError(Validations.afterDate, shipmentDate.getCaption(), sampleDateField.getCaption())));
    shipmentDate.addValidator(new DateComparisonValidator(shipmentDate, receivedDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, shipmentDate.getCaption(), receivedDate.getCaption())));
    receivedDate.addValidator(new DateComparisonValidator(receivedDate, sampleDateField, false, false, I18nProperties.getValidationError(Validations.afterDate, receivedDate.getCaption(), sampleDateField.getCaption())));
    receivedDate.addValidator(new DateComparisonValidator(receivedDate, shipmentDate, false, false, I18nProperties.getValidationError(Validations.afterDate, receivedDate.getCaption(), shipmentDate.getCaption())));
    List<AbstractField<Date>> validatedFields = Arrays.asList(sampleDateField, shipmentDate, receivedDate);
    validatedFields.forEach(field -> field.addValueChangeListener(r -> {
        validatedFields.forEach(otherField -> {
            otherField.setValidationVisible(!otherField.isValid());
        });
    }));
}
Also used : FeatureType(de.symeda.sormas.api.feature.FeatureType) AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) Arrays(java.util.Arrays) AbstractField(com.vaadin.v7.ui.AbstractField) Date(java.util.Date) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) SpecimenCondition(de.symeda.sormas.api.sample.SpecimenCondition) HSPACE_RIGHT_4(de.symeda.sormas.ui.utils.CssStyles.HSPACE_RIGHT_4) CssStyles(de.symeda.sormas.ui.utils.CssStyles) VSPACE_4(de.symeda.sormas.ui.utils.CssStyles.VSPACE_4) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) UserProvider(de.symeda.sormas.ui.UserProvider) Property(com.vaadin.v7.data.Property) ComboBox(com.vaadin.v7.ui.ComboBox) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) List(java.util.List) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) TextField(com.vaadin.v7.ui.TextField) Descriptions(de.symeda.sormas.api.i18n.Descriptions) AdditionalTestType(de.symeda.sormas.api.sample.AdditionalTestType) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) VSPACE_TOP_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_TOP_3) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) FacadeProvider(de.symeda.sormas.api.FacadeProvider) DateFormatHelper(de.symeda.sormas.ui.utils.DateFormatHelper) CssLayout(com.vaadin.ui.CssLayout) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) OptionGroup(com.vaadin.v7.ui.OptionGroup) LayoutUtil.loc(de.symeda.sormas.ui.utils.LayoutUtil.loc) LayoutUtil.locCss(de.symeda.sormas.ui.utils.LayoutUtil.locCss) Label(com.vaadin.ui.Label) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) Validations(de.symeda.sormas.api.i18n.Validations) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) UserRight(de.symeda.sormas.api.user.UserRight) Disease(de.symeda.sormas.api.Disease) SampleDto(de.symeda.sormas.api.sample.SampleDto) TextArea(com.vaadin.v7.ui.TextArea) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) SamplingReason(de.symeda.sormas.api.sample.SamplingReason) AbstractField(com.vaadin.v7.ui.AbstractField) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) DateField(com.vaadin.v7.ui.DateField) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator)

Example 14 with Field

use of com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.

the class LocationEditForm method addFields.

@SuppressWarnings("deprecation")
@Override
protected void addFields() {
    addressType = addField(LocationDto.ADDRESS_TYPE, ComboBox.class);
    addressType.setVisible(false);
    final PersonAddressType[] personAddressTypeValues = PersonAddressType.getValues(FacadeProvider.getConfigFacade().getCountryCode());
    if (!isConfiguredServer("ch")) {
        addressType.removeAllItems();
        addressType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
        addressType.addItems(personAddressTypeValues);
    }
    TextField addressTypeDetails = addField(LocationDto.ADDRESS_TYPE_DETAILS, TextField.class);
    addressTypeDetails.setVisible(false);
    FieldHelper.setVisibleWhen(getFieldGroup(), LocationDto.ADDRESS_TYPE_DETAILS, addressType, Arrays.stream(personAddressTypeValues).filter(pat -> !pat.equals(PersonAddressType.HOME)).collect(Collectors.toList()), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), addressType, Arrays.asList(LocationDto.ADDRESS_TYPE_DETAILS), Arrays.asList(PersonAddressType.OTHER_ADDRESS));
    facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
    ;
    facilityTypeGroup.setId("typeGroup");
    facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
    facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
    facilityTypeGroup.addItems(FacilityTypeGroup.values());
    getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
    facilityType = addField(LocationDto.FACILITY_TYPE);
    facility = addInfrastructureField(LocationDto.FACILITY);
    facility.setImmediate(true);
    facilityDetails = addField(LocationDto.FACILITY_DETAILS, TextField.class);
    facilityDetails.setVisible(false);
    addressType.addValueChangeListener(e -> {
        FacilityTypeGroup oldGroup = (FacilityTypeGroup) facilityTypeGroup.getValue();
        FacilityType oldType = (FacilityType) facilityType.getValue();
        FacilityReferenceDto oldFacility = (FacilityReferenceDto) facility.getValue();
        String oldDetails = facilityDetails.getValue();
        if (PersonAddressType.HOME.equals(addressType.getValue())) {
            facilityTypeGroup.removeAllItems();
            facilityTypeGroup.addItems(FacilityTypeGroup.getAccomodationGroups());
            setOldFacilityValuesIfPossible(oldGroup, oldType, oldFacility, oldDetails);
        } else {
            facilityTypeGroup.removeAllItems();
            facilityTypeGroup.addItems(FacilityTypeGroup.values());
            setOldFacilityValuesIfPossible(oldGroup, oldType, oldFacility, oldDetails);
        }
    });
    TextField streetField = addField(LocationDto.STREET, TextField.class);
    TextField houseNumberField = addField(LocationDto.HOUSE_NUMBER, TextField.class);
    TextField additionalInformationField = addField(LocationDto.ADDITIONAL_INFORMATION, TextField.class);
    addField(LocationDto.DETAILS, TextField.class);
    TextField cityField = addField(LocationDto.CITY, TextField.class);
    TextField postalCodeField = addField(LocationDto.POSTAL_CODE, TextField.class);
    ComboBox areaType = addField(LocationDto.AREA_TYPE, ComboBox.class);
    areaType.setDescription(I18nProperties.getDescription(getPropertyI18nPrefix() + "." + LocationDto.AREA_TYPE));
    contactPersonFirstName = addField(LocationDto.CONTACT_PERSON_FIRST_NAME, TextField.class);
    contactPersonLastName = addField(LocationDto.CONTACT_PERSON_LAST_NAME, TextField.class);
    contactPersonPhone = addField(LocationDto.CONTACT_PERSON_PHONE, TextField.class);
    contactPersonPhone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, contactPersonPhone.getCaption())));
    contactPersonEmail = addField(LocationDto.CONTACT_PERSON_EMAIL, TextField.class);
    contactPersonEmail.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, contactPersonEmail.getCaption())));
    final AccessibleTextField tfLatitude = addField(LocationDto.LATITUDE, AccessibleTextField.class);
    final AccessibleTextField tfLongitude = addField(LocationDto.LONGITUDE, AccessibleTextField.class);
    final AccessibleTextField tfAccuracy = addField(LocationDto.LAT_LON_ACCURACY, AccessibleTextField.class);
    final StringToAngularLocationConverter stringToAngularLocationConverter = new StringToAngularLocationConverter();
    tfLatitude.setConverter(stringToAngularLocationConverter);
    tfLongitude.setConverter(stringToAngularLocationConverter);
    tfAccuracy.setConverter(stringToAngularLocationConverter);
    continent = addInfrastructureField(LocationDto.CONTINENT);
    subcontinent = addInfrastructureField(LocationDto.SUB_CONTINENT);
    country = addInfrastructureField(LocationDto.COUNTRY);
    ComboBox region = addInfrastructureField(LocationDto.REGION);
    ComboBox district = addInfrastructureField(LocationDto.DISTRICT);
    ComboBox community = addInfrastructureField(LocationDto.COMMUNITY);
    continent.setVisible(false);
    subcontinent.setVisible(false);
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    if (!isEditableAllowed(LocationDto.COMMUNITY)) {
        setEnabled(false, LocationDto.COUNTRY, LocationDto.REGION, LocationDto.DISTRICT);
    }
    ValueChangeListener continentValueListener = e -> {
        if (continent.isVisible()) {
            ContinentReferenceDto continentReferenceDto = (ContinentReferenceDto) e.getProperty().getValue();
            if (subcontinent.getValue() == null) {
                FieldHelper.updateItems(country, continentReferenceDto != null ? FacadeProvider.getCountryFacade().getAllActiveByContinent(continentReferenceDto.getUuid()) : FacadeProvider.getCountryFacade().getAllActiveAsReference());
                country.setValue(null);
            }
            subcontinent.setValue(null);
            FieldHelper.updateItems(subcontinent, continentReferenceDto != null ? FacadeProvider.getSubcontinentFacade().getAllActiveByContinent(continentReferenceDto.getUuid()) : FacadeProvider.getSubcontinentFacade().getAllActiveAsReference());
        }
    };
    ValueChangeListener subContinentValueListener = e -> {
        if (subcontinent.isVisible()) {
            SubcontinentReferenceDto subcontinentReferenceDto = (SubcontinentReferenceDto) e.getProperty().getValue();
            if (subcontinentReferenceDto != null) {
                continent.removeValueChangeListener(continentValueListener);
                continent.setValue(FacadeProvider.getContinentFacade().getBySubcontinent(subcontinentReferenceDto));
                continent.addValueChangeListener(continentValueListener);
            }
            country.setValue(null);
            ContinentReferenceDto continentValue = (ContinentReferenceDto) continent.getValue();
            FieldHelper.updateItems(country, subcontinentReferenceDto != null ? FacadeProvider.getCountryFacade().getAllActiveBySubcontinent(subcontinentReferenceDto.getUuid()) : continentValue == null ? FacadeProvider.getCountryFacade().getAllActiveAsReference() : FacadeProvider.getCountryFacade().getAllActiveByContinent(continentValue.getUuid()));
        }
    };
    continent.addValueChangeListener(continentValueListener);
    subcontinent.addValueChangeListener(subContinentValueListener);
    skipCountryValueChange = false;
    country.addValueChangeListener(e -> {
        if (!skipCountryValueChange) {
            CountryReferenceDto countryDto = (CountryReferenceDto) e.getProperty().getValue();
            if (countryDto != null) {
                final ContinentReferenceDto countryContinent = FacadeProvider.getContinentFacade().getByCountry(countryDto);
                final SubcontinentReferenceDto countrySubcontinent = FacadeProvider.getSubcontinentFacade().getByCountry(countryDto);
                if (countryContinent != null) {
                    continent.removeValueChangeListener(continentValueListener);
                    if (continent.isVisible()) {
                        skipCountryValueChange = true;
                        FieldHelper.updateItems(country, FacadeProvider.getCountryFacade().getAllActiveByContinent(countryContinent.getUuid()));
                        skipCountryValueChange = false;
                    }
                    continent.setValue(countryContinent);
                    continent.addValueChangeListener(continentValueListener);
                }
                if (countrySubcontinent != null) {
                    subcontinent.removeValueChangeListener(subContinentValueListener);
                    if (subcontinent.isVisible()) {
                        skipCountryValueChange = true;
                        if (countryContinent != null) {
                            FieldHelper.updateItems(subcontinent, FacadeProvider.getSubcontinentFacade().getAllActiveByContinent(countryContinent.getUuid()));
                        }
                        FieldHelper.updateItems(country, FacadeProvider.getCountryFacade().getAllActiveBySubcontinent(countrySubcontinent.getUuid()));
                        skipCountryValueChange = false;
                    }
                    subcontinent.setValue(countrySubcontinent);
                    subcontinent.addValueChangeListener(subContinentValueListener);
                }
            }
        }
    });
    region.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(district, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
    });
    district.addValueChangeListener(e -> {
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(community, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
        if (districtDto == null) {
            FieldHelper.removeItems(facility);
            // Add a visual indictator reminding the user to select a district
            facility.setComponentError(new ErrorMessage() {

                @Override
                public ErrorLevel getErrorLevel() {
                    return ErrorLevel.INFO;
                }

                @Override
                public String getFormattedHtmlMessage() {
                    return I18nProperties.getString(Strings.infoFacilityNeedsDistrict);
                }
            });
        } else if (facilityType.getValue() != null) {
            facility.setComponentError(null);
            facility.markAsDirty();
            FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(districtDto, (FacilityType) facilityType.getValue(), true, false));
        }
    });
    community.addValueChangeListener(e -> {
        CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
        if (facilityType.getValue() != null) {
            FieldHelper.updateItems(facility, communityDto != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(communityDto, (FacilityType) facilityType.getValue(), true, true) : district.getValue() != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) district.getValue(), (FacilityType) facilityType.getValue(), true, false) : null);
        }
    });
    skipFacilityTypeUpdate = false;
    facilityTypeGroup.addValueChangeListener(e -> {
        if (!skipFacilityTypeUpdate) {
            FieldHelper.removeItems(facility);
            FieldHelper.updateEnumData(facilityType, FacilityType.getTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
            facilityType.setRequired(facilityTypeGroup.getValue() != null);
        }
    });
    facilityType.addValueChangeListener(e -> {
        FieldHelper.removeItems(facility);
        facility.setComponentError(null);
        facility.markAsDirty();
        if (facilityType.getValue() != null && facilityTypeGroup.getValue() == null) {
            facilityTypeGroup.setValue(((FacilityType) facilityType.getValue()).getFacilityTypeGroup());
        }
        if (facilityType.getValue() != null && district.getValue() != null) {
            if (community.getValue() != null) {
                FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType((CommunityReferenceDto) community.getValue(), (FacilityType) facilityType.getValue(), true, false));
            } else {
                FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) district.getValue(), (FacilityType) facilityType.getValue(), true, false));
            }
        } else if (facilityType.getValue() != null && district.getValue() == null) {
            // Add a visual indictator reminding the user to select a district
            facility.setComponentError(new ErrorMessage() {

                @Override
                public ErrorLevel getErrorLevel() {
                    return ErrorLevel.INFO;
                }

                @Override
                public String getFormattedHtmlMessage() {
                    return I18nProperties.getString(Strings.infoFacilityNeedsDistrict);
                }
            });
        }
        // Only show contactperson-details if at least a faciltytype has been set
        if (facilityType.getValue() != null) {
            setFacilityContactPersonFieldsVisible(true, true);
        } else {
            setFacilityContactPersonFieldsVisible(false, true);
        }
    });
    facility.addValueChangeListener(e -> {
        if (facility.getValue() != null) {
            boolean visibleAndRequired = areFacilityDetailsRequired();
            facilityDetails.setVisible(visibleAndRequired);
            facilityDetails.setRequired(visibleAndRequired);
            if (!visibleAndRequired) {
                facilityDetails.clear();
            } else {
                String facilityDetailsValue = getValue() != null ? getValue().getFacilityDetails() : null;
                facilityDetails.setValue(facilityDetailsValue);
            }
        } else {
            facilityDetails.setVisible(false);
            facilityDetails.setRequired(false);
            facilityDetails.clear();
        }
        // value because of this field dependencies to other fields and the way updateEnumValues works
        if (facility.isAttached() && !disableFacilityAddressCheck) {
            if (facility.getValue() != null) {
                FacilityDto facilityDto = FacadeProvider.getFacilityFacade().getByUuid(((FacilityReferenceDto) getField(LocationDto.FACILITY).getValue()).getUuid());
                // Only if the facility's address is set
                if (StringUtils.isNotEmpty(facilityDto.getCity()) || StringUtils.isNotEmpty(facilityDto.getPostalCode()) || StringUtils.isNotEmpty(facilityDto.getStreet()) || StringUtils.isNotEmpty(facilityDto.getHouseNumber()) || StringUtils.isNotEmpty(facilityDto.getAdditionalInformation()) || facilityDto.getAreaType() != null || facilityDto.getLatitude() != null || facilityDto.getLongitude() != null || (StringUtils.isNotEmpty(facilityDto.getContactPersonFirstName()) && StringUtils.isNotEmpty(facilityDto.getContactPersonLastName()))) {
                    // Show a confirmation popup if the location's address is already set and different from the facility one
                    if ((StringUtils.isNotEmpty(cityField.getValue()) && !cityField.getValue().equals(facilityDto.getCity())) || (StringUtils.isNotEmpty(postalCodeField.getValue()) && !postalCodeField.getValue().equals(facilityDto.getPostalCode())) || (StringUtils.isNotEmpty(streetField.getValue()) && !streetField.getValue().equals(facilityDto.getStreet())) || (StringUtils.isNotEmpty(houseNumberField.getValue()) && !houseNumberField.getValue().equals(facilityDto.getHouseNumber())) || (StringUtils.isNotEmpty(additionalInformationField.getValue()) && !additionalInformationField.getValue().equals(facilityDto.getAdditionalInformation())) || (areaType.getValue() != null && areaType.getValue() != facilityDto.getAreaType()) || (StringUtils.isNotEmpty(contactPersonFirstName.getValue()) && StringUtils.isNotEmpty(contactPersonLastName.getValue())) || (tfLatitude.getConvertedValue() != null && Double.compare((Double) tfLatitude.getConvertedValue(), facilityDto.getLatitude()) != 0) || (tfLongitude.getConvertedValue() != null && Double.compare((Double) tfLongitude.getConvertedValue(), facilityDto.getLongitude()) != 0)) {
                        VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingLocation), new Label(I18nProperties.getString(Strings.confirmationLocationFacilityAddressOverride)), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), 640, confirmationEvent -> {
                            if (confirmationEvent) {
                                overrideLocationDetailsWithFacilityOnes(facilityDto);
                            }
                        });
                    } else {
                        overrideLocationDetailsWithFacilityOnes(facilityDto);
                    }
                }
            }
        }
    });
    final List<ContinentReferenceDto> continents = FacadeProvider.getContinentFacade().getAllActiveAsReference();
    if (continents.isEmpty()) {
        continent.setVisible(false);
        continent.clear();
    } else {
        continent.addItems(continents);
    }
    final List<SubcontinentReferenceDto> subcontinents = FacadeProvider.getSubcontinentFacade().getAllActiveAsReference();
    if (subcontinents.isEmpty()) {
        subcontinent.setVisible(false);
        subcontinent.clear();
    } else {
        subcontinent.addItems(subcontinents);
    }
    country.addItems(FacadeProvider.getCountryFacade().getAllActiveAsReference());
    updateRegionCombo(region, country);
    country.addValueChangeListener(e -> {
        updateRegionCombo(region, country);
        region.setValue(null);
    });
    Stream.of(LocationDto.LATITUDE, LocationDto.LONGITUDE).<Field<?>>map(this::getField).forEach(f -> f.addValueChangeListener(e -> this.updateLeafletMapContent()));
    // Set initial visiblity of facility-contactperson-details (should only be visible if at least a facilityType has been selected)
    setFacilityContactPersonFieldsVisible(facilityType.getValue() != null, true);
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) Arrays(java.util.Arrays) AbstractField(com.vaadin.v7.ui.AbstractField) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) Alignment(com.vaadin.ui.Alignment) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) LeafletMarker(de.symeda.sormas.ui.map.LeafletMarker) StringUtils(org.apache.commons.lang3.StringUtils) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) CssStyles(de.symeda.sormas.ui.utils.CssStyles) GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon) VaadinIcons(com.vaadin.icons.VaadinIcons) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) LeafletMap(de.symeda.sormas.ui.map.LeafletMap) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) LayoutUtil.divs(de.symeda.sormas.ui.utils.LayoutUtil.divs) PopupView(com.vaadin.ui.PopupView) ComboBox(com.vaadin.v7.ui.ComboBox) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) List(java.util.List) PersonAddressType(de.symeda.sormas.api.person.PersonAddressType) Stream(java.util.stream.Stream) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) SubcontinentReferenceDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) FacadeProvider(de.symeda.sormas.api.FacadeProvider) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) ContinentCriteria(de.symeda.sormas.api.infrastructure.continent.ContinentCriteria) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) Converter(com.vaadin.v7.data.util.converter.Converter) CustomLayout(com.vaadin.ui.CustomLayout) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Label(com.vaadin.ui.Label) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) LocationDto(de.symeda.sormas.api.location.LocationDto) ContentMode(com.vaadin.shared.ui.ContentMode) Validations(de.symeda.sormas.api.i18n.Validations) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ErrorMessage(com.vaadin.server.ErrorMessage) Captions(de.symeda.sormas.api.i18n.Captions) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Button(com.vaadin.ui.Button) MarkerIcon(de.symeda.sormas.ui.map.MarkerIcon) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SubcontinentCriteria(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentCriteria) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) StringToAngularLocationConverter(de.symeda.sormas.ui.utils.StringToAngularLocationConverter) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) Component(com.vaadin.ui.Component) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) Label(com.vaadin.ui.Label) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) StringToAngularLocationConverter(de.symeda.sormas.ui.utils.StringToAngularLocationConverter) TextField(com.vaadin.v7.ui.TextField) SubcontinentReferenceDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto) ComboBox(com.vaadin.v7.ui.ComboBox) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) PersonAddressType(de.symeda.sormas.api.person.PersonAddressType) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) ErrorMessage(com.vaadin.server.ErrorMessage) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 15 with Field

use of com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.

the class LocationEditForm method createGeoButton.

private HorizontalLayout createGeoButton() {
    HorizontalLayout geoButtonLayout = new HorizontalLayout();
    geoButtonLayout.setMargin(false);
    geoButtonLayout.setSpacing(false);
    Button geocodeButton = ButtonHelper.createIconButtonWithCaption("geocodeButton", null, VaadinIcons.MAP_MARKER, e -> {
        triggerGeocoding();
        e.getButton().removeStyleName(CssStyles.GEOCODE_BUTTON_HIGHLIGHT);
    }, ValoTheme.BUTTON_ICON_ONLY, ValoTheme.BUTTON_BORDERLESS, ValoTheme.BUTTON_LARGE);
    Field[] locationGeoFields = Stream.of(LocationDto.STREET, LocationDto.POSTAL_CODE, LocationDto.CITY, LocationDto.HOUSE_NUMBER).map(field -> (Field) getField(field)).toArray(Field[]::new);
    // Highlight geocode-button when the address changes
    Stream.of(locationGeoFields).forEach(field -> field.addValueChangeListener(e -> {
        if (isAllFieldsEmpty(locationGeoFields)) {
            geocodeButton.removeStyleName(CssStyles.GEOCODE_BUTTON_HIGHLIGHT);
        } else if (field.isModified()) {
            geocodeButton.addStyleName(CssStyles.GEOCODE_BUTTON_HIGHLIGHT);
        }
    }));
    geoButtonLayout.addComponent(geocodeButton);
    geoButtonLayout.setComponentAlignment(geocodeButton, Alignment.BOTTOM_RIGHT);
    leafletMapPopup = new MapPopupView();
    leafletMapPopup.setCaption(" ");
    leafletMapPopup.setEnabled(false);
    leafletMapPopup.setStyleName(ValoTheme.BUTTON_LARGE);
    leafletMapPopup.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    geoButtonLayout.addComponent(leafletMapPopup);
    geoButtonLayout.setComponentAlignment(leafletMapPopup, Alignment.BOTTOM_RIGHT);
    return geoButtonLayout;
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) Arrays(java.util.Arrays) AbstractField(com.vaadin.v7.ui.AbstractField) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) Alignment(com.vaadin.ui.Alignment) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) LeafletMarker(de.symeda.sormas.ui.map.LeafletMarker) StringUtils(org.apache.commons.lang3.StringUtils) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) CssStyles(de.symeda.sormas.ui.utils.CssStyles) GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon) VaadinIcons(com.vaadin.icons.VaadinIcons) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) LeafletMap(de.symeda.sormas.ui.map.LeafletMap) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) LayoutUtil.divs(de.symeda.sormas.ui.utils.LayoutUtil.divs) PopupView(com.vaadin.ui.PopupView) ComboBox(com.vaadin.v7.ui.ComboBox) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) List(java.util.List) PersonAddressType(de.symeda.sormas.api.person.PersonAddressType) Stream(java.util.stream.Stream) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) SubcontinentReferenceDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) FacadeProvider(de.symeda.sormas.api.FacadeProvider) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) ContinentCriteria(de.symeda.sormas.api.infrastructure.continent.ContinentCriteria) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) Converter(com.vaadin.v7.data.util.converter.Converter) CustomLayout(com.vaadin.ui.CustomLayout) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Label(com.vaadin.ui.Label) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) LocationDto(de.symeda.sormas.api.location.LocationDto) ContentMode(com.vaadin.shared.ui.ContentMode) Validations(de.symeda.sormas.api.i18n.Validations) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ErrorMessage(com.vaadin.server.ErrorMessage) Captions(de.symeda.sormas.api.i18n.Captions) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Button(com.vaadin.ui.Button) MarkerIcon(de.symeda.sormas.ui.map.MarkerIcon) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SubcontinentCriteria(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentCriteria) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) StringToAngularLocationConverter(de.symeda.sormas.ui.utils.StringToAngularLocationConverter) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) Component(com.vaadin.ui.Component) AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) Button(com.vaadin.ui.Button) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Aggregations

TextField (com.vaadin.v7.ui.TextField)36 Field (com.vaadin.v7.ui.Field)34 ComboBox (com.vaadin.v7.ui.ComboBox)32 AbstractField (com.vaadin.v7.ui.AbstractField)23 DateField (com.vaadin.v7.ui.DateField)20 Label (com.vaadin.ui.Label)19 Disease (de.symeda.sormas.api.Disease)15 FacadeProvider (de.symeda.sormas.api.FacadeProvider)15 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)15 FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)15 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)15 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)14 Strings (de.symeda.sormas.api.i18n.Strings)14 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)14 DateComparisonValidator (de.symeda.sormas.ui.utils.DateComparisonValidator)14 FieldHelper (de.symeda.sormas.ui.utils.FieldHelper)14 LayoutUtil.fluidRowLocs (de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs)14 Collections (java.util.Collections)14 Button (com.vaadin.ui.Button)13 CssStyles (de.symeda.sormas.ui.utils.CssStyles)13