use of com.vaadin.v7.ui.AbstractField 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());
});
}));
}
use of com.vaadin.v7.ui.AbstractField 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.AbstractField in project SORMAS-Project by hzi-braunschweig.
the class SormasErrorHandler method handleError.
public static void handleError(ErrorEvent event) {
Logger logger = LoggerFactory.getLogger(SormasErrorHandler.class);
final Throwable t = event.getThrowable();
if (t instanceof SocketException) {
// Most likely client browser closed socket
logger.info("SocketException in CommunicationManager." + " Most likely client (browser) closed socket.");
return;
}
ErrorMessage errorMessage = getErrorMessageForException(t);
if (t != null) {
// log the error or warning
if (errorMessage instanceof SystemError) {
logger.error(getMessage(t), t);
} else {
logger.warn(t.getMessage(), t);
}
}
// finds the original source of the error/exception
AbstractComponent component = DefaultErrorHandler.findAbstractComponent(event);
if (errorMessage != null && component != null) {
// Shows the error in AbstractComponent
if (errorMessage instanceof SystemError) {
Notification.show(I18nProperties.getString(Strings.errorOccurred, I18nProperties.getString(Strings.errorOccurred)), I18nProperties.getString(Strings.errorWasReported), Notification.Type.ERROR_MESSAGE);
} else {
// to prevent the original message from appearing, if necessary
if (component instanceof AbstractField<?>) {
((AbstractField<?>) component).setCurrentBufferedSourceException(null);
}
Notification notification = new Notification(I18nProperties.getString(Strings.errorProblemOccurred, I18nProperties.getString(Strings.errorProblemOccurred)), errorMessage.getFormattedHtmlMessage(), Notification.Type.WARNING_MESSAGE, true);
notification.setDelayMsec(-1);
notification.show(Page.getCurrent());
component.setComponentError(errorMessage);
}
}
}
use of com.vaadin.v7.ui.AbstractField in project SORMAS-Project by hzi-braunschweig.
the class FieldHelper method setReadOnlyWhen.
@SuppressWarnings("rawtypes")
public static void setReadOnlyWhen(final FieldGroup fieldGroup, List<?> targetPropertyIds, Object sourcePropertyId, final List<?> sourceValues, final boolean clearOnReadOnly, boolean readOnlyWhenNull) {
Field sourceField = fieldGroup.getField(sourcePropertyId);
if (sourceField instanceof AbstractField<?>) {
((AbstractField) sourceField).setImmediate(true);
}
// initialize
{
boolean readOnly;
if (getNullableSourceFieldValue(sourceField) == null) {
readOnly = readOnlyWhenNull;
} else {
readOnly = sourceValues.contains(getNullableSourceFieldValue(sourceField));
}
for (Object targetPropertyId : targetPropertyIds) {
Field targetField = fieldGroup.getField(targetPropertyId);
if (readOnly && clearOnReadOnly && targetField.getValue() != null) {
targetField.setReadOnly(false);
targetField.clear();
}
targetField.setReadOnly(readOnly);
if (readOnly) {
// workaround to make sure the caption also knows the field is read-only
targetField.addStyleName("v-readonly");
} else {
targetField.removeStyleName("v-readonly");
}
}
}
sourceField.addValueChangeListener(event -> {
boolean readOnly;
if (getNullableSourceFieldValue(sourceField) == null) {
readOnly = readOnlyWhenNull;
} else {
readOnly = sourceValues.contains(getNullableSourceFieldValue(((Field) event.getProperty())));
}
for (Object targetPropertyId : targetPropertyIds) {
Field targetField = fieldGroup.getField(targetPropertyId);
if (readOnly && clearOnReadOnly && targetField.getValue() != null) {
targetField.setReadOnly(false);
targetField.clear();
}
targetField.setReadOnly(readOnly);
if (readOnly) {
// workaround to make sure the caption also knows the field is read-only
targetField.addStyleName("v-readonly");
} else {
targetField.removeStyleName("v-readonly");
}
}
});
}
use of com.vaadin.v7.ui.AbstractField in project SORMAS-Project by hzi-braunschweig.
the class ContactCreateForm method addFields.
@Override
protected void addFields() {
if (hasCaseRelation == null) {
return;
}
reportDate = addField(ContactDto.REPORT_DATE_TIME, DateField.class);
ComboBox cbDisease = addDiseaseField(ContactDto.DISEASE, false, true);
addField(ContactDto.DISEASE_DETAILS, TextField.class);
personCreateForm = new PersonCreateForm(false, false, false, showPersonSearchButton);
personCreateForm.setWidth(100, Unit.PERCENTAGE);
personCreateForm.setValue(new PersonDto());
getContent().addComponent(personCreateForm, ContactDto.PERSON);
addField(ContactDto.RETURNING_TRAVELER, NullableOptionGroup.class);
ComboBox region = addInfrastructureField(ContactDto.REGION);
ComboBox district = addInfrastructureField(ContactDto.DISTRICT);
ComboBox community = addInfrastructureField(ContactDto.COMMUNITY);
multiDayContact = addField(ContactDto.MULTI_DAY_CONTACT, CheckBox.class);
firstContactDate = addField(ContactDto.FIRST_CONTACT_DATE, DateField.class);
lastContactDate = addField(ContactDto.LAST_CONTACT_DATE, DateField.class);
firstContactDate.addValueChangeListener(event -> lastContactDate.setRequired(event.getProperty().getValue() != null));
multiDayContact.addValueChangeListener(event -> updateDateComparison());
List<AbstractField<Date>> validatedFields = Arrays.asList(firstContactDate, lastContactDate, reportDate);
validatedFields.forEach(field -> field.addValueChangeListener(r -> {
validatedFields.forEach(otherField -> {
otherField.setValidationVisible(!otherField.isValid());
});
}));
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.FIRST_CONTACT_DATE, ContactDto.MULTI_DAY_CONTACT, Collections.singletonList(true), true);
updateDateComparison();
contactProximity = addField(ContactDto.CONTACT_PROXIMITY, NullableOptionGroup.class);
contactProximity.removeStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
if (isConfiguredServer(CountryHelper.COUNTRY_CODE_GERMANY)) {
contactProximity.addValueChangeListener(e -> updateContactCategory((ContactProximity) contactProximity.getNullableValue()));
contactProximityDetails = addField(ContactDto.CONTACT_PROXIMITY_DETAILS, TextField.class);
contactCategory = addField(ContactDto.CONTACT_CATEGORY, NullableOptionGroup.class);
}
addField(ContactDto.DESCRIPTION, TextArea.class).setRows(4);
ComboBox relationToCase = addField(ContactDto.RELATION_TO_CASE, ComboBox.class);
addField(ContactDto.RELATION_DESCRIPTION, TextField.class);
addField(ContactDto.CASE_ID_EXTERNAL_SYSTEM, TextField.class);
addField(ContactDto.CASE_OR_EVENT_INFORMATION, TextArea.class).setRows(4);
CssStyles.style(CssStyles.SOFT_REQUIRED, firstContactDate, lastContactDate, contactProximity, relationToCase);
region.addValueChangeListener(e -> {
RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(district, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
});
region.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
district.addValueChangeListener(e -> {
DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
FieldHelper.updateItems(community, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
});
setRequired(true, ContactDto.REPORT_DATE_TIME);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.RELATION_DESCRIPTION, ContactDto.RELATION_TO_CASE, Arrays.asList(ContactRelation.OTHER), true);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.DISEASE_DETAILS, ContactDto.DISEASE, Arrays.asList(Disease.OTHER), true);
FieldHelper.setRequiredWhen(getFieldGroup(), ContactDto.DISEASE, Arrays.asList(ContactDto.DISEASE_DETAILS), Arrays.asList(Disease.OTHER));
cbDisease.addValueChangeListener(e -> {
disease = (Disease) e.getProperty().getValue();
setVisible(disease != null, ContactDto.CONTACT_PROXIMITY);
if (isConfiguredServer("de")) {
contactCategory.setVisible(disease != null);
contactProximityDetails.setVisible(disease != null);
}
updateContactProximity();
});
if (!hasCaseRelation) {
Label caseInfoLabel = new Label(I18nProperties.getString(Strings.infoNoSourceCaseSelected), ContentMode.HTML);
Button chooseCaseButton = ButtonHelper.createButton(Captions.contactChooseCase, null, ValoTheme.BUTTON_PRIMARY, CssStyles.VSPACE_2);
Button removeCaseButton = ButtonHelper.createButton(Captions.contactRemoveCase, null, ValoTheme.BUTTON_LINK);
CssStyles.style(caseInfoLabel, CssStyles.VSPACE_TOP_4);
getContent().addComponent(caseInfoLabel, CASE_INFO_LOC);
chooseCaseButton.addClickListener(e -> {
ControllerProvider.getContactController().openSelectCaseForContactWindow((Disease) cbDisease.getValue(), selectedCase -> {
if (selectedCase != null) {
caseInfoLabel.setValue(String.format(I18nProperties.getString(Strings.infoContactCreationSourceCase), selectedCase.getPersonFirstName() + " " + selectedCase.getPersonLastName() + " " + "(" + DataHelper.getShortUuid(selectedCase.getUuid()) + ")"));
caseInfoLabel.removeStyleName(CssStyles.VSPACE_TOP_4);
removeCaseButton.setVisible(true);
chooseCaseButton.setCaption(I18nProperties.getCaption(Captions.contactChangeCase));
getValue().setCaze(selectedCase.toReference());
cbDisease.setValue(selectedCase.getDisease());
updateFieldVisibilitiesByCase(true);
}
});
});
getContent().addComponent(chooseCaseButton, CHOOSE_CASE_LOC);
removeCaseButton.addClickListener(e -> {
getValue().setCaze(null);
cbDisease.setValue(null);
caseInfoLabel.setValue(I18nProperties.getString(Strings.infoNoSourceCaseSelected));
caseInfoLabel.addStyleName(CssStyles.VSPACE_TOP_4);
removeCaseButton.setVisible(false);
chooseCaseButton.setCaption(I18nProperties.getCaption(Captions.contactChooseCase));
updateFieldVisibilitiesByCase(false);
});
getContent().addComponent(removeCaseButton, REMOVE_CASE_LOC);
removeCaseButton.setVisible(false);
}
if (asSourceContact) {
setEnabled(false, ContactDto.DISEASE, ContactDto.DISEASE_DETAILS);
}
addValueChangeListener(e -> {
updateFieldVisibilitiesByCase(hasCaseRelation);
if (!hasCaseRelation && disease == null) {
setVisible(false, ContactDto.CONTACT_PROXIMITY);
if (isConfiguredServer("de")) {
contactCategory.setVisible(false);
contactProximityDetails.setVisible(false);
}
}
updateContactProximity();
if (asSourceContact) {
personCreateForm.setVisible(false);
personCreateForm.enablePersonFields(false);
TextField personNameField = addCustomField(PERSON_NAME_LOC, String.class, TextField.class);
personNameField.setCaption(I18nProperties.getPrefixCaption(ContactDto.I18N_PREFIX, ContactDto.PERSON));
personNameField.setValue(getValue().getPerson().getCaption());
personNameField.setReadOnly(true);
}
});
}
Aggregations