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 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 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 opencms-core by alkacon.
the class CmsOUEditDialog method validate.
/**
* Adds validators to fields.<p>
*/
@SuppressWarnings("unchecked")
protected void validate() {
if (m_ou == null) {
m_name.removeAllValidators();
m_name.addValidator(new NameValidator());
}
m_description.setRequired(true);
m_description.setRequiredError("Required");
if (m_ouResources.getRows().isEmpty() & !m_webuser.getValue().booleanValue()) {
CmsPathSelectField field = new CmsPathSelectField();
field.setUseRootPaths(true);
field.setCmsObject(m_cms);
m_ouResources.addRow(field);
}
for (I_CmsEditableGroupRow row : m_ouResources.getRows()) {
((AbstractField<String>) row.getComponent()).removeAllValidators();
((AbstractField<String>) row.getComponent()).addValidator(new ResourceValidator());
}
}
Aggregations