WidgetMapGenerator in Vaadin 7

Hello All!

In Vaadin 6 I used to trim the list of components to be included in the widgetset by using CustomWidgetMapGenerator.
I was basically overriding getUsedPaintables to return short list of components (“Paintables”) that i was using within the application,
thus significantly reducing the compiled widgetset size.
Unfortunately there were several changes in Vaadin 7 affecting this, and the old method is not longer working.

Is there any other mechanism in the newest Vaadin 7, that accomplishes the same task?
The version I’m using now is 7.0.0beta7.

Thanks in advance!

Code splitting is currently broken in Vaadin 7 (
#8636
) - practically all the generated code goes into the main widgetset JavaScript file. When that is fixed, it might also help you.

The method that is currently the closest equivalent to getPaintables() is ConnectorBundleGenerator.getLoadStyle(connectorType) - I believe it can return null to omit a widget. The generator is activated in com/vaadin/Vaadin.gwt.xml .

Thanks!

I will then probably wait for the changes in this matter.

Best Regards!

Hello all,

If anyone is still interested in generating custom widgetset, it is now possible with vaadin 7.0.0-RC1.
It works by extending ConnectorBundleLoaderFactory class and implementing your own getConnectorsForWidgetset() method that returns list of connectors (Collection) to be included in the compiled widgetset.

Here is how it works for me:

  1. open the AppWidgetSet.gwt.xml of your app and add this somewhere between tags:

     <generate-with
        class="your.package.WidgetLoaderFactory">
        <when-type-assignable
            class="com.vaadin.client.metadata.ConnectorBundleLoader" />
    </generate-with> 
  1. Create class your.package.WidgetLoaderFactory that extends ConnectorBundleLoaderFactory and implements getConnectorsForWidgetset
    Here’s my example:

public class WidgetLoaderFactory extends com.vaadin.server.widgetsetutils.ConnectorBundleLoaderFactory {
	protected Collection<JClassType> getConnectorsForWidgetset( 
		 	TreeLogger logger, TypeOracle typeOracle) 
		 	throws UnableToCompleteException {
		
		ArrayList<String> filterOutList = new ArrayList<String>(
				Arrays.asList("com.vaadin.client.ui.passwordfield.PasswordFieldConnector",
						"com.vaadin.client.ui.draganddropwrapper.DragAndDropWrapperConnector",
						"com.vaadin.client.extensions.BrowserWindowOpenerConnector",
						"com.vaadin.client.ui.richtextarea.RichTextAreaConnector",
						"com.vaadin.client.ui.tabsheet.TabsheetConnector",
						"com.vaadin.client.ui.listselect.ListSelectConnector",
						"com.vaadin.client.ui.form.FormConnector",
						"com.vaadin.client.extensions.javascriptmanager.JavaScriptManagerConnector",
						"com.vaadin.client.ui.formlayout.FormLayoutConnector",
						"com.vaadin.client.ui.popupview.PopupViewConnector"
                            /* here you can put all connectors that you're NOT going to use */
				));		
         //get list of all connectors
		Collection<JClassType> c = super.getConnectorsForWidgetset(logger, typeOracle);
         //filter out unneded ones
		c = filterOutTypes(c, filterOutList);
		System.out.println(c);
		
		return c;
		
	}
	
	private Collection<JClassType> filterOutTypes(Collection<JClassType> all, ArrayList<String> removeClasses) {
		ArrayList<JClassType> list = new ArrayList<JClassType>();
		
		for (JClassType jct : all) {
			boolean exists = false;
			for (String f: removeClasses) {		
				if (jct.toString().toLowerCase().contains(f.toLowerCase()) == true) {
					exists = true;
				}
			}
			if (exists == false) {
				list.add(jct);
			}
		}
		return list;
	}
}
  1. be sure to include vaadin-compiler

    com.vaadin
    vaadin-client-compiler
    ${vaadin.version}

you may want to remove it later from resulting WAR, or just use it for widgetset compilation only. In my case i remove it from WAR, as it breaks something.

  1. when you rebuild your entire project, your widgetset should be now smaller.

  2. if you’re interested in making widgetset even less heavy, I suggest also looking at gzip compression. you can get really good results (like making it 1/5 of original size)

Hope it helps

There is now also a
tutorial
about this and an add-on that makes the process easier - see the tutorial page.

I would recommend starting with enabling gzip compression on the server (it always helps, whether you limit the set of eager widgets or not) and only then considering limiting the content of the widgetset if necessary.