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

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

Introduction

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

Prototype

public void setFieldInitializerAsConstructor(String fieldName, String... args) 

Source Link

Document

Instructs the writer to initialize the field with a specific constructor invocation, instead of the default GWT.create call.

Usage

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  ww.  j a va2s  .  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);
}