Search in sources :

Example 41 with ComboBox

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

the class TaskEditForm method updateByTaskContext.

private void updateByTaskContext() {
    TaskContext taskContext = (TaskContext) getFieldGroup().getField(TaskDto.TASK_CONTEXT).getValue();
    // Task types depending on task context
    ComboBox taskType = (ComboBox) getFieldGroup().getField(TaskDto.TASK_TYPE);
    FieldHelper.updateItems(taskType, TaskType.getTaskTypes(taskContext), FieldVisibilityCheckers.withDisease(disease), TaskType.class);
    // context reference depending on task context
    ComboBox caseField = (ComboBox) getFieldGroup().getField(TaskDto.CAZE);
    ComboBox eventField = (ComboBox) getFieldGroup().getField(TaskDto.EVENT);
    ComboBox contactField = (ComboBox) getFieldGroup().getField(TaskDto.CONTACT);
    if (taskContext != null) {
        switch(taskContext) {
            case CASE:
                FieldHelper.setFirstVisibleClearOthers(caseField, eventField, contactField);
                FieldHelper.setFirstRequired(caseField, eventField, contactField);
                break;
            case EVENT:
                FieldHelper.setFirstVisibleClearOthers(eventField, caseField, contactField);
                FieldHelper.setFirstRequired(eventField, caseField, contactField);
                break;
            case CONTACT:
                FieldHelper.setFirstVisibleClearOthers(contactField, caseField, eventField);
                FieldHelper.setFirstRequired(contactField, caseField, eventField);
                break;
            case GENERAL:
                FieldHelper.setFirstVisibleClearOthers(null, caseField, contactField, eventField);
                FieldHelper.setFirstRequired(null, caseField, contactField, eventField);
                break;
        }
    } else {
        FieldHelper.setFirstVisibleClearOthers(null, caseField, eventField, contactField);
        FieldHelper.setFirstRequired(null, caseField, eventField, contactField);
    }
}
Also used : TaskContext(de.symeda.sormas.api.task.TaskContext) ComboBox(com.vaadin.v7.ui.ComboBox)

Example 42 with ComboBox

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

the class UserEditForm method updateFieldsByUserRole.

@SuppressWarnings("unchecked")
private void updateFieldsByUserRole() {
    final Field userRolesField = getFieldGroup().getField(UserDto.USER_ROLES);
    final Set<UserRole> userRoles = (Set<UserRole>) userRolesField.getValue();
    final JurisdictionLevel jurisdictionLevel = UserRole.getJurisdictionLevel(userRoles);
    final boolean hasAssociatedOfficer = UserRole.hasAssociatedOfficer(userRoles);
    final boolean hasOptionalHealthFacility = UserRole.hasOptionalHealthFacility(userRoles);
    final boolean isPortHealthUser = UserRole.isPortHealthUser(userRoles);
    final boolean usePointOfEntry = (isPortHealthUser && hasAssociatedOfficer) || jurisdictionLevel == JurisdictionLevel.POINT_OF_ENTRY;
    final boolean useHealthFacility = jurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY;
    final boolean useLaboratory = jurisdictionLevel == JurisdictionLevel.LABORATORY;
    final boolean useCommunity = jurisdictionLevel == JurisdictionLevel.COMMUNITY;
    final boolean useDistrict = hasAssociatedOfficer || jurisdictionLevel == JurisdictionLevel.DISTRICT || useCommunity || useHealthFacility || usePointOfEntry;
    ;
    final boolean useRegion = jurisdictionLevel == JurisdictionLevel.REGION || useDistrict;
    final ComboBox associatedOfficer = (ComboBox) getFieldGroup().getField(UserDto.ASSOCIATED_OFFICER);
    associatedOfficer.setVisible(hasAssociatedOfficer);
    setRequired(hasAssociatedOfficer && !isPortHealthUser, UserDto.ASSOCIATED_OFFICER);
    if (!hasAssociatedOfficer) {
        associatedOfficer.clear();
    }
    final ComboBox community = (ComboBox) getFieldGroup().getField(UserDto.COMMUNITY);
    community.setVisible(useCommunity);
    setRequired(useCommunity, UserDto.COMMUNITY);
    if (!useCommunity) {
        community.clear();
    }
    final ComboBox healthFacility = (ComboBox) getFieldGroup().getField(UserDto.HEALTH_FACILITY);
    healthFacility.setVisible(hasOptionalHealthFacility || useHealthFacility);
    setRequired(useHealthFacility, UserDto.HEALTH_FACILITY);
    if (!healthFacility.isVisible()) {
        healthFacility.clear();
    }
    final ComboBox laboratory = (ComboBox) getFieldGroup().getField(UserDto.LABORATORY);
    laboratory.setVisible(useLaboratory);
    setRequired(useLaboratory, UserDto.LABORATORY);
    if (!useLaboratory) {
        laboratory.clear();
    }
    final ComboBox pointOfEntry = (ComboBox) getFieldGroup().getField(UserDto.POINT_OF_ENTRY);
    pointOfEntry.setVisible(usePointOfEntry);
    setRequired(usePointOfEntry, UserDto.POINT_OF_ENTRY);
    if (!usePointOfEntry) {
        pointOfEntry.clear();
    }
    final ComboBox district = (ComboBox) getFieldGroup().getField(UserDto.DISTRICT);
    district.setVisible(useDistrict);
    setRequired(useDistrict, UserDto.DISTRICT);
    if (!useDistrict) {
        district.clear();
    }
    final ComboBox region = (ComboBox) getFieldGroup().getField(UserDto.REGION);
    region.setVisible(useRegion);
    setRequired(useRegion, UserDto.REGION);
    if (!useRegion) {
        region.clear();
    }
}
Also used : Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) Set(java.util.Set) UserRole(de.symeda.sormas.api.user.UserRole) ComboBox(com.vaadin.v7.ui.ComboBox) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel)

Example 43 with ComboBox

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

the class UserEditForm method addFields.

@Override
protected void addFields() {
    Label personDataHeadingLabel = new Label(I18nProperties.getString(Strings.headingPersonData));
    personDataHeadingLabel.addStyleName(H3);
    getContent().addComponent(personDataHeadingLabel, PERSON_DATA_HEADING_LOC);
    Label addressHeadingLabel = new Label(I18nProperties.getString(Strings.address));
    addressHeadingLabel.addStyleName(H3);
    getContent().addComponent(addressHeadingLabel, ADDRESS_HEADING_LOC);
    Label userDataHeadingLabel = new Label(I18nProperties.getString(Strings.headingUserData));
    userDataHeadingLabel.addStyleName(H3);
    getContent().addComponent(userDataHeadingLabel, USER_DATA_HEADING_LOC);
    addField(UserDto.FIRST_NAME, TextField.class);
    addField(UserDto.LAST_NAME, TextField.class);
    addField(UserDto.USER_EMAIL, TextField.class);
    TextField phone = addField(UserDto.PHONE, TextField.class);
    phone.addValidator(new UserPhoneNumberValidator(I18nProperties.getValidationError(Validations.phoneNumberValidation)));
    if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.AGGREGATE_REPORTING) || FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.EVENT_SURVEILLANCE) || FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.WEEKLY_REPORTING) || FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.CASE_SURVEILANCE)) {
        addDiseaseField(UserDto.LIMITED_DISEASE, false);
    }
    Label userEmailDesc = new Label(I18nProperties.getString(Strings.infoUserEmail));
    getContent().addComponent(userEmailDesc, USER_EMAIL_DESC_LOC);
    Label userPhoneDesc = new Label(I18nProperties.getString(Strings.infoUserPhoneNumber));
    getContent().addComponent(userPhoneDesc, USER_PHONE_DESC_LOC);
    ComboBox cbLanguage = addField(UserDto.LANGUAGE, ComboBox.class);
    CssStyles.style(cbLanguage, CssStyles.COMBO_BOX_WITH_FLAG_ICON);
    ControllerProvider.getUserController().setFlagIcons(cbLanguage);
    addField(UserDto.ADDRESS, LocationEditForm.class).setCaption(null);
    addField(UserDto.ACTIVE, CheckBox.class);
    addField(UserDto.USER_NAME, TextField.class);
    addField(UserDto.USER_ROLES, OptionGroup.class).addValidator(new UserRolesValidator());
    OptionGroup userRoles = (OptionGroup) getFieldGroup().getField(UserDto.USER_ROLES);
    userRoles.setMultiSelect(true);
    ComboBox region = addInfrastructureField(UserDto.REGION);
    ComboBox community = addInfrastructureField(UserDto.COMMUNITY);
    ComboBox district = addInfrastructureField(UserDto.DISTRICT);
    region.addValueChangeListener(e -> {
        FieldHelper.removeItems(community);
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(district, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
    });
    // for informant
    ComboBox associatedOfficer = addField(UserDto.ASSOCIATED_OFFICER, ComboBox.class);
    ComboBox healthFacility = addInfrastructureField(UserDto.HEALTH_FACILITY);
    ComboBox cbPointOfEntry = addInfrastructureField(UserDto.POINT_OF_ENTRY);
    district.addValueChangeListener(e -> {
        FieldHelper.removeItems(healthFacility);
        FieldHelper.removeItems(associatedOfficer);
        FieldHelper.removeItems(cbPointOfEntry);
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(community, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
        FieldHelper.updateItems(healthFacility, districtDto != null ? FacadeProvider.getFacilityFacade().getActiveHospitalsByDistrict(districtDto, false) : null);
        FieldHelper.updateItems(associatedOfficer, districtDto != null ? FacadeProvider.getUserFacade().getUserRefsByDistrict(districtDto, null, UserRight.CASE_RESPONSIBLE, UserRight.WEEKLYREPORT_CREATE) : null);
        FieldHelper.updateItems(cbPointOfEntry, districtDto != null ? FacadeProvider.getPointOfEntryFacade().getAllActiveByDistrict(districtDto.getUuid(), false) : null);
    });
    ComboBox laboratory = addInfrastructureField(UserDto.LABORATORY);
    laboratory.addItems(FacadeProvider.getFacilityFacade().getAllActiveLaboratories(false));
    region.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    setRequired(true, UserDto.FIRST_NAME, UserDto.LAST_NAME, UserDto.USER_NAME, UserDto.USER_ROLES);
    addValidators(UserDto.USER_NAME, new UserNameValidator());
    addFieldListeners(UserDto.FIRST_NAME, e -> suggestUserName());
    addFieldListeners(UserDto.LAST_NAME, e -> suggestUserName());
    addFieldListeners(UserDto.USER_ROLES, e -> updateFieldsByUserRole());
    updateFieldsByUserRole();
}
Also used : OptionGroup(com.vaadin.v7.ui.OptionGroup) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) TextField(com.vaadin.v7.ui.TextField) UserPhoneNumberValidator(de.symeda.sormas.ui.utils.UserPhoneNumberValidator) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)

Example 44 with ComboBox

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

the class UserSettingsForm method addFields.

@Override
protected void addFields() {
    ComboBox cbLanguage = addField(UserDto.LANGUAGE, ComboBox.class);
    CssStyles.style(cbLanguage, CssStyles.COMBO_BOX_WITH_FLAG_ICON);
    ControllerProvider.getUserController().setFlagIcons(cbLanguage);
    String authenticationProvider = FacadeProvider.getConfigFacade().getAuthenticationProvider();
    if (AuthProvider.KEYCLOAK.equals(authenticationProvider)) {
        emailTf = addField(UserDto.USER_EMAIL, TextField.class);
        emailTf.setCaption(I18nProperties.getCaption(Captions.User_userEmail));
        emailTf.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, emailTf.getCaption())));
    }
}
Also used : EmailValidator(com.vaadin.v7.data.validator.EmailValidator) ComboBox(com.vaadin.v7.ui.ComboBox) TextField(com.vaadin.v7.ui.TextField)

Example 45 with ComboBox

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

the class AbstractEditForm method addNonPrimaryDiseasesTo.

@SuppressWarnings("unchecked")
protected void addNonPrimaryDiseasesTo(ComboBox diseaseField) {
    List<Disease> diseases = FacadeProvider.getDiseaseConfigurationFacade().getAllDiseases(true, false, true);
    for (Disease disease : diseases) {
        if (diseaseField.getItem(disease) != null) {
            continue;
        }
        Item newItem = diseaseField.addItem(disease);
        newItem.getItemProperty(SormasFieldGroupFieldFactory.CAPTION_PROPERTY_ID).setValue(disease.toString());
    }
}
Also used : Item(com.vaadin.v7.data.Item) Disease(de.symeda.sormas.api.Disease)

Aggregations

ComboBox (com.vaadin.v7.ui.ComboBox)113 TextField (com.vaadin.v7.ui.TextField)43 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)31 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)28 Label (com.vaadin.ui.Label)24 Disease (de.symeda.sormas.api.Disease)24 TextArea (com.vaadin.v7.ui.TextArea)19 UserDto (de.symeda.sormas.api.user.UserDto)19 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)19 DateField (com.vaadin.v7.ui.DateField)18 List (java.util.List)18 CheckBox (com.vaadin.v7.ui.CheckBox)17 FacadeProvider (de.symeda.sormas.api.FacadeProvider)17 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)17 DateComparisonValidator (de.symeda.sormas.ui.utils.DateComparisonValidator)17 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)16 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)16 Field (com.vaadin.v7.ui.Field)15 FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)15 Captions (de.symeda.sormas.api.i18n.Captions)14