Search in sources :

Example 21 with Field

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

the class SymptomsForm method addListenerForOnsetFields.

@SuppressWarnings("rawtypes")
private void addListenerForOnsetFields(ComboBox onsetSymptom, DateField onsetDateField) {
    List<String> allPropertyIds = Stream.concat(unconditionalSymptomFieldIds.stream(), conditionalBleedingSymptomFieldIds.stream()).collect(Collectors.toList());
    allPropertyIds.add(LESIONS_THAT_ITCH);
    for (Object sourcePropertyId : allPropertyIds) {
        Field sourceField = getFieldGroup().getField(sourcePropertyId);
        sourceField.addValueChangeListener(event -> {
            if (FieldHelper.getNullableSourceFieldValue(sourceField) == SymptomState.YES) {
                onsetSymptom.addItem(sourceField.getCaption());
                onsetDateField.setEnabled(true);
            } else {
                onsetSymptom.removeItem(sourceField.getCaption());
                boolean isOnsetDateFieldEnabled = isAnySymptomSetToYes(getFieldGroup(), allPropertyIds, Arrays.asList(SymptomState.YES));
                onsetDateField.setEnabled(isOnsetDateFieldEnabled);
                Date onsetDate = getValue().getOnsetDate();
                if (onsetDate != null) {
                    onsetDateField.setValue(onsetDate);
                } else if (!isOnsetDateFieldEnabled) {
                    onsetDateField.setValue(null);
                }
            }
            onsetSymptom.setEnabled(!onsetSymptom.getItemIds().isEmpty());
        });
    }
    // will be updated by listener if needed
    onsetSymptom.setEnabled(false);
    // will be updated by listener if needed
    onsetDateField.setEnabled(false);
}
Also used : AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) Date(java.util.Date)

Example 22 with Field

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

the class SymptomsForm method addSoftRequiredStyleWhenSymptomaticAndCooperative.

/**
 * 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.
 */
@SuppressWarnings("rawtypes")
private void addSoftRequiredStyleWhenSymptomaticAndCooperative(FieldGroup fieldGroup, Object targetPropertyId, List<String> sourcePropertyIds, List<Object> sourceValues, NullableOptionGroup 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.getNullableValue() == 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);
                }
            }
        });
    }
}
Also used : AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) AbstractField(com.vaadin.v7.ui.AbstractField)

Example 23 with Field

use of com.vaadin.v7.ui.Field 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 24 with Field

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

the class AbstractEditForm method addInfrastructureField.

protected ComboBox addInfrastructureField(String fieldId) {
    ComboBox field = addField(fieldId, ComboBox.class);
    // Make sure that the ComboBox still contains a pre-selected inactive infrastructure entity
    field.addValueChangeListener(e -> {
        InfrastructureDataReferenceDto value = (InfrastructureDataReferenceDto) e.getProperty().getValue();
        if (value != null && !field.containsId(value)) {
            InfrastructureDataReferenceDto inactiveValue = value.clone();
            inactiveValue.setCaption(value.getCaption() + " (" + I18nProperties.getString(Strings.inactive) + ")");
            field.addItem(inactiveValue);
        }
    });
    return field;
}
Also used : ComboBox(com.vaadin.v7.ui.ComboBox) InfrastructureDataReferenceDto(de.symeda.sormas.api.InfrastructureDataReferenceDto)

Example 25 with Field

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

the class AbstractFilterForm method clearAndDisableFields.

protected void clearAndDisableFields(Field... fields) {
    for (Field field : fields) {
        if (field != null) {
            field.setValue(null);
            field.setEnabled(false);
        }
    }
}
Also used : Field(com.vaadin.v7.ui.Field) AbstractTextField(com.vaadin.v7.ui.AbstractTextField) PopupDateField(com.vaadin.v7.ui.PopupDateField)

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