public void toForm(String name, Attribute<?> attribute) {
AttributeInfo info = attributeInfoMap.get(name);
if (info == null || !isIncluded(info)) {
return;
}
FormItem item = formWidget.getField(info.getName());
if (item != null) {
if (info instanceof PrimitiveAttributeInfo) {
PrimitiveAttribute<?> primitive = (PrimitiveAttribute<?>) attribute;
if (attribute == null) {
item.setDisabled(true);
} else {
switch (primitive.getType()) {
case BOOLEAN:
setValue(info.getName(), (BooleanAttribute) primitive); // NOSONAR valid cast
break;
case SHORT:
setValue(info.getName(), (ShortAttribute) primitive); // NOSONAR valid cast
break;
case INTEGER:
setValue(info.getName(), (IntegerAttribute) primitive); // NOSONAR valid cast
break;
case LONG:
setValue(info.getName(), (LongAttribute) primitive); // NOSONAR valid cast
break;
case FLOAT:
setValue(info.getName(), (FloatAttribute) primitive); // NOSONAR valid cast
break;
case DOUBLE:
setValue(info.getName(), (DoubleAttribute) primitive); // NOSONAR valid cast
break;
case CURRENCY:
setValue(info.getName(), (CurrencyAttribute) primitive); // NOSONAR valid cast
break;
case STRING:
setValue(info.getName(), (StringAttribute) primitive); // NOSONAR valid cast
break;
case URL:
setValue(info.getName(), (UrlAttribute) primitive); // NOSONAR valid cast
break;
case IMGURL:
setValue(info.getName(), (ImageUrlAttribute) primitive); // NOSONAR valid cast
break;
case DATE:
setValue(info.getName(), (DateAttribute) primitive); // NOSONAR valid cast
break;
default:
throw new IllegalStateException("Unhandled primitive attribute type " +
primitive.getType());
}
}
} else if (info instanceof AssociationAttributeInfo) {
Object associationItem = item.getAttributeAsObject(AssociationItem.ASSOCIATION_ITEM_ATTRIBUTE_KEY);
AssociationAttributeInfo associationInfo = (AssociationAttributeInfo) info;
if (associationItem != null) {
switch (associationInfo.getType()) {
case MANY_TO_ONE:
((ManyToOneItem<?>) associationItem).toItem((ManyToOneAttribute) attribute); // NOSONAR
break;
case ONE_TO_MANY:
((OneToManyItem<?>) associationItem).toItem((OneToManyAttribute) attribute); // NOSONAR
break;
default:
throw new IllegalStateException("Unhandled association attribute type " +
associationInfo.getType());
}
}
}
item.fireEvent(new ChangedEvent(item.getJsObj()));
}
}