com.vaadin.terminal.gwt.widgetsetutils.


Class WidgetMapGenerator

java.lang.Object
  com.google.gwt.core.ext.Generator
      com.vaadin.terminal.gwt.widgetsetutils.WidgetMapGenerator

Direct Known Subclasses:

CustomWidgetMapGenerator, EagerWidgetMapGenerator, LazyWidgetMapGenerator

public class WidgetMapGenerator
extends com.google.gwt.core.ext.Generator

WidgetMapGenerator's are GWT generator to build WidgetMapImpl dynamically based on ClientWidget annotations available in workspace. By modifying the generator it is possible to do some fine tuning for the generated widgetset (aka client side engine). The components to be included in the client side engine can modified be overriding getUsedPaintables().

The generator also decides how the client side component implementations are loaded to the browser. The default generator is EagerWidgetMapGenerator that builds a monolithic client side engine that loads all widget implementation on application initialization. This has been the only option until Vaadin 6.4.

This generator uses the loadStyle hints from the ClientWidget annotations. Depending on the ClientWidget.LoadStyle used, the widget may be included in the initially loaded JavaScript, loaded when the application has started and there is no communication to server or lazy loaded when the implementation is absolutely needed.

The GWT module description file of the widgetset ( ...Widgetset.gwt.xml) can be used to define the WidgetMapGenarator. An example that defines this generator to be used:

 
 <generate-with
           class="com.vaadin.terminal.gwt.widgetsetutils.MyWidgetMapGenerator">
          <when-type-is class="com.vaadin.terminal.gwt.client.WidgetMap" />
 </generate-with>
 
 
 

Vaadin package also includes LazyWidgetMapGenerator, which is a good option if the transferred data should be minimized, and CustomWidgetMapGenerator for easy overriding of loading strategies.

Constructor Summary
WidgetMapGenerator()
           
 
Method Summary
 String generate(com.google.gwt.core.ext.TreeLogger logger, com.google.gwt.core.ext.GeneratorContext context, String typeName)
           
protected  ClientWidget.LoadStyle getLoadStyle(Class<? extends Paintable> paintableType)
          Returns true if the widget for given component will be lazy loaded by the client.
protected  Collection<Class<? extends Paintable>> getUsedPaintables()
          This method is protected to allow creation of optimized widgetsets.
 
Methods inherited from class com.google.gwt.core.ext.Generator
escape
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WidgetMapGenerator

public WidgetMapGenerator()
Method Detail

generate

public String generate(com.google.gwt.core.ext.TreeLogger logger,
                       com.google.gwt.core.ext.GeneratorContext context,
                       String typeName)
                throws com.google.gwt.core.ext.UnableToCompleteException

Specified by:
generate in class com.google.gwt.core.ext.Generator

Throws:
com.google.gwt.core.ext.UnableToCompleteException

getUsedPaintables

protected Collection<Class<? extends Paintable>> getUsedPaintables()

This method is protected to allow creation of optimized widgetsets. The Widgetset will contain only implementation returned by this function. If one knows which widgets are needed for the application, returning only them here will significantly optimize the size of the produced JS.

Returns:
a collections of Vaadin components that will be added to widgetset

getLoadStyle

protected ClientWidget.LoadStyle getLoadStyle(Class<? extends Paintable> paintableType)

Returns true if the widget for given component will be lazy loaded by the client. The default implementation reads the information from the ClientWidget annotation.

The method can be overridden to optimize the widget loading mechanism. If the Widgetset is wanted to be optimized for a network with a high latency or for a one with a very fast throughput, it may be good to return false for every component.

Parameters:
paintableType -
Returns:
true iff the widget for given component should be lazy loaded by the client side engine