private void parseColumns(String fieldName, UiBinderWriter writer, RowContent row, XMLElement child) throws UnableToCompleteException { String tagName; for (XMLElement cell : child.consumeChildElements()) { tagName = cell.getLocalName(); if (!tagName.equals(CELL_TAG) && !tagName.equals(CUSTOMCELL_TAG) || !cell.getPrefix().equals(child.getPrefix())) { writer.die("Grid's row tag in %s may only contain %s or %s element.", fieldName, CELL_TAG, CUSTOMCELL_TAG); } CellContent newColumn = null; String styleName = cell.consumeStringAttribute(STYLE_NAME_ATTRIBUTE, null); if (tagName.equals(CELL_TAG)) { HtmlInterpreter htmlInt = HtmlInterpreter.newInterpreterForUiObject( writer, fieldName); String html = cell.consumeInnerHtml(htmlInt); newColumn = new CellContent(tagName, html, styleName); } if (tagName.equals(CUSTOMCELL_TAG)) { FieldWriter field = writer.parseElementToField(cell.consumeSingleChildElement()); newColumn = new CellContent(tagName, field.getNextReference(), styleName); } row.addColumn(newColumn); } }
private String consumeCurrency(XMLElement elem, UiBinderWriter writer) throws UnableToCompleteException { String currencyData = elem.consumeAttribute("currencyData", writer.getOracle().findType(CurrencyData.class.getCanonicalName())); String currencyCode = elem.consumeStringAttribute("currencyCode"); if (currencyData != null && currencyCode != null) { writer.die(elem, AT_MOST_ONE_SPECIFIED_CURRENCY); } return currencyData != null ? currencyData : currencyCode; }
boolean custom = isCustomWidget(writer, type); if (!custom) { String autoHide = elem.consumeBooleanAttribute("autoHide", false); String modal = elem.consumeBooleanAttribute("modal", true); customCaption.getPrefix(), CUSTOM_CAPTION); customCaption.getPrefix(), CUSTOM_CAPTION, Caption.class.getCanonicalName());
private boolean isValidChildElement(XMLElement parent, XMLElement child) { if (child != null && child.getNamespaceUri() != null && child.getNamespaceUri().equals(parent.getNamespaceUri()) && uiChildMethods.containsKey(child.getLocalName())) { return true; } else { return false; } }
private static String getLegalPlaceholderTag(XMLElement elem) { XMLElement parent = elem.getParent(); String tag = null; if (parent != null) { tag = LEGAL_CHILD_ELEMENTS.get(parent.getLocalName()); } if (tag == null) { tag = DEFAULT_CHILD_ELEMENT; } return tag; }
private void parseRows(XMLElement elem, String fieldName, UiBinderWriter writer, List<RowContent> matrix) throws UnableToCompleteException { for (XMLElement child : elem.consumeChildElements()) { String tagName = child.getLocalName(); if (!tagName.equals(ROW_TAG) || !elem.getPrefix().equals(child.getPrefix())) { writer.die( "%1$s:Grid elements must contain only %1$s:%2$s children, found %3$s:%4$s", elem.getPrefix(), ROW_TAG, child.getPrefix(), tagName); } RowContent newRow = new RowContent(); newRow.setStyleName(child.consumeStringAttribute(STYLE_NAME_ATTRIBUTE, null)); matrix.add(newRow); parseColumns(fieldName, writer, newRow, child); } } }
String unit = panelElem.consumeAttributeWithDefault("unit", String.format("%s.%s", unitEnumType.getQualifiedSourceName(), "PX"), unitEnumType); for (XMLElement stackElem : panelElem.consumeChildElements()) { panelElem.getPrefix(), STACK); HtmlInterpreter htmlInt = HtmlInterpreter.newInterpreterForUiObject( writer, fieldName); String size = children.header.consumeRequiredDoubleAttribute("size"); String html = children.header.consumeInnerHtml(htmlInt); writer.addStatement("%s.add(%s, %s, true, %s);", fieldName, childField.getNextReference(), writer.declareTemplateCall(html, fieldName), size); } else if (children.customHeader != null) { XMLElement headerElement = children.customHeader.consumeSingleChildElement(); String size = children.customHeader.consumeRequiredDoubleAttribute("size"); if (!writer.isWidgetElement(headerElement)) { writer.die(headerElement, "Is not a widget"); stackElem.getPrefix(), HEADER, CUSTOM);
@Override public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { if (elem.hasAttribute(ATTR_RESOURCE) && elem.hasChildNodes()) { writer.die("In %s, attribute \"%s\" and inline svg are mutually exclusive", elem, ATTR_RESOURCE); if (!(elem.hasAttribute(ATTR_RESOURCE) || elem.hasChildNodes())) { writer.die("In %s, attribute \"%s\" or inline svg must be present", elem, ATTR_RESOURCE); if (elem.hasAttribute(ATTR_RESOURCE)) { JClassType svgResourceType = writer.getOracle().findType(SVGResource.class.getCanonicalName()); String resource = elem.consumeAttribute(ATTR_RESOURCE, svgResourceType); writer.addStatement("%s.setResource(%s);", fieldName, resource); } else { boolean validated = true; if (elem.hasAttribute(ATTR_VALIDATED)) { String value = elem.consumeBooleanAttribute(ATTR_VALIDATED); validated = Boolean.valueOf(value); Element container = elem.getElement(); NodeList childNodes = container.getChildNodes(); Element root = null; String rawSvg = elem.consumeInnerHtml(interpreter); if (validated) { SVGValidator.validate(rawSvg, elem.getLocation().getSystemId(), null, writer);
public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { for (XMLElement child : elem.consumeChildElements()) { String ns = child.getNamespaceUri(); String tagName = child.getLocalName(); if (!ns.equals(elem.getNamespaceUri())) { writer.die(elem, "Invalid DockPanel child namespace: " + ns); if (!child.hasAttribute("direction")) { writer.die(elem, "Dock must specify the 'direction' attribute"); String value = child.consumeRawAttribute("direction"); String translated = values.get(value); if (translated == null) { XMLElement widget = child.consumeSingleChildElement(); FieldWriter childField = writer.parseElementToField(widget); writer.addStatement("%1$s.add(%2$s, %3$s);", fieldName,
JEnumType unitEnumType = writer.getOracle().findType( Unit.class.getCanonicalName()).isEnum(); String unit = elem.consumeAttributeWithDefault("unit", String.format("%s.%s", unitEnumType.getQualifiedSourceName(), "PX"), unitEnumType); for (XMLElement child : elem.consumeChildElements()) { "Child must be one of " + "<%1$s:north>, <%1$s:south>, <%1$s:east>, <%1$s:west> or <%1$s:center>, " + "but found %2$s", elem.getPrefix(), child); XMLElement widget = child.consumeSingleChildElement(); if (!writer.isWidgetElement(widget)) { writer.die(elem, "%s must contain a widget, but found %s", child, if (child.getLocalName().equals("center")) { if (center != null) { writer.die(elem, "Only one <%s:center> is allowed", elem.getPrefix()); String size = child.consumeRequiredDoubleAttribute("size"); writer.addStatement("%s.%s(%s, %s);", fieldName, addMethodName(child), widgetField.getNextReference(), size);
@Override public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { String parameterizedType = elem.consumeRawAttribute("type", "java.lang.String"); JClassType valueType = writer.getOracle().findType(parameterizedType); if (valueType == null) { writer.die(elem, "Found type attribute, but unable to resolve the value: %s", parameterizedType); } for(XMLElement child : elem.consumeChildElements()) { if ( ! child.getNamespaceUri().equals(elem.getNamespaceUri())) { writer.die(elem, "Children of SimpleComboBox must be in the same namespace. Expected '%s' but found '%s'", elem.getPrefix(), child.getPrefix()); } String data = parseChildElement(child, valueType, writer); writer.addStatement("%s.add(%s);", fieldName, data); } if (elem.getAttribute("simpleValue") != null) { writer.addStatement("%s.setSimpleValue(%s);", fieldName, elem.consumeAttribute("simpleValue", valueType)); } }
public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { for (XMLElement child : elem.consumeChildElements()) { String ns = child.getNamespaceUri(); String tagName = child.getLocalName(); if (ns != null && ns.equals(elem.getNamespaceUri()) && localTagNameIsCell(tagName)) { // It's a cell element, so parse its single child as a widget. XMLElement widget = child.consumeSingleChildElement(); FieldWriter childField = writer.parseElementToField(widget); writer.addStatement("%1$s.add(%2$s);", fieldName, childField.getNextReference()); // Parse the cell tag's alignment & size attributes. parseCellAttributes(child, fieldName, childField, writer); } else { if (!writer.isWidgetElement(child)) { writer.die(elem, "Expected a widget or <%s:%s>, found %s", elem.getPrefix(), CELL_TAG.toLowerCase(Locale.ROOT), child); } // It's just a normal child, so parse it as a widget. FieldWriter childField = writer.parseElementToField(child); writer.addStatement("%1$s.add(%2$s);", fieldName, childField.getNextReference()); } } }
public Boolean interpretElement(XMLElement child) throws UnableToCompleteException { // CustomButton can only contain Face elements. String ns = child.getNamespaceUri(); String faceName = child.getLocalName(); if (!ns.equals(elem.getNamespaceUri())) { writer.die(elem, "Invalid child namespace: %s", ns); } if (!faceNames.contains(faceName)) { writer.die(elem, "Invalid CustomButton face: %s:%s", ns, faceName); } HtmlInterpreter interpreter = HtmlInterpreter.newInterpreterForUiObject( writer, fieldName); String innerHtml = child.consumeInnerHtml(interpreter); if (innerHtml.length() > 0) { writer.addStatement("%s.%s().setHTML(%s);", fieldName, faceNameGetter(faceName), writer.declareTemplateCall(innerHtml, fieldName)); } if (child.hasAttribute("image")) { String image = child.consumeImageResourceAttribute("image"); writer.addStatement("%s.%s().setImage(new %s(%s));", fieldName, faceNameGetter(faceName), IMAGE_CLASS, image); } return true; // We consumed it } });
public String interpretElement(XMLElement elem) throws UnableToCompleteException { // Must be in the format: <ui:string from="{myMsg.message}" /> if (writer.isBinderElement(elem) && getLocalName().equals(elem.getLocalName())) { if (!elem.hasAttribute("from")) { logger.die(elem, "Attribute 'from' not found."); } if (!elem.getAttribute("from").hasComputedValue()) { logger.die(elem, "Attribute 'from' does not have a computed value"); } // Make sure all computed attributes are interpreted first computedAttributeInterpreter.interpretElement(elem); String fieldRef = elem.consumeStringAttribute("from"); // Make sure that "from" was the only attribute elem.assertNoAttributes(); return "\" + " + fieldRef + " + \""; } return null; }
/** * Consumes all attributes, and returns a string representing the entire * opening tag. E.g., "<div able='baker'>" */ public String consumeOpeningTag() { String rtn = getOpeningTag(); for (int i = getAttributeCount() - 1; i >= 0; i--) { getAttribute(i).consumeRawValue(); } return rtn; }
if (elem.hasAttribute("vertical")) { String vertical = elem.consumeBooleanAttribute("vertical"); writer.setFieldInitializerAsConstructor(fieldName, vertical); for (XMLElement child : elem.consumeChildElements()) { JClassType childType = writer.findFieldType(child);
for (int i = elem.getAttributeCount() - 1; i >= 0; i--) { XMLAttribute attribute = elem.getAttribute(i); String value = elem.consumeAttributeWithDefault(attribute.getName(), null, paramType); if (value == null) { if (setter != null) { String n = attribute.getName(); String value = elem.consumeAttributeWithDefault(n, null, getParamTypes(setter)); if (ownerFieldClass.getRawType().findMethod(addMethod, new JType[]{stringType}) != null) { String n = attribute.getName(); String[] value = elem.consumeStringArrayAttribute(n); } else { writer.die(elem, "Class %s has no appropriate %s() method", elem.getLocalName(), addMethod); elem.getLocalName(), initialCap(propertyName));
if (childElem.hasAttribute(ATTR_VALIDATED)) { String value = childElem.consumeBooleanAttribute(ATTR_VALIDATED); validated = Boolean.valueOf(value); Element container = childElem.getElement(); NodeList childNodes = container.getChildNodes(); Element root = null; String rawSvg = childElem.consumeInnerHtml(interpreter); if (validated) { SVGValidator.validate(rawSvg, elem.getLocation().getSystemId(), null, writer);
public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { // Parse children. for (XMLElement child : elem.consumeChildElements()) { String tagName = child.getLocalName(); if (!tagName.equals(ITEM_TAG)) { writer.die(elem, "Invalid ListBox child element: " + tagName); } String value = child.consumeStringAttribute("value"); String innerText = child.consumeInnerTextEscapedAsStringLiteral( new TextInterpreter(writer)); if (value != null) { writer.addStatement("%s.addItem(\"%s\", %s);", fieldName, innerText, value); } else { writer.addStatement("%s.addItem(\"%s\");", fieldName, innerText); } } }
public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { // Parse children. for (XMLElement child : elem.consumeChildElements()) { if (!writer.isWidgetElement(child)) { writer.die(child, "Widget required"); } // Stack panel label comes from the StackPanel-text attribute of the child String stackItemLabel = null; String variableAttributeName = elem.getPrefix() + ":" + ATTRIBUTE_TEXT; if (child.hasAttribute(variableAttributeName)) { stackItemLabel = child.consumeRawAttribute(variableAttributeName); } FieldWriter childField = writer.parseElementToField(child); if (stackItemLabel == null) { writer.addStatement("%1$s.add(%2$s);", fieldName, childField.getNextReference()); } else { writer.addStatement("%1$s.add(%2$s, \"%3$s\");", fieldName, childField.getNextReference(), stackItemLabel); } } } }