Example usage for com.google.gwt.uibinder.rebind XMLElement getAttribute

List of usage examples for com.google.gwt.uibinder.rebind XMLElement getAttribute

Introduction

In this page you can find the example usage for com.google.gwt.uibinder.rebind XMLElement getAttribute.

Prototype

public XMLAttribute getAttribute(String name) 

Source Link

Document

Get the attribute with the given name.

Usage

From source file:com.jhickman.web.gwt.gxtuibinder.elementparsers.form.SimpleComboBoxParser.java

License:Apache License

@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);
    }/*from  www  .java  2s .  c om*/

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

From source file:com.jhickman.web.gwt.gxtuibinder.elementparsers.grid.GridParser.java

License:Apache License

protected void applyColumnConfigProperties(UiBinderWriter writer, Map<String, JType> columnConfigSetterTypes,
        XMLElement child, String columnConfig) throws UnableToCompleteException {

    int attributeCount = child.getAttributeCount();
    for (int i = 0; i < attributeCount; i++) {
        // always get 0 because we're consuming them
        XMLAttribute attribute = child.getAttribute(0);

        String setterMethod = "set" + initialCap(attribute.getName());
        String value = child.consumeAttribute(attribute.getName(), columnConfigSetterTypes.get(setterMethod));
        writer.addStatement("%s.%s(%s);", columnConfig, setterMethod, value);
    }// w  w w . j a v a 2  s .  c  o  m
}

From source file:com.jhickman.web.gwt.gxtuibinder.elementparsers.layout.GenericLayoutParser.java

License:Apache License

protected void handleLayoutData(XMLElement layoutDataElem, String fieldName, UiBinderWriter writer)
        throws UnableToCompleteException {
    XMLAttribute typeAttribute = layoutDataElem.getAttribute("type");
    if (typeAttribute != null) {
        String layoutDataField = LayoutDataFieldFactory.declareField(layoutDataElem,
                typeAttribute.consumeRawValue(), writer);

        for (XMLElement child : layoutDataElem.consumeChildElements()) {
            String childField = writer.parseElementToField(child);
            writer.addStatement("%s.add(%s, %s);", fieldName, childField, layoutDataField);
        }/* w  w  w.  j av a  2  s.c o m*/
    } else {
        writer.die(layoutDataElem, "layoutdata missing type attribute");
    }
}

From source file:com.jhickman.web.gwt.gxtuibinder.elementparsers.LayoutContainerParser.java

License:Apache License

private boolean consumeLayout(XMLElement elem, String layoutContainerFieldName, JClassType type,
        UiBinderWriter writer) throws UnableToCompleteException {
    boolean layoutFound = false;
    // locate child Element
    for (XMLElement layoutChild : elem
            .consumeChildElements(new SimpleInterpreter(elem.getNamespaceUri(), "layout"))) {
        if (layoutFound) {
            writer.die(elem,//from   w  w  w. j a  va2 s .c  om
                    "LayoutContainer's and subclasses can contain only a single <%s:layout /> child.  Found multiple.",
                    elem.getPrefix());
        }

        String layoutType = layoutChild.consumeRequiredRawAttribute("type");

        LayoutParser layoutParser = LayoutParserFactory.findLayoutParserBySimpleName(elem, layoutType, writer);
        layoutParser.parse(layoutChild, elem, layoutContainerFieldName, type, writer);

        layoutFound = true;
    }

    // first, check attribute
    XMLAttribute layoutAttribute = elem.getAttribute("layout");
    if (layoutAttribute != null) {
        if (layoutFound) {
            writer.die(elem,
                    "LayoutContainer can contain either a layout attribute or a single nested <%s:layout /> child.  Not both.",
                    elem.getPrefix());
        }
        String layoutType = layoutAttribute.consumeRawValue();

        LayoutParser layoutParser = LayoutParserFactory.findLayoutParserBySimpleName(elem, layoutType, writer);
        layoutParser.parse(elem, layoutContainerFieldName, type, writer);
        layoutFound = true;
    }

    return layoutFound;
}

From source file:com.jhickman.web.gwt.gxtuibinder.elementparsers.SliderParser.java

License:Apache License

@Override
public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer)
        throws UnableToCompleteException {
    // need to grab the "value" attribute as it's ambiguous
    XMLAttribute attribute = elem.getAttribute("value");
    if (attribute != null) {
        String value = attribute.consumeRawValue();
        writer.addStatement("%s.setValue(%s);", fieldName, value);
    }/*w  w  w  . j  a v  a  2s .  co m*/
}

From source file:com.jhickman.web.gwt.gxtuibinder.elementparsers.util.ElementParserUtil.java

License:Apache License

/**
 * Consumes and applies attributes to given element
 * //from   w w  w  .j  av  a  2s . com
 * @param elem
 * @param fieldName
 * @param type
 * @param writer
 * @throws UnableToCompleteException
 */
public static void applyAttributes(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer)
        throws UnableToCompleteException {

    // first get the special Margin attribute
    ElementParserUtil.consumeRegionAttributes(elem, fieldName, writer);

    Map<String, JType> setterMethods = fetchSetterMethods(type);
    int attributeCount = elem.getAttributeCount();

    // count backwards since we're consuming as we go
    for (int i = attributeCount - 1; i >= 0; i--) {
        // always get 0 because we're consuming them
        XMLAttribute attribute = elem.getAttribute(i);

        String setterMethod = "set" + initialCap(attribute.getName());

        if (setterMethods.containsKey(setterMethod)) {
            JType setterType = setterMethods.get(setterMethod);
            String value;

            if ("float".equals(setterType.getQualifiedSourceName())) {
                value = attribute.consumeRawValue();
                float floatValue = 0;
                try {
                    floatValue = Float.parseFloat(value);
                } catch (NumberFormatException e) {
                    writer.die(elem, "Cannot parse float value for attribute '%s'.  Found %s.",
                            attribute.getName(), value);
                }
                // assuming that we didn't die due to a NumberFormatException, we can use the value
                value = floatValue + "f";
            } else if ("java.lang.Number".equals(setterType.getQualifiedSourceName())) {
                value = elem.consumeRawAttribute(attribute.getName());
            } else {
                value = elem.consumeAttribute(attribute.getName(), setterType);
            }
            writer.addStatement("%s.%s(%s);", fieldName, setterMethod, value);

        } else {
            try {
                writer.findFieldType(elem);
            } catch (UnableToCompleteException e) {
                writer.warn(elem, "Found attribute without associated setter method: %s.  IGNORING",
                        attribute.getName());
            }
        }
    }
}