Search in sources :

Example 1 with IBeanPropertyValidator

use of org.jowidgets.cap.ui.api.bean.IBeanPropertyValidator in project jo-client-platform by jo-source.

the class BeanLinkCreatorCommand method createDefaultBean.

private <BEAN_TYPE> IBeanProxy<BEAN_TYPE> createDefaultBean(final IBeanFormBluePrint<BEAN_TYPE> formBp, final Object beanTypeId, final Class<? extends BEAN_TYPE> beanType, final List<IBeanPropertyValidator<BEAN_TYPE>> validators) {
    if (formBp != null) {
        final HashMap<String, Object> defaultValues = new HashMap<String, Object>();
        final LinkedList<String> properties = new LinkedList<String>();
        final Collection<IAttribute<?>> attributes = formBp.getCreateModeAttributes();
        final IAttributeSet attributeSet = AttributeSet.create(attributes);
        for (final IAttribute<?> attribute : attributes) {
            final String propertyName = attribute.getPropertyName();
            properties.add(propertyName);
            final Object defaultValue = attribute.getDefaultValue();
            if (defaultValue != null) {
                defaultValues.put(propertyName, defaultValue);
            }
        }
        final List<IBeanPropertyValidator<BEAN_TYPE>> propertyValidators = createBeanPropertyValidators(attributes);
        if (!EmptyCheck.isEmpty(validators)) {
            propertyValidators.addAll(validators);
        }
        @SuppressWarnings("unchecked") final IBeanProxyFactory<BEAN_TYPE> proxyFactory = BeanProxyFactory.builder((Class<BEAN_TYPE>) beanType).setBeanTypeId(beanTypeId).setAttributes(attributeSet).setBeanPropertyValidators(propertyValidators).build();
        return proxyFactory.createTransientProxy(defaultValues);
    } else {
        return null;
    }
}
Also used : HashMap(java.util.HashMap) IBeanPropertyValidator(org.jowidgets.cap.ui.api.bean.IBeanPropertyValidator) LinkedList(java.util.LinkedList) IAttribute(org.jowidgets.cap.ui.api.attribute.IAttribute) IAttributeSet(org.jowidgets.cap.ui.api.attribute.IAttributeSet)

Example 2 with IBeanPropertyValidator

use of org.jowidgets.cap.ui.api.bean.IBeanPropertyValidator in project jo-client-platform by jo-source.

the class BeanProxyImplTest method createValidators.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static <BEAN_TYPE> List<IBeanPropertyValidator<BEAN_TYPE>> createValidators(final IBeanDtoDescriptor descriptor, final Collection<IAttribute<Object>> attributes) {
    final List<IBeanPropertyValidator<BEAN_TYPE>> result = new LinkedList<IBeanPropertyValidator<BEAN_TYPE>>();
    result.add(new AttributesBeanPropertyValidator<BEAN_TYPE>(attributes));
    for (final IBeanValidator beanValidator : descriptor.getValidators()) {
        result.add(new BeanPropertyValidatorAdapter<BEAN_TYPE>(beanValidator));
    }
    return result;
}
Also used : IBeanValidator(org.jowidgets.cap.common.api.validation.IBeanValidator) IBeanPropertyValidator(org.jowidgets.cap.ui.api.bean.IBeanPropertyValidator) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)2 IBeanPropertyValidator (org.jowidgets.cap.ui.api.bean.IBeanPropertyValidator)2 HashMap (java.util.HashMap)1 IBeanValidator (org.jowidgets.cap.common.api.validation.IBeanValidator)1 IAttribute (org.jowidgets.cap.ui.api.attribute.IAttribute)1 IAttributeSet (org.jowidgets.cap.ui.api.attribute.IAttributeSet)1