Example usage for com.vaadin.ui AbstractField isEmpty

List of usage examples for com.vaadin.ui AbstractField isEmpty

Introduction

In this page you can find the example usage for com.vaadin.ui AbstractField isEmpty.

Prototype

public default boolean isEmpty() 

Source Link

Document

Returns whether this HasValue is considered to be empty.

Usage

From source file:net.sourceforge.javydreamercsw.validation.manager.web.execution.ExecutionWizardStep.java

License:Apache License

@Override
public boolean onAdvance() {
    //Can only proceed after the current step is executed and documented.
    String answer = ((String) result.getValue());
    String answer2 = ((String) review.getValue());
    boolean pass = true;
    if (answer == null) {
        Notification.show(TRANSLATOR.translate("unable.to.proceed"), result.getRequiredError(),
                Notification.Type.WARNING_MESSAGE);
    } else if (reviewer && answer2 == null) {
        Notification.show(TRANSLATOR.translate("unable.to.proceed"), review.getRequiredError(),
                Notification.Type.WARNING_MESSAGE);
    } else {//ww w  . j  av a2 s  .com
        //Check all fields for answers
        for (AbstractField field : fields) {
            if (field.isRequired() && !(field instanceof CheckBox) && field.isEmpty()) {
                Notification.show(TRANSLATOR.translate("unable.to.proceed"), field.getRequiredError(),
                        Notification.Type.WARNING_MESSAGE);
                pass = false;
            }
        }
        if (pass) {
            try {
                //Save the result
                ExecutionResult newResult = ExecutionResultServer.getResult(answer);
                ReviewResult newReview = ReviewResultServer.getReview(answer2);
                getExecutionStep().setExecutionStart(start.getValue());
                if (getExecutionStep().getResultId() == null
                        || !Objects.equals(getExecutionStep().getResultId().getId(), newResult.getId())) {
                    getExecutionStep().setResultId(newResult);
                    //Set end date to null to reflect update
                    getExecutionStep().setExecutionEnd(null);
                }
                if (reviewer && (getExecutionStep().getReviewResultId() == null || !Objects
                        .equals(getExecutionStep().getReviewResultId().getId(), newReview.getId()))) {
                    getExecutionStep().setReviewResultId(newReview);
                    getExecutionStep().setReviewer(ValidationManagerUI.getInstance().getUser());
                }
                if (getExecutionStep().getExecutionEnd() == null) {
                    getExecutionStep().setExecutionEnd(new Date());
                }
                if (reviewer && getExecutionStep().getReviewDate() == null) {
                    getExecutionStep().setReviewDate(new Date());
                }
                if (getExecutionStep().getExecutionStepAnswerList() == null) {
                    getExecutionStep().setExecutionStepAnswerList(new ArrayList<>());
                }
                if (getExecutionStep().getExecutionStepHasVmUserList() == null) {
                    getExecutionStep().setExecutionStepHasVmUserList(new ArrayList<>());
                }
                getExecutionStep().getExecutionStepAnswerList().clear();
                for (AbstractField field : fields) {
                    //The field has the field name as data
                    if (field.getData() == null) {
                        pass = false;
                        LOG.log(Level.SEVERE, "Field missing data! {0}", field);
                    } else {
                        String fieldName = (String) field.getData();
                        ExecutionStepAnswer stepAnswer = new ExecutionStepAnswer(
                                getExecutionStep().getExecutionStepPK().getTestCaseExecutionId(),
                                getExecutionStep().getExecutionStepPK().getStepId(),
                                getExecutionStep().getExecutionStepPK().getStepTestCaseId());
                        stepAnswer.setExecutionStep(getExecutionStep().getEntity());
                        stepAnswer.setFieldName(fieldName);
                        stepAnswer.setFieldAnswer(field.getValue().toString());
                        getExecutionStep().getExecutionStepAnswerList().add(stepAnswer);
                    }
                }
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, null, ex);
            }
        }
    }
    boolean validAnswer = result.getValue() != null && !((String) result.getValue()).trim().isEmpty();
    boolean validReview = review.getValue() != null && !((String) review.getValue()).trim().isEmpty();
    return reviewer ? validReview && validAnswer : validAnswer && pass;
}

From source file:org.vaadin.viritin.MBeanFieldGroup.java

License:Apache License

/**
 * This method hides validation errors on a required fields until the field
 * has been changed for the first time. Does pretty much the same as old
 * Vaadin Form did with its validationVisibleOnCommit, but eagerly per
 * field.//w  ww .j  av  a  2 s  . c  om
 * <p>
 * Fields that hide validation errors this way are available in
 * getFieldsWithIntiallyDisabledValidation() so they can be emphasized in
 * UI.
 */
public void hideInitialEmpyFieldValidationErrors() {
    fieldsWithInitiallyDisabledValidation.clear();
    for (Field f : getFields()) {
        if (f instanceof AbstractField) {
            final AbstractField abstractField = (AbstractField) f;
            if (abstractField.getErrorMessage() != null && abstractField.isRequired() && abstractField.isEmpty()
                    && abstractField.isValidationVisible()) {
                final String propertyId = getPropertyId(abstractField).toString();
                abstractField.setValidationVisible(false);
                fieldsWithInitiallyDisabledValidation.add(propertyId);
            }
        }
    }
}