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;
}
}
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);
}
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;
}
Aggregations