Search in sources :

Example 1 with IValidationResult

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

the class BeanSelectionDialogDefaults method initialize.

@Override
public void initialize(final IBeanSelectionDialogBluePrint<?> bluePrint) {
    bluePrint.setContentScrolled(false);
    bluePrint.setContentBorder();
    bluePrint.setMissingInputHint("Bitte wählen Sie einen Datensatz aus");
    bluePrint.setDefaultButtonPolicy(InputDialogDefaultButtonPolicy.DISABLED);
    final IInputComponentValidationLabelBluePrint validationLabelBp = BPF.inputComponentValidationLabel();
    validationLabelBp.setInitialValidationDecorator(new IDecorator<IValidationResult>() {

        @Override
        public IValidationResult decorate(final IValidationResult original) {
            if (!original.isValid()) {
                return original;
            }
            return null;
        }
    });
}
Also used : IValidationResult(org.jowidgets.validation.IValidationResult) IInputComponentValidationLabelBluePrint(org.jowidgets.api.widgets.blueprint.IInputComponentValidationLabelBluePrint)

Example 2 with IValidationResult

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

the class BeansStateTrackerImpl method createValidationResult.

@Override
public IValidationResult createValidationResult() {
    final IValidationResultBuilder builder = ValidationResult.builder();
    for (final IBeanProxy<BEAN_TYPE> bean : new LinkedList<IBeanProxy<BEAN_TYPE>>(validationDirtyBeans)) {
        final IValidationResult validationResult = bean.validate();
        builder.addResult(validationResult);
        if (validationResult.isOk()) {
            validationDirtyBeans.remove(bean);
        } else if (!validationResult.isValid()) {
            break;
        }
    }
    return builder.build();
}
Also used : IValidationResultBuilder(org.jowidgets.validation.IValidationResultBuilder) IValidationResult(org.jowidgets.validation.IValidationResult) LinkedList(java.util.LinkedList)

Example 3 with IValidationResult

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

the class AttributesBeanPropertyValidator method validatePropertyImpl.

private IValidationResult validatePropertyImpl(final IBeanProxy<BEAN_TYPE> bean, final String propertyName) {
    final IValidationResultBuilder builder = ValidationResult.builder();
    final IValidator<Object> validator = validators.get(propertyName);
    if (validator != null) {
        final IValidationResult validationResult = validator.validate(bean.getValue(propertyName));
        if (!validationResult.isValid()) {
            return validationResult;
        } else if (!validationResult.isOk()) {
            builder.addResult(validationResult);
        }
    }
    return builder.build();
}
Also used : IValidationResultBuilder(org.jowidgets.validation.IValidationResultBuilder) IValidationResult(org.jowidgets.validation.IValidationResult)

Example 4 with IValidationResult

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

the class BeanProxyImpl method setValidationResults.

private void setValidationResults(final ValueHolder<IBeanValidationResult> firstWorstIndependendResultHolder, final Collection<IBeanValidationResult> results) {
    if (results.size() > 0) {
        boolean validationChanged = false;
        // set the property dependent results
        for (final IBeanValidationResult result : results) {
            final String propertyName = result.getPropertyName();
            final IValidationResult validationResult = result.getValidationResult();
            final IValidationResult lastResult = validationResults.get(propertyName);
            if (lastResult == null || !validationResult.getWorstFirst().equals(lastResult.getWorstFirst())) {
                if (validationResult.isOk()) {
                    validationResults.remove(propertyName);
                } else {
                    validationResults.put(propertyName, validationResult);
                }
                validationChanged = true;
            }
        }
        // set the property independent result
        final IValidationResult lastIndependentResult = independentWorstResult.get();
        final IBeanValidationResult currentIndependentBeanValidationResult = firstWorstIndependendResultHolder.get();
        if (currentIndependentBeanValidationResult != null) {
            final IValidationResult currentIndependentResult = currentIndependentBeanValidationResult.getValidationResult();
            if (lastIndependentResult == null || !currentIndependentResult.getWorstFirst().equals(lastIndependentResult.getWorstFirst())) {
                independentWorstResult.set(currentIndependentResult);
                validationChanged = true;
            }
        } else if (lastIndependentResult != null) {
            independentWorstResult.set(null);
            validationChanged = true;
        }
        if (validationChanged) {
            fireValidationConditionsChanged();
        }
    }
}
Also used : IBeanValidationResult(org.jowidgets.cap.common.api.validation.IBeanValidationResult) IValidationResult(org.jowidgets.validation.IValidationResult)

Example 5 with IValidationResult

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

the class BeanProxyImplTest method testAllValidatorsForInitialValidPerson.

private void testAllValidatorsForInitialValidPerson(final IBeanProxy<IPerson> personProxy) {
    IValidationResult validationResult = personProxy.validate();
    Assert.assertTrue(validationResult.isOk());
    // make name invalid
    final IPerson person = personProxy.getBean();
    person.setName(PersonNameValidator.FORBIDDEN_NAME);
    validationResult = personProxy.validate();
    IValidationMessage worstFirst = validationResult.getWorstFirst();
    Assert.assertEquals(personAttributes.getAttribute(IPerson.NAME_PROPERTY).getCurrentLabel(), worstFirst.getContext());
    Assert.assertEquals(MessageType.ERROR, worstFirst.getType());
    // make name valid again
    personProxy.undoModifications();
    validationResult = personProxy.validate();
    Assert.assertTrue(validationResult.isOk());
    // make name invalid
    person.setName(null);
    validationResult = personProxy.validate();
    worstFirst = validationResult.getWorstFirst();
    Assert.assertEquals(personAttributes.getAttribute(IPerson.NAME_PROPERTY).getCurrentLabel(), worstFirst.getContext());
    Assert.assertEquals(MessageType.INFO_ERROR, worstFirst.getType());
    // make name valid again
    personProxy.undoModifications();
    validationResult = personProxy.validate();
    Assert.assertTrue(validationResult.isOk());
    // make lastname invalid
    person.setLastname(null);
    validationResult = personProxy.validate();
    worstFirst = validationResult.getWorstFirst();
    Assert.assertEquals(personAttributes.getAttribute(IPerson.LAST_NAME_PROPERTY).getCurrentLabel(), worstFirst.getContext());
    Assert.assertEquals(MessageType.INFO_ERROR, worstFirst.getType());
    // make lastname valid again
    personProxy.undoModifications();
    validationResult = personProxy.validate();
    Assert.assertTrue(validationResult.isOk());
    // make name invalid again
    person.setName(PersonNameValidator.FORBIDDEN_NAME);
    validationResult = personProxy.validate();
    worstFirst = validationResult.getWorstFirst();
    Assert.assertEquals(personAttributes.getAttribute(IPerson.NAME_PROPERTY).getCurrentLabel(), worstFirst.getContext());
    Assert.assertEquals(MessageType.ERROR, worstFirst.getType());
    // modify lastname valid
    person.setLastname("Foo");
    // name must still be invalid
    validationResult = personProxy.validate();
    worstFirst = validationResult.getWorstFirst();
    Assert.assertEquals(personAttributes.getAttribute(IPerson.NAME_PROPERTY).getCurrentLabel(), worstFirst.getContext());
    Assert.assertEquals(MessageType.ERROR, worstFirst.getType());
}
Also used : IPerson(org.jowidgets.cap.ui.impl.beans.IPerson) IValidationMessage(org.jowidgets.validation.IValidationMessage) IValidationResult(org.jowidgets.validation.IValidationResult)

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