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

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

Introduction

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

Prototype

public Iterable<XMLElement> consumeChildElements() throws UnableToCompleteException 

Source Link

Document

Consumes and returns all child elements.

Usage

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

License:Apache License

@Override
public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer)
        throws UnableToCompleteException {
    // parse as component first.  FIXME figure out the parser order on class hierarchy. should the superclass ones should parse first?
    super.parse(elem, fieldName, type, writer);

    handleBackwardsCompatibleMenu(elem, fieldName, writer);

    JClassType menuType = writer.getOracle().findType(GxtClassnameConstants.MENU);
    boolean foundSingleMenu = false;
    for (XMLElement child : elem.consumeChildElements()) {
        if (foundSingleMenu) {
            writer.die(elem, "Buttons only support a single Menu.  Found more than one.");
        }// w  ww. j a va  2  s.  c  o m

        JClassType childType = writer.findFieldType(child);
        if (!childType.isAssignableTo(menuType)) {
            writer.die(elem, "Buttons only support nested Menu Components.  Found %s.", child);
        }
        foundSingleMenu = true;

        String menu = writer.parseElementToField(child);
        writer.addStatement("%s.setMenu(%s);", fieldName, menu);
    }
}

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);
        }// w ww  .  j a v a2  s . 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);
        }/*  www .  j  av  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.  jav  a  2  s.  co 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.form.SliderFieldParser.java

License:Apache License

@Override
public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer)
        throws UnableToCompleteException {
    boolean seen = false;
    for (XMLElement child : elem.consumeChildElements()) {
        if (seen) {
            writer.die("SliderField can contain exactly one child element of type Slider.");
        }/*from   w  ww .  j  ava2  s. co m*/

        // single child must be of type "Slider"
        String childField = writer.parseElementToField(child);
        writer.setFieldInitializerAsConstructor(fieldName, type, childField);

        seen = true;
    }
}

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

License:Apache License

@Override
public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer)
        throws UnableToCompleteException {
    JClassType listStoreType = writer.getOracle().findType(GxtClassnameConstants.LISTSTORE);
    String store = elem.consumeAttribute("store", listStoreType);

    if (store == null) {
        writer.die(elem, "Attribute 'store' is required");
    }/*from   w w  w.j  a  va2  s  . c  o  m*/

    // have to set the following fields to null temporarily.  
    // Due to the order of operations added, we need to construct
    // all ColumnConfigs before constructing a ColumnModel.
    writer.setFieldInitializer(fieldName, "null");
    // new ColumnModel(columnConfig)
    String columnModel = writer.declareField(GxtClassnameConstants.COLUMNMODEL, elem);
    writer.setFieldInitializer(columnModel, "null");

    JClassType arrayListType = writer.getOracle().findType(ArrayList.class.getName());
    JClassType columnConfigType = writer.getOracle().findType(GxtClassnameConstants.COLUMNCONFIG);
    JParameterizedType parameterizedArrayListType = writer.getOracle()
            .getParameterizedType(arrayListType.isGenericType(), new JClassType[] { columnConfigType });

    Map<String, JType> columnConfigSetterTypes = fetchColumnConfigProperties(columnConfigType);

    // List<ColumnConfig>
    String columnConfigList = writer.declareField(List.class.getName(), elem);
    writer.setFieldInitializerAsConstructor(columnConfigList, parameterizedArrayListType);

    for (XMLElement child : elem.consumeChildElements()) {
        if (!elem.getPrefix().equals(child.getPrefix())) {
            writer.die(child, "Child node of %s must use the same prefix.  Expecting %s, but found %s", elem,
                    elem.getPrefix(), child.getPrefix());
        }

        if (!"column".equals(child.getLocalName())) {
            writer.die(child, "Only <%s:column> children are allowed. Found %s.", elem.getPrefix(), child);
        }

        String columnConfig = writer.declareField(GxtClassnameConstants.COLUMNCONFIG, elem);

        applyColumnConfigProperties(writer, columnConfigSetterTypes, child, columnConfig);

        writer.addStatement("%s.add(%s);", columnConfigList, columnConfig);
    }

    // now that we have all ColumnConfigs created and added to list, we can now
    // construct the ColumnModel and Grid
    writer.addStatement("%s = new %s(%s);", columnModel, GxtClassnameConstants.COLUMNMODEL, columnConfigList);
    writer.addStatement("%s = new %s(%s, %s);", fieldName, type.getQualifiedSourceName(), store, columnModel);
}

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

License:Apache License

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

    Set<String> layoutRegionsSeen = new HashSet<String>();

    for (XMLElement layoutDataElem : elem.consumeChildElements()) {
        if (!isValidChildElement(elem, layoutDataElem)) {
            StringBuilder sb = new StringBuilder("Child must be one of ");
            for (String name : DOCK_NAMES) {
                sb.append("<%1$s:").append(name).append(", ");
            }//  ww w  . ja va 2  s.  co m
            sb.append("but found %2$s");
            writer.die(elem, sb.toString(), elem.getPrefix(), layoutDataElem);
        }

        // have we already added this region?
        String region = layoutDataElem.getLocalName();
        if (layoutRegionsSeen.contains(region)) {
            writer.die(elem, "Only one <%s:%s> is allowed", elem.getPrefix(), region);
        }
        layoutRegionsSeen.add(region);

        // delegate to super class
        layoutDataElem.setAttribute("type", "BorderLayoutData");
        handleLayoutData(layoutDataElem, fieldName, writer);
    }
}

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

License:Apache License

protected void handleChildren(XMLElement elem, String fieldName, UiBinderWriter writer)
        throws UnableToCompleteException {
    SimpleInterpreter layoutDataInterpreter = new SimpleInterpreter(elem.getNamespaceUri(), "layoutdata");

    for (XMLElement child : elem.consumeChildElements()) {
        if (layoutDataInterpreter.interpretElement(child)) {
            handleLayoutData(child, fieldName, writer);
        } else {//from  w  ww  . jav  a2  s .co m
            String childField = writer.parseElementToField(child);
            writer.addStatement("%s.add(%s);", fieldName, childField);
        }
    }
}

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);
        }/*from w  w  w  . j  a va 2 s.  c  o  m*/
    } else {
        writer.die(layoutDataElem, "layoutdata missing type attribute");
    }
}

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

License:Apache License

public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer)
        throws UnableToCompleteException {
    boolean found = false;
    for (XMLElement child : elem.consumeChildElements()) {
        if (found) {
            writer.die(elem, "element only supports 0 or 1 child elements.");
        }//w  ww. j  a va  2s  .  c  om
        found = true;

        JClassType menuType = writer.getOracle().findType(GxtClassnameConstants.MENU);
        JClassType childType = writer.findFieldType(child);
        if (!menuType.isAssignableFrom(childType)) {
            writer.die(child, "%s only supports children type Menu", elem.getLocalName());
        }

        String menuVarName = writer.parseElementToField(child);
        writer.addStatement("%s.setSubMenu(%s);", fieldName, menuVarName);
    }
}