Example usage for com.google.gwt.uibinder.rebind XMLAttribute getName

List of usage examples for com.google.gwt.uibinder.rebind XMLAttribute getName

Introduction

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

Prototype

public String getName() 

Source Link

Usage

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 ava  2 s.com
}

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

License:Apache License

/**
 * Consumes and applies attributes to given element
 * //  w ww.  j ava2s .  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());
            }
        }
    }
}