Example usage for com.google.gwt.uibinder.rebind UiBinderWriter beginAttachedSection

List of usage examples for com.google.gwt.uibinder.rebind UiBinderWriter beginAttachedSection

Introduction

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

Prototype

public void beginAttachedSection(String element) 

Source Link

Document

Begin a section where a new attachable element is being parsed--that is, one that will be constructed as a big innerHTML string, and then briefly attached to the dom to allow fields accessing its to be filled (at the moment, HasHTMLParser, HTMLPanelParser, and DomElementParser.).

Usage

From source file:org.vectomatic.dev.svg.impl.gen.SVGImageParser.java

License:Open Source License

@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);
    }/*from w  ww.  j a  v  a 2 s  . c  om*/
    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;
        for (int i = 0, length = childNodes.getLength(); i < length; i++) {
            Node node = childNodes.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                if (root == null && SVGConstants.SVG_NAMESPACE_URI.equals(node.getNamespaceURI())
                        && SVGConstants.SVG_SVG_TAG.equals(node.getLocalName())) {
                    root = (Element) node;
                } else {
                    writer.die("In %s, attribute \"%s\" or inline svg must be present", elem, ATTR_RESOURCE);
                }
            }
        }
        if (root == null) {
            writer.die("In %s, attribute \"%s\" or inline svg must be present", elem, ATTR_RESOURCE);
        }
        writer.beginAttachedSection(fieldName + ".getElement()");
        SvgInterpreter interpreter = SvgInterpreter.newInterpreterForUiObject(writer, fieldName, root);
        String rawSvg = elem.consumeInnerHtml(interpreter);
        if (validated) {
            SVGValidator.validate(rawSvg, elem.getLocation().getSystemId(), null, writer);
        }
        String omSvgParser = OMSVGParser.class.getName();
        writer.addStatement("%s.setSvgElement(%s.parse(\"%s\"));", fieldName, omSvgParser, rawSvg);
        writer.endAttachedSection();
    }
}