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);
}
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);
}
}
});
}
}
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();
}
}
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;
}
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);
}
}
}
Aggregations