Search in sources :

Example 1 with IAttributeSet

use of org.jowidgets.cap.ui.api.attribute.IAttributeSet 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 IAttributeSet

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

the class BeanProxyFactoryBuilderImpl method addValidators.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void addValidators(final IBeanDtoDescriptor dtoDescriptor, final IAttributeSet attributes) {
    addBeanPropertyValidator(attributes);
    final Set beanValidators = dtoDescriptor.getValidators();
    addBeanPropertyValidator(beanValidators);
}
Also used : IAttributeSet(org.jowidgets.cap.ui.api.attribute.IAttributeSet) Set(java.util.Set) AttributeSet(org.jowidgets.cap.ui.api.attribute.AttributeSet)

Example 3 with IAttributeSet

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

the class BeanProxyFactoryBuilderImpl method configureFromEntityService.

@Override
public IBeanProxyFactoryBuilder<BEAN_TYPE> configureFromEntityService(final Object entityId) {
    final IBeanDtoDescriptor dtoDescriptor = EntityServiceHelper.getDtoDescriptor(entityId);
    final List<IAttribute<Object>> entityAttributes = EntityServiceHelper.createAttributes(entityId);
    if (dtoDescriptor != null && entityAttributes != null) {
        final Class<?> descritporBeanType = dtoDescriptor.getBeanType();
        if (descritporBeanType == null || !descritporBeanType.isAssignableFrom(beanType)) {
            throw new IllegalArgumentException("The entity id '" + entityId + "' has a bean type '" + descritporBeanType + "' that is not compatible with the bean type '" + beanType + "' of this builder");
        }
        setBeanTypeId(dtoDescriptor.getBeanTypeId());
        final IAttributeSet attributeSet = AttributeSet.create(entityAttributes);
        setAttributes(attributeSet);
        addValidators(dtoDescriptor, attributeSet);
        setDefaultValuesForTransientBeans(attributeSet);
    } else {
        throw new IllegalArgumentException("TFor the entity id '" + entityId + "' no descriptor or attributes was found");
    }
    return this;
}
Also used : IBeanDtoDescriptor(org.jowidgets.cap.common.api.bean.IBeanDtoDescriptor) IAttribute(org.jowidgets.cap.ui.api.attribute.IAttribute) IAttributeSet(org.jowidgets.cap.ui.api.attribute.IAttributeSet)

Aggregations

IAttributeSet (org.jowidgets.cap.ui.api.attribute.IAttributeSet)3 IAttribute (org.jowidgets.cap.ui.api.attribute.IAttribute)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 IBeanDtoDescriptor (org.jowidgets.cap.common.api.bean.IBeanDtoDescriptor)1 AttributeSet (org.jowidgets.cap.ui.api.attribute.AttributeSet)1 IBeanPropertyValidator (org.jowidgets.cap.ui.api.bean.IBeanPropertyValidator)1