List of usage examples for com.google.gwt.uibinder.rebind UiBinderWriter findFieldType
public JClassType findFieldType(XMLElement elem) throws UnableToCompleteException
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."); }/*from w w w . j a va2 s.c om*/ 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.ContentPanelParser.java
License:Apache License
private boolean isComponentElement(UiBinderWriter writer, XMLElement widget) throws UnableToCompleteException { JClassType fieldType = writer.findFieldType(widget); JClassType componentType;//from ww w. ja va 2 s .c o m try { componentType = writer.getOracle().getType(GxtClassnameConstants.COMPONENT); } catch (NotFoundException e) { throw new UnableToCompleteException(); } return componentType.isAssignableFrom(fieldType); }
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); }// ww w . ja v a 2s . com String childFieldName = writer.parseElementToField(child); writer.addStatement("%s.add(%s);", fieldName, childFieldName); } }
From source file:com.jhickman.web.gwt.gxtuibinder.elementparsers.menu.MenuBarItemParser.java
License:Apache License
private boolean isMenuElement(UiBinderWriter writer, XMLElement menu) throws UnableToCompleteException { JClassType fieldType = writer.findFieldType(menu); JClassType menuType;/*from www . jav a 2s .com*/ try { menuType = writer.getOracle().getType(GxtClassnameConstants.MENU); } catch (NotFoundException e) { throw new UnableToCompleteException(); } return menuType.isAssignableFrom(fieldType); }
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 . j a v a 2s . c o m*/ 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.ElementParserUtil.java
License:Apache License
/** * Consumes and applies attributes to given element * // www .ja va2s. c om * @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()); } } } }
From source file:com.jhickman.web.gwt.gxtuibinder.elementparsers.util.ElementParserUtil.java
License:Apache License
/** * @param button/*from w w w.j a v a2s. c o m*/ * @param button2 * @return */ public static boolean isElementOfType(UiBinderWriter writer, XMLElement elem, String typeName) throws UnableToCompleteException { JClassType elemType = writer.findFieldType(elem); JClassType componentType; try { componentType = writer.getOracle().getType(typeName); } catch (NotFoundException e) { throw new UnableToCompleteException(); } return componentType.isAssignableFrom(elemType); }