Search in sources :

Example 1 with AbstractField

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);
        }
    }
}
Also used : SocketException(java.net.SocketException) AbstractComponent(com.vaadin.ui.AbstractComponent) SystemError(com.vaadin.server.SystemError) AbstractField(com.vaadin.v7.ui.AbstractField) Logger(org.slf4j.Logger) ErrorMessage(com.vaadin.server.ErrorMessage) Notification(com.vaadin.ui.Notification)

Example 2 with AbstractField

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());
        });
    }));
}
Also used : FeatureType(de.symeda.sormas.api.feature.FeatureType) AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) Arrays(java.util.Arrays) AbstractField(com.vaadin.v7.ui.AbstractField) Date(java.util.Date) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) SpecimenCondition(de.symeda.sormas.api.sample.SpecimenCondition) HSPACE_RIGHT_4(de.symeda.sormas.ui.utils.CssStyles.HSPACE_RIGHT_4) CssStyles(de.symeda.sormas.ui.utils.CssStyles) VSPACE_4(de.symeda.sormas.ui.utils.CssStyles.VSPACE_4) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) UserProvider(de.symeda.sormas.ui.UserProvider) Property(com.vaadin.v7.data.Property) ComboBox(com.vaadin.v7.ui.ComboBox) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) List(java.util.List) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) TextField(com.vaadin.v7.ui.TextField) Descriptions(de.symeda.sormas.api.i18n.Descriptions) AdditionalTestType(de.symeda.sormas.api.sample.AdditionalTestType) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) VSPACE_TOP_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_TOP_3) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) FacadeProvider(de.symeda.sormas.api.FacadeProvider) DateFormatHelper(de.symeda.sormas.ui.utils.DateFormatHelper) CssLayout(com.vaadin.ui.CssLayout) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) OptionGroup(com.vaadin.v7.ui.OptionGroup) LayoutUtil.loc(de.symeda.sormas.ui.utils.LayoutUtil.loc) LayoutUtil.locCss(de.symeda.sormas.ui.utils.LayoutUtil.locCss) Label(com.vaadin.ui.Label) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) Validations(de.symeda.sormas.api.i18n.Validations) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) UserRight(de.symeda.sormas.api.user.UserRight) Disease(de.symeda.sormas.api.Disease) SampleDto(de.symeda.sormas.api.sample.SampleDto) TextArea(com.vaadin.v7.ui.TextArea) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) SamplingReason(de.symeda.sormas.api.sample.SamplingReason) AbstractField(com.vaadin.v7.ui.AbstractField) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) DateField(com.vaadin.v7.ui.DateField) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator)

Example 3 with AbstractField

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);
                }
            }
        });
    }
}
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 4 with AbstractField

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");
            }
        }
    });
}
Also used : AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field) AbstractField(com.vaadin.v7.ui.AbstractField)

Example 5 with AbstractField

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());
    }
}
Also used : AbstractField(com.vaadin.v7.ui.AbstractField) CmsPathSelectField(org.opencms.ui.components.fileselect.CmsPathSelectField) I_CmsEditableGroupRow(org.opencms.ui.components.editablegroup.I_CmsEditableGroupRow)

Aggregations

AbstractField (com.vaadin.v7.ui.AbstractField)11 Field (com.vaadin.v7.ui.Field)5 Component (com.vaadin.ui.Component)4 CmsRemovableFormRow (org.opencms.ui.components.CmsRemovableFormRow)4 DateField (com.vaadin.v7.ui.DateField)2 TextField (com.vaadin.v7.ui.TextField)2 ErrorMessage (com.vaadin.server.ErrorMessage)1 SystemError (com.vaadin.server.SystemError)1 UserError (com.vaadin.server.UserError)1 AbstractComponent (com.vaadin.ui.AbstractComponent)1 CssLayout (com.vaadin.ui.CssLayout)1 Label (com.vaadin.ui.Label)1 Notification (com.vaadin.ui.Notification)1 Property (com.vaadin.v7.data.Property)1 CheckBox (com.vaadin.v7.ui.CheckBox)1 ComboBox (com.vaadin.v7.ui.ComboBox)1 OptionGroup (com.vaadin.v7.ui.OptionGroup)1 TextArea (com.vaadin.v7.ui.TextArea)1 Disease (de.symeda.sormas.api.Disease)1 FacadeProvider (de.symeda.sormas.api.FacadeProvider)1