Search in sources :

Example 11 with IValidationResult

use of org.jowidgets.validation.IValidationResult in project jo-client-platform by jo-source.

the class BeanDialogImpl method setOkButtonEnabledState.

private void setOkButtonEnabledState() {
    final IValidationResult validationResult = beanForm.validate();
    final IBeanProxy<BEAN_TYPE> bean = beanForm.getValue();
    if (validationResult.isValid()) {
        if (!bean.isTransient() && !bean.hasModifications()) {
            okButton.setToolTipText(NO_MODIFICATIONS.get());
            okButton.setEnabled(false);
        } else {
            okButton.setToolTipText(okButtonTooltip);
            okButton.setEnabled(true);
        }
    } else {
        okButton.setToolTipText(validationResult.getWorstFirst().getText());
        okButton.setEnabled(false);
    }
}
Also used : IValidationResult(org.jowidgets.validation.IValidationResult)

Example 12 with IValidationResult

use of org.jowidgets.validation.IValidationResult in project jo-client-platform by jo-source.

the class BeanFormControl method validate.

private IBeanValidationResult validate(final IBeanValidationResult parentResult) {
    final String propertyName = parentResult.getPropertyName();
    final IValidationResult parentValidationResult = parentResult.getValidationResult();
    boolean validationChanged = false;
    IValidationResult validationResult = ValidationResult.ok();
    final IInputControl<?> control = controls.get(propertyName);
    final String propertyLabel = getLabel(propertyName);
    if (bean != null && control != null && EmptyCompatibleEquivalence.equals(control.getValue(), bean.getValue(propertyName))) {
        validationResult = control.validate();
        // use the parent result if the control result is valid and the parent result is not valid
        if (validationResult.isValid() && !parentValidationResult.isValid()) {
            validationResult = parentValidationResult;
        } else if (validationResult.isOk() && !parentValidationResult.isOk()) {
            validationResult = parentValidationResult;
        }
        // change the validation map, if the worst first changed
        final IValidationResult lastResult = validationResults.get(propertyName);
        if (lastResult == null || !validationResult.getWorstFirst().equals(lastResult.getWorstFirst())) {
            boolean hasMessage = false;
            boolean hasHint = false;
            final IAttribute<Object> attribute = attributes.get(propertyName);
            if (!validationResult.isValid() && !control.hasModifications() && !bean.isModified(propertyName) && inputHint != null && attribute != null && attribute.isMandatory() && EmptyCheck.isEmpty(bean.getValue(propertyName))) {
                validationResults.put(propertyName, ValidationResult.infoError(inputHint));
                hasHint = true;
            } else {
                validationResults.put(propertyName, validationResult.withContext(propertyLabel));
                hasMessage = validationResult.getWorstFirst().getType() != MessageType.OK;
            }
            validationChanged = true;
            // update the validation label
            final IValidationResultLabel validationLabel = validationLabels.get(propertyName);
            if (validationLabel != null) {
                if (hasMessage || control.hasModifications() || bean.isModified(propertyName)) {
                    if (!hasHint) {
                        validationLabel.setResult(validationResult);
                    }
                } else {
                    validationLabel.setEmpty();
                }
            }
        }
    } else if (bean != null && control == null) {
        // change the validation map, if the worst first changed
        validationResult = parentValidationResult;
        final IValidationResult lastResult = validationResults.get(propertyName);
        if (lastResult == null || !validationResult.getWorstFirst().equals(lastResult.getWorstFirst())) {
            if (propertyLabel != null) {
                validationResults.put(propertyName, validationResult.withContext(propertyLabel));
            } else {
                validationResults.put(propertyName, validationResult);
            }
            validationChanged = true;
        }
    }
    if (validationChanged) {
        final IValidationResult newValidationResult = validationResult;
        return new IBeanValidationResult() {

            @Override
            public IValidationResult getValidationResult() {
                return newValidationResult.withContext(propertyLabel);
            }

            @Override
            public String getPropertyName() {
                return propertyName;
            }
        };
    } else {
        return null;
    }
}
Also used : IBeanValidationResult(org.jowidgets.cap.common.api.validation.IBeanValidationResult) IValidationResult(org.jowidgets.validation.IValidationResult) IValidationResultLabel(org.jowidgets.api.widgets.IValidationResultLabel)

Example 13 with IValidationResult

use of org.jowidgets.validation.IValidationResult in project jo-client-platform by jo-source.

the class BeanFormDefaults method initialize.

@Override
public void initialize(final IBeanFormBluePrint<?> bluePrint) {
    bluePrint.setAutoResetValidation(true);
    bluePrint.setCreateModeForegroundColor(Colors.GREEN);
    bluePrint.setModifiedForegroundColor(Colors.STRONG);
    bluePrint.setScrollbarsAllowed(true);
    final IInputComponentValidationLabelBluePrint editModeValidationLabel = BPF.inputComponentValidationLabel();
    final IDecorator<IValidationResult> editModeValidationDecorator = new IDecorator<IValidationResult>() {

        @Override
        public IValidationResult decorate(final IValidationResult original) {
            if (original != null) {
                final IValidationMessage worstFirst = original.getWorstFirst();
                if (worstFirst != null && worstFirst.getType().equalOrWorse(MessageType.WARNING)) {
                    return original;
                }
            }
            return null;
        }
    };
    editModeValidationLabel.setInitialValidationDecorator(editModeValidationDecorator);
    editModeValidationLabel.setUnmodifiedValidationDecorator(editModeValidationDecorator);
    editModeValidationLabel.setEmptyIcon(IconsSmall.OK_GREYED);
    bluePrint.setEditModeValidationLabel(editModeValidationLabel);
    final IInputComponentValidationLabelBluePrint createModeValidationLabel = BPF.inputComponentValidationLabel();
    final IDecorator<IValidationResult> createModeValidationDecorator = new IDecorator<IValidationResult>() {

        @Override
        public IValidationResult decorate(final IValidationResult original) {
            if (original != null) {
                final IValidationMessage worstFirst = original.getWorstFirst();
                if (worstFirst != null && worstFirst.getType().equalOrWorse(MessageType.WARNING)) {
                    return original;
                }
            }
            return null;
        }
    };
    createModeValidationLabel.setInitialValidationDecorator(createModeValidationDecorator);
    createModeValidationLabel.setUnmodifiedValidationDecorator(createModeValidationDecorator);
    bluePrint.setCreateModeValidationLabel(createModeValidationLabel);
    bluePrint.setCreateModeInputHint(Messages.getString("BeanFormDefaults.fill_out_mandatory_fields"));
    bluePrint.setMandatoryBackgroundColor(CapColors.MANDATORY_BACKGROUND);
    bluePrint.setMandatoryLabelDecorator(new IDecorator<String>() {

        @Override
        public String decorate(final String original) {
            if (original != null) {
                return original + "*";
            }
            return null;
        }
    });
    bluePrint.setPropertyValidationLabel(BPF.validationResultLabel().setShowValidationMessage(false));
}
Also used : IValidationMessage(org.jowidgets.validation.IValidationMessage) IValidationResult(org.jowidgets.validation.IValidationResult) IInputComponentValidationLabelBluePrint(org.jowidgets.api.widgets.blueprint.IInputComponentValidationLabelBluePrint) IDecorator(org.jowidgets.util.IDecorator)

Aggregations

IValidationResult (org.jowidgets.validation.IValidationResult)13 IValidationMessage (org.jowidgets.validation.IValidationMessage)5 IPerson (org.jowidgets.cap.ui.impl.beans.IPerson)4 IValidationResultBuilder (org.jowidgets.validation.IValidationResultBuilder)3 Test (org.junit.Test)3 IInputComponentValidationLabelBluePrint (org.jowidgets.api.widgets.blueprint.IInputComponentValidationLabelBluePrint)2 IBeanValidationResult (org.jowidgets.cap.common.api.validation.IBeanValidationResult)2 LinkedList (java.util.LinkedList)1 IValidationResultLabel (org.jowidgets.api.widgets.IValidationResultLabel)1 IDecorator (org.jowidgets.util.IDecorator)1