List of usage examples for com.google.gwt.uibinder.rebind UiBinderWriter getOracle
public TypeOracle getOracle()
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 . jav a 2s. 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.ComponentParser.java
License:Apache License
/** * FIXME - only works for String value's * /* www . j a va 2 s . c om*/ * @param elem * @param fieldName * @param writer */ private void consumeDataChildren(XMLElement elem, String fieldName, UiBinderWriter writer) throws UnableToCompleteException { Interpreter<Boolean> interpreter = new SimpleInterpreter(elem.getNamespaceUri(), "data"); JClassType stringType = writer.getOracle().findType("java.lang.String"); for (XMLElement child : elem.consumeChildElements(interpreter)) { String key = child.consumeRequiredAttribute("key", stringType); String value = child.consumeRequiredAttribute("value", stringType); writer.addStatement("%s.setData(%s, %s);", fieldName, key, value); } }
From source file:com.jhickman.web.gwt.gxtuibinder.elementparsers.ComponentParser.java
License:Apache License
protected void handleToolTips(XMLElement elem, String fieldName, UiBinderWriter writer) throws UnableToCompleteException { Interpreter<Boolean> toolTipConfigInterpreter = new SimpleInterpreter(elem.getNamespaceUri(), "tooltipconfig"); Collection<XMLElement> toolTipConfigs = elem.consumeChildElements(toolTipConfigInterpreter); if (toolTipConfigs.isEmpty()) return;/* w w w . j a v a 2s.c om*/ if (toolTipConfigs.size() > 1) { writer.die(elem, "tooltipconfig can only be used once"); } XMLElement toolTipConfigElem = toolTipConfigs.iterator().next(); String toolTipConfig = writer.declareField(GxtClassnameConstants.TOOLTIPCONFIG, toolTipConfigElem); JClassType toolTipConfigType = writer.getOracle().findType(GxtClassnameConstants.TOOLTIPCONFIG); ElementParserUtil.applyAttributes(toolTipConfigElem, toolTipConfig, toolTipConfigType, writer); writer.addStatement("%s.setToolTip(%s);", fieldName, toolTipConfig); }
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;/* w ww .j a v a2 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.custom.PortalParser.java
License:Apache License
@Override public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { JClassType integerType = writer.getOracle().findType("java.lang.Integer"); JClassType doubleType = writer.getOracle().findType("java.lang.Double"); String columnCountAttribute = elem.consumeRequiredAttribute("numColumns", integerType); Integer columnCount = Integer.valueOf(columnCountAttribute); Interpreter<Boolean> interpreter = new SimpleInterpreter(elem.getNamespaceUri(), "column"); int columnIndex = 0; for (XMLElement column : elem.consumeChildElements(interpreter)) { String width = column.consumeAttribute("width", doubleType); if (width != null) { writer.addStatement("%s.setColumnWidth(%d, %s);", fieldName, columnIndex, width); }//w w w . j a v a2s . c om for (XMLElement columnChild : column.consumeChildElements()) { String childField = writer.parseElementToField(columnChild); writer.addStatement("%s.add(%s, %d);", fieldName, childField, columnIndex); } columnIndex++; } if (columnIndex > columnCount) { writer.die(elem, "numColumns set to %s, but found %s", columnCountAttribute, columnIndex); } writer.setFieldInitializerAsConstructor(fieldName, type, "" + columnIndex); }
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 ww .j a v a 2 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); }//from www. j ava 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.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 ww. j a v a 2 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.GenericLayoutParser.java
License:Apache License
protected String createAndSetLayout(XMLElement layoutElem, XMLElement elem, String fieldName, UiBinderWriter writer) throws UnableToCompleteException { String layoutField = writer.declareField(layoutClassName, elem); writer.addStatement("%s.setLayout(%s);", fieldName, layoutField); if (layoutElem != null) { JClassType layoutType = writer.getOracle().findType(layoutClassName); ElementParserUtil.applyAttributes(layoutElem, layoutField, layoutType, writer); }/*www . j av a2 s . c o m*/ return layoutField; }
From source file:com.jhickman.web.gwt.gxtuibinder.elementparsers.layout.LayoutDataFieldFactory.java
License:Apache License
/** * @param layoutDataElem// ww w .j ava 2s. c om * @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); }