Search in sources :

Example 1 with ResourcePrototypeProxyBuilder

use of com.googlecode.gwt.test.internal.resources.ResourcePrototypeProxyBuilder in project gwt-test-utils by gwt-test-utils.

the class UiResourceManager method registerResource.

/**
     * Register a new resource which should correspond to a resource tag in the .ui.xml file.
     *
     * @param localName  The type of the resource ('with', 'style', 'image' or 'data')
     * @param attributes Map of attributes parsed from the tag
     * @param parentTag  The parent tag if any
     * @param owner      The {@link UiBinder} owner widget, which calls the
     *                   {@link UiBinder#createAndBindUi(Object)} method to initialize itself.
     * @return The UiBinderTag which wraps the Resource instance.
     * @throws GwtTestUiBinderException If the localName is not managed or if the alias is already
     *                                  binded to another Resource object
     */
UiTag<?> registerResource(String localName, Map<String, Object> attributes, UiTag<?> parentTag, Object owner) throws GwtTestUiBinderException {
    String alias = getResourceAlias(localName, attributes);
    if (resources.containsKey(alias)) {
        throw new GwtTestUiBinderException("Two inner resources '" + alias + " are declared in " + owner.getClass().getSimpleName() + ".ui.xml. You should add a 'field' attribute to one of them");
    }
    Class<?> type = getResourceType(alias, localName, attributes);
    if ("with".equals(localName)) {
        // special resource <ui:with> : the resource can be annotated with
        // @UiConstructor, @UiFactory or @UiField(provided=true)
        Object resource = UiBinderInstanciator.getInstance(type, attributes, owner);
        resources.put(alias, resource);
        return new UiWithTag(resource);
    }
    ResourcePrototypeProxyBuilder builder = ResourcePrototypeProxyBuilder.createBuilder(type, owner.getClass());
    // common properties
    builder.name(alias);
    if ("style".equals(localName)) {
        // <ui:style>
        return new UiStyleTag(builder, alias, parentTag, owner, resources);
    } else if ("image".equals(localName)) {
        // <ui:image>
        return new UiImgTag(builder, alias, parentTag, owner, resources, attributes);
    } else if ("data".equals(localName)) {
        // <ui:data>
        return new UiDataTag(builder, alias, parentTag, owner, resources, attributes);
    } else {
        throw new GwtTestUiBinderException("resource <" + localName + "> element is not yet implemented by gwt-test-utils");
    }
}
Also used : GwtTestUiBinderException(com.googlecode.gwt.test.exceptions.GwtTestUiBinderException) ResourcePrototypeProxyBuilder(com.googlecode.gwt.test.internal.resources.ResourcePrototypeProxyBuilder) UIObject(com.google.gwt.user.client.ui.UIObject)

Aggregations

UIObject (com.google.gwt.user.client.ui.UIObject)1 GwtTestUiBinderException (com.googlecode.gwt.test.exceptions.GwtTestUiBinderException)1 ResourcePrototypeProxyBuilder (com.googlecode.gwt.test.internal.resources.ResourcePrototypeProxyBuilder)1