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

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

Introduction

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

Prototype

public String getLocalName() 

Source Link

Document

Gets this element's local name (sans namespace prefix).

Usage

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

License:Apache License

protected void handleTopBottomComponents(XMLElement elem, String fieldName, UiBinderWriter writer)
        throws UnableToCompleteException {
    Interpreter<Boolean> topBottomComponentInterpreter = new TopBottomComponentInterpreter(
            elem.getNamespaceUri());/*  w w  w  .j  av a 2 s.  c  o  m*/

    for (XMLElement child : elem.consumeChildElements(topBottomComponentInterpreter)) {
        XMLElement widget = child.consumeSingleChildElement();

        if (!isComponentElement(writer, widget)) {
            writer.die(elem, "%s must contain a GXT Component, but found %s", child, widget);
        }

        String widgetName = writer.parseElementToField(widget);
        String methodName = SupportedChildLocalNames.valueOf(child.getLocalName()).getMethodName();
        writer.addStatement("%s.%s(%s);", fieldName, methodName, widgetName);
    }
}

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

License:Apache License

private boolean isValidElement(XMLElement parent, XMLElement child) {
    if (!parent.getNamespaceUri().equals(child.getNamespaceUri())) {
        return false;
    }/*from   w  w w. j a  va  2 s  .c  om*/

    return "CheckBox".equals(child.getLocalName());
}

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

License:Apache License

private String parseChildElement(XMLElement elem, JClassType valueType, UiBinderWriter writer)
        throws UnableToCompleteException {
    if ("value".equals(elem.getLocalName())) {
        return String.format("\"%s\"",
                elem.consumeInnerTextEscapedAsHtmlStringLiteral(new TextInterpreter(writer)));
    } else if ("item".equals(elem.getLocalName())) {
        return elem.consumeRequiredAttribute("value", valueType);
    }/*from  w w  w .  j a v a 2s.c  o  m*/

    writer.die(elem, "Unknown child element of SimpleComboBox");

    return null; // will never get here
}

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");
    }/*w w  w  .  ja  v  a2 s .c om*/

    // 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(", ");
            }//from  w w w.  j a  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.BorderLayoutParser.java

License:Apache License

private boolean isValidChildElement(XMLElement parent, XMLElement child) {
    if (!parent.getNamespaceUri().equals(child.getNamespaceUri())) {
        return false;
    }/*from  ww w.j  a va 2 s . c  o  m*/

    if (!DOCK_NAMES.contains(child.getLocalName())) {
        return false;
    }

    return true;
}

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.");
        }/*from   w w w.ja v  a 2  s .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);
    }
}

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

License:Apache License

@Override
public Boolean interpretElement(XMLElement elem) throws UnableToCompleteException {
    return (namespaceUri != null && namespaceUri.equals(elem.getNamespaceUri()))
            && (localName != null && localName.equals(elem.getLocalName()));
}

From source file:com.jhickman.web.gwt.gxtuibinder.resourceparsers.XTemplateParser.java

License:Apache License

@Override
public boolean supports(XMLElement elem) {
    return "urn:ui:com.jhickman.web.gwt.gxtuibinder".equals(elem.getNamespaceUri())
            && "xtemplate".equals(elem.getLocalName());
}