Example usage for com.vaadin.v7.ui OptionGroup getValue

List of usage examples for com.vaadin.v7.ui OptionGroup getValue

Introduction

In this page you can find the example usage for com.vaadin.v7.ui OptionGroup getValue.

Prototype

@Override
public Object getValue() 

Source Link

Document

Gets the selected item id or in multiselect mode a set of selected ids.

Usage

From source file:de.symeda.sormas.ui.epidata.EpiDataForm.java

License:Open Source License

private void updateBurialsHint(OptionGroup burialAttendedField, EpiDataBurialsField burialsField) {
    YesNoUnknown value = (YesNoUnknown) burialAttendedField.getValue();
    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_EDIT) && value == YesNoUnknown.YES
            && (burialsField == null || burialsField.getValue() == null
                    || burialsField.getValue().size() == 0)) {
        burialAttendedField.setComponentError(
                new UserError(I18nProperties.getValidationError(Validations.softAddEntryToList)));
    } else {/*from   w  ww. ja v a2s . c  o m*/
        burialAttendedField.setComponentError(null);
    }
}

From source file:de.symeda.sormas.ui.epidata.EpiDataForm.java

License:Open Source License

private void updateGatheringsHint(OptionGroup gatheringAttendedField, EpiDataGatheringsField gatheringsField) {
    YesNoUnknown value = (YesNoUnknown) gatheringAttendedField.getValue();
    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_EDIT) && value == YesNoUnknown.YES
            && (gatheringsField == null || gatheringsField.getValue() == null
                    || gatheringsField.getValue().size() == 0)) {
        gatheringAttendedField.setComponentError(
                new UserError(I18nProperties.getValidationError(Validations.softAddEntryToList)));
    } else {// www  . j a  v a  2s  .com
        gatheringAttendedField.setComponentError(null);
    }
}

From source file:de.symeda.sormas.ui.epidata.EpiDataForm.java

License:Open Source License

private void updateTravelsHint(OptionGroup traveledField, EpiDataTravelsField travelsField) {
    YesNoUnknown value = (YesNoUnknown) traveledField.getValue();
    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_EDIT) && value == YesNoUnknown.YES
            && (travelsField == null || travelsField.getValue() == null
                    || travelsField.getValue().size() == 0)) {
        traveledField.setComponentError(
                new UserError(I18nProperties.getValidationError(Validations.softAddEntryToList)));
    } else {//from   ww  w .  j  av a 2  s.  c om
        traveledField.setComponentError(null);
    }
}

From source file:de.symeda.sormas.ui.hospitalization.HospitalizationForm.java

License:Open Source License

private void updatePrevHospHint(OptionGroup hospitalizedPreviouslyField,
        PreviousHospitalizationsField previousHospitalizationsField) {
    YesNoUnknown value = (YesNoUnknown) hospitalizedPreviouslyField.getValue();
    Collection<PreviousHospitalizationDto> previousHospitalizations = previousHospitalizationsField.getValue();
    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_EDIT) && value == YesNoUnknown.YES
            && (previousHospitalizations == null || previousHospitalizations.size() == 0)) {
        hospitalizedPreviouslyField.setComponentError(
                new UserError(I18nProperties.getValidationError(Validations.softAddEntryToList)));
    } else {/*  www  . j a  va 2s  . com*/
        hospitalizedPreviouslyField.setComponentError(null);
    }
}

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

License:Open Source License

/**
 * Sets the fields defined by the ids contained in sourceValues to required when the person is symptomatic
 * and - if a visit is processed - cooperative. When this method is called from within a case, it needs to 
 * be called with visitStatusField set to null in order to ignore the visit status requirement.
 *//*w w w .j  av a 2 s . c o  m*/
@SuppressWarnings("rawtypes")
private void addSoftRequiredStyleWhenSymptomaticAndCooperative(FieldGroup fieldGroup, Object targetPropertyId,
        List<String> sourcePropertyIds, List<Object> sourceValues, OptionGroup visitStatusField) {

    for (Object sourcePropertyId : sourcePropertyIds) {
        Field sourceField = fieldGroup.getField(sourcePropertyId);
        if (sourceField instanceof AbstractField<?>) {
            ((AbstractField) sourceField).setImmediate(true);
        }
    }

    // Initialize
    final Field targetField = fieldGroup.getField(targetPropertyId);
    if (!targetField.isVisible()) {
        return;
    }

    if (visitStatusField != null) {
        if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)
                && visitStatusField.getValue() == VisitStatus.COOPERATIVE) {
            FieldHelper.addSoftRequiredStyle(targetField);
        } else {
            FieldHelper.removeSoftRequiredStyle(targetField);
        }
    } else {
        if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)) {
            FieldHelper.addSoftRequiredStyle(targetField);
        } else {
            FieldHelper.removeSoftRequiredStyle(targetField);
        }
    }

    // Add listeners
    for (Object sourcePropertyId : sourcePropertyIds) {
        Field sourceField = fieldGroup.getField(sourcePropertyId);
        sourceField.addValueChangeListener(event -> {
            if (visitStatusField != null) {
                if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)
                        && visitStatusField.getValue() == VisitStatus.COOPERATIVE) {
                    FieldHelper.addSoftRequiredStyle(targetField);
                } else {
                    FieldHelper.removeSoftRequiredStyle(targetField);
                }
            } else {
                if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)) {
                    FieldHelper.addSoftRequiredStyle(targetField);
                } else {
                    FieldHelper.removeSoftRequiredStyle(targetField);
                }
            }
        });
    }

    if (visitStatusField != null) {
        visitStatusField.addValueChangeListener(new ValueChangeListener() {
            @Override
            public void valueChange(com.vaadin.v7.data.Property.ValueChangeEvent event) {
                if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)
                        && visitStatusField.getValue() == VisitStatus.COOPERATIVE) {
                    FieldHelper.addSoftRequiredStyle(targetField);
                } else {
                    FieldHelper.removeSoftRequiredStyle(targetField);
                }
            }
        });
    }
}

From source file:de.symeda.sormas.ui.user.UserEditForm.java

License:Open Source License

@SuppressWarnings("unchecked")
private void updateFieldsByUserRole() {
    OptionGroup userRolesField = (OptionGroup) getFieldGroup().getField(UserDto.USER_ROLES);
    Set<UserRole> userRoles = (Set<UserRole>) userRolesField.getValue();
    boolean isInformant = UserRole.isInformant(userRoles);
    boolean isOfficer = UserRole.isOfficer(userRoles);
    boolean isSupervisor = UserRole.isSupervisor(userRoles);
    boolean isLabUser = UserRole.isLabUser(userRoles);
    boolean isPortHealthUser = UserRole.isPortHealthUser(userRoles);
    boolean isStateObserver = userRoles.contains(UserRole.STATE_OBSERVER);
    boolean isDistrictObserver = userRoles.contains(UserRole.DISTRICT_OBSERVER);

    // associated officer
    ComboBox associatedOfficer = (ComboBox) getFieldGroup().getField(UserDto.ASSOCIATED_OFFICER);
    associatedOfficer.setVisible(isInformant);
    setRequired(isInformant && !isPortHealthUser, UserDto.ASSOCIATED_OFFICER);
    if (!isInformant) {
        associatedOfficer.clear();// ww  w  .j  a  v  a  2 s. com
    }

    // community
    ComboBox community = (ComboBox) getFieldGroup().getField(UserDto.COMMUNITY);
    community.setVisible(userRoles.contains(UserRole.COMMUNITY_INFORMANT));
    setRequired(userRoles.contains(UserRole.COMMUNITY_INFORMANT), UserDto.COMMUNITY);
    if (!userRoles.contains(UserRole.COMMUNITY_INFORMANT)) {
        community.clear();
    }

    // health facility
    ComboBox healthFacility = (ComboBox) getFieldGroup().getField(UserDto.HEALTH_FACILITY);
    healthFacility.setVisible(isOfficer || userRoles.contains(UserRole.HOSPITAL_INFORMANT));
    setRequired(userRoles.contains(UserRole.HOSPITAL_INFORMANT), UserDto.HEALTH_FACILITY);
    if (!healthFacility.isVisible()) {
        healthFacility.clear();
    }

    // laboratory
    ComboBox laboratory = (ComboBox) getFieldGroup().getField(UserDto.LABORATORY);
    laboratory.setVisible(isLabUser);
    setRequired(isLabUser, UserDto.LABORATORY);
    if (!isLabUser) {
        laboratory.clear();
    }

    // point of entry
    ComboBox pointOfEntry = (ComboBox) getFieldGroup().getField(UserDto.POINT_OF_ENTRY);
    boolean usePointOfEntry = isPortHealthUser && isInformant;
    pointOfEntry.setVisible(usePointOfEntry);
    setRequired(usePointOfEntry, UserDto.POINT_OF_ENTRY);
    if (!usePointOfEntry) {
        pointOfEntry.clear();
    }

    ComboBox region = (ComboBox) getFieldGroup().getField(UserDto.REGION);
    boolean useRegion = isSupervisor || isInformant || isOfficer || isStateObserver || isDistrictObserver;
    region.setVisible(useRegion);
    setRequired(useRegion, UserDto.REGION);
    if (!useRegion) {
        region.clear();
    }

    ComboBox district = (ComboBox) getFieldGroup().getField(UserDto.DISTRICT);
    boolean useDistrict = isInformant || isOfficer || isDistrictObserver;
    district.setVisible(useDistrict);
    setRequired(useDistrict, UserDto.DISTRICT);
    if (!useDistrict) {
        district.clear();
    }
}