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

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

Introduction

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

Prototype

public void die(XMLElement context, String message, Object... params) throws UnableToCompleteException 

Source Link

Document

Post an error message about a specific XMLElement and halt processing.

Usage

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

License:Apache License

@Override
public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer)
        throws UnableToCompleteException {

    for (XMLElement child : elem.consumeChildElements()) {
        if (!isValidElement(elem, child)) {
            writer.die(elem, "CheckBoxGroup can only contain CheckBox children, but found '%s'.", child);
        }/*from   www .  j a v  a  2s  . co  m*/

        String childFieldName = writer.parseElementToField(child);

        writer.addStatement("%s.add(%s);", fieldName, childFieldName);
    }

}

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

License:Apache License

@Override
public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer)
        throws UnableToCompleteException {

    JClassType radioType = writer.getOracle().findType(GxtClassnameConstants.RADIO);

    for (XMLElement child : elem.consumeChildElements()) {

        JClassType childType = writer.findFieldType(child);
        if (!childType.isAssignableTo(radioType)) {
            writer.die(elem, "RadioGroup can only contain Radio children, but found '%s'.", child);
        }/* w  w w. jav  a2 s.  c o m*/

        String childFieldName = writer.parseElementToField(child);

        writer.addStatement("%s.add(%s);", fieldName, childFieldName);
    }
}

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);
    }/*w ww .j  a  va  2  s  .  c  o m*/

    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.layout.LayoutDataFieldFactory.java

License:Apache License

/**
 * @param layoutDataElem/*from  w  w  w .  j  av a2  s . com*/
 * @param layoutDataSimpleName
 * @param writer
 * @return
 */
public static String declareField(XMLElement layoutDataElem, String layoutDataSimpleName, UiBinderWriter writer)
        throws UnableToCompleteException {

    if (SpecialHandlingLayoutDataType.contains(layoutDataSimpleName)) {
        return SpecialHandlingLayoutDataType.valueOf(layoutDataSimpleName).declareField(writer, layoutDataElem);
    }

    // not one that requires special handling
    JClassType layoutDataType = writer.getOracle()
            .findType(GxtClassnameConstants.LAYOUT_BASE_PACKAGE + layoutDataSimpleName);
    if (layoutDataType == null) {
        writer.die(layoutDataElem, "Unable to find specified LayoutData type: %s", layoutDataSimpleName);
    }

    return declareField(layoutDataElem, layoutDataType, writer);
}

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

License:Apache License

public static LayoutParser findLayoutParser(XMLElement elem, String layoutClassName, UiBinderWriter writer)
        throws UnableToCompleteException {
    if (null == writer.getOracle().findType(layoutClassName)) {
        // type not found.  die
        writer.die(elem, "Unable to find Layout type: %s", layoutClassName);
    }/*from  ww  w  .jav a2 s  .co  m*/

    // ones with custom parsers
    if (GxtClassnameConstants.BORDERLAYOUT.equals(layoutClassName)) {
        return new BorderLayoutParser();
    }

    if (GxtClassnameConstants.ROWLAYOUT.equals(layoutClassName)
            || GxtClassnameConstants.FILLLAYOUT.equals(layoutClassName)) {
        return new RowLayoutParser(layoutClassName);
    }

    return new GenericLayoutParser(layoutClassName);
}

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,
                    "LayoutContainer's and subclasses can contain only a single <%s:layout /> child.  Found multiple.",
                    elem.getPrefix());//w w w  .j a v  a 2s  . co  m
        }

        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.menu.AdapterMenuItemParser.java

License:Apache License

public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer)
        throws UnableToCompleteException {

    XMLElement childElement = elem.consumeSingleChildElement();
    if (!writer.isWidgetElement(childElement)) {
        writer.die(elem, "Child element must be a widget type. Found: %s", childElement);
    }/*from w ww . j  a  va 2s .  com*/

    String widget = writer.parseElementToField(childElement);
    writer.setFieldInitializerAsConstructor(fieldName, type, widget);
}

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

License:Apache License

/**
 * Consumes the styleAttribute attribute from the provided elements.
 * /* ww  w. j a v a  2 s.  c o  m*/
 * Allowed value format is:
 * styleName:value;styleName:value
 * 
 * 
 * @param elem
 * @param fieldName
 * @param writer
 * @return
 * @throws UnableToCompleteException
 */
public static void consumeStyleAttribute(XMLElement elem, String fieldName, UiBinderWriter writer)
        throws UnableToCompleteException {
    String styleAttributes = elem.consumeRawAttribute("styleAttribute");
    if (styleAttributes == null)
        return;

    String[] styles = styleAttributes.split("\\s*;\\s*");
    for (String style : styles) {
        String[] keyValue = style.split("\\s*:\\s*");
        if (keyValue.length != 2) {
            writer.die(elem,
                    "styleAttribute should be in format: styleName:styleValue;styleName:styleValue  but found %s",
                    styleAttributes);
        }

        writer.addStatement("%s.setStyleAttribute(\"%s\", \"%s\");", fieldName, keyValue[0], keyValue[1]);
    }

}

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 w w.  jav 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();
    }
}