/** * @see com.alkacon.acacia.client.I_EntityRenderer#renderForm(com.alkacon.vie.shared.I_Entity, * com.google.gwt.user.client.ui.Panel) */ public void renderForm(final I_Entity entity, Panel context) { context.addStyleName(ENTITY_CLASS); context.getElement().setAttribute("typeof", entity.getTypeName()); context.getElement().setAttribute("about", entity.getId()); I_Type entityType = m_vie.getType(entity.getTypeName()); List<String> attributeNames = entityType.getAttributeNames(); for (final String attributeName : attributeNames) { AttributeHandler handler = new AttributeHandler(m_vie, entity, attributeName, m_widgetService); I_Type attributeType = entityType.getAttributeType(attributeName); I_EntityRenderer renderer = m_widgetService.getRendererForAttribute(attributeName, attributeType); int minOccurrence = entityType.getAttributeMinOccurrence(attributeName); String label = m_widgetService.getAttributeLabel(attributeName); String help = m_widgetService.getAttributeHelp(attributeName); ValuePanel attributeElement = new ValuePanel(); context.add(attributeElement); I_EntityAttribute attribute = entity.getAttribute(attributeName); if ((attribute == null) && (minOccurrence > 0)) { attribute = createEmptyAttribute(entity, attributeName, minOccurrence); } if (attribute != null) { for (int i = 0; i < attribute.getValueCount(); i++) { AttributeValueView valueWidget = new AttributeValueView(handler, label, help); attributeElement.add(valueWidget); if (attribute.isSimpleValue()) { valueWidget.setValueWidget( m_widgetService.getAttributeWidget(attributeName), attribute.getSimpleValues().get(i)); } else { valueWidget.setValueEntity(renderer, attribute.getComplexValues().get(i)); } } } else { AttributeValueView valueWidget = new AttributeValueView(handler, label, help); attributeElement.add(valueWidget); } handler.updateButtonVisisbility(); } }
/** * @see com.alkacon.acacia.client.I_EntityRenderer#renderInline(com.alkacon.vie.shared.I_Entity, * com.google.gwt.dom.client.Element) */ public void renderInline(I_Entity entity, Element context) { I_Type entityType = m_vie.getType(entity.getTypeName()); List<String> attributeNames = entityType.getAttributeNames(); for (String attributeName : attributeNames) { I_Type attributeType = entityType.getAttributeType(attributeName); I_EntityRenderer renderer = m_widgetService.getRendererForAttribute(attributeName, attributeType); renderer.renderInline( entity, attributeName, context, entityType.getAttributeMinOccurrence(attributeName), entityType.getAttributeMaxOccurrence(attributeName)); } }
/** * Creates an empty attribute. * * <p> * * @param parentEntity the parent entity * @param attributeName the attribute name * @param minOccurrence the minimum occurrence of the attribute * @return the entity attribute */ protected I_EntityAttribute createEmptyAttribute( I_Entity parentEntity, String attributeName, int minOccurrence) { I_EntityAttribute result = null; I_Type attributeType = m_vie.getType(parentEntity.getTypeName()).getAttributeType(attributeName); if (attributeType.isSimpleType()) { for (int i = 0; i < minOccurrence; i++) { parentEntity.addAttributeValue( attributeName, m_widgetService.getDefaultAttributeValue(attributeName)); } result = parentEntity.getAttribute(attributeName); } else { for (int i = 0; i < minOccurrence; i++) { parentEntity.addAttributeValue( attributeName, m_vie.createEntity(null, attributeType.getId())); } result = parentEntity.getAttribute(attributeName); } return result; }
/** * @see com.alkacon.acacia.client.I_EntityRenderer#renderInline(com.alkacon.vie.shared.I_Entity, * java.lang.String, com.google.gwt.dom.client.Element, int, int) */ public void renderInline( I_Entity parentEntity, String attributeName, Element context, int minOccurrence, int maxOccurrence) { I_EntityAttribute attribute = parentEntity.getAttribute(attributeName); if (attribute != null) { if (attribute.isSimpleValue()) { List<Element> elements = m_vie.getAttributeElements(parentEntity, attributeName, context); for (int i = 0; i < elements.size(); i++) { Element element = elements.get(i); I_EditWidget widget = m_widgetService.getAttributeWidget(attributeName).initWidget(element, true); widget.addValueChangeHandler(new WidgetChangeHandler(parentEntity, attributeName, i)); } } else { for (I_Entity entity : attribute.getComplexValues()) { renderInline(entity, context); } } } }