Example usage for com.vaadin.ui AbstractField getData

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

Introduction

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

Prototype

public Object getData() 

Source Link

Document

Gets the application specific data.

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 {//from   www.  j a v a  2 s .c  om
        //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:net.sourceforge.javydreamercsw.validation.manager.web.execution.ExecutionWizardStep.java

License:Apache License

private void updateValue(AbstractField field) {
    if (field.getData() != null) {
        //Look for the answer in the database
        getExecutionStep().getExecutionStepAnswerList().forEach(answer -> {
            if (answer.getFieldName().equals(field.getData())) {
                if (field instanceof AbstractTextField) {//This includes NumberField
                    field.setValue(answer.getFieldAnswer());
                } else if (field instanceof CheckBox) {
                    field.setValue(answer.getFieldAnswer().equals("true"));
                }/* ww w.ja  v a2  s  .co m*/
            }
        });
    } else {
        LOG.log(Level.SEVERE, "Field missing data! {0}", field);
    }
}