ArrayList<Class<? extends Paintable>> lazyLoadedWidgets = new ArrayList<Class<? extends Paintable>>();
HashSet<Class<? extends com.vaadin.terminal.gwt.client.Paintable>> widgetsWithInstantiator = new HashSet<Class<? extends com.vaadin.terminal.gwt.client.Paintable>>();
for (Class<? extends Paintable> class1 : paintablesHavingWidgetAnnotation) {
ClientWidget annotation = class1.getAnnotation(ClientWidget.class);
Class<? extends com.vaadin.terminal.gwt.client.Paintable> clientClass = annotation
.value();
if(widgetsWithInstantiator.contains(clientClass)) {
continue;
}
if (clientClass == VView.class) {
// VView's are not instantiated by widgetset
continue;
}
if (!first) {
sourceWriter.print(" else ");
} else {
first = false;
}
sourceWriter.print("if( classType == " + clientClass.getName()
+ ".class) {");
String instantiator = "new WidgetInstantiator() {\n public Paintable get() {\n return GWT.create("
+ clientClass.getName() + ".class );\n}\n}\n";
LoadStyle loadStyle = getLoadStyle(class1);
if (loadStyle != LoadStyle.EAGER) {
sourceWriter
.print("ApplicationConfiguration.startWidgetLoading();\n"
+ "GWT.runAsync( \n"
+ "new WidgetLoader() { void addInstantiator() {instmap.put("
+ clientClass.getName()
+ ".class,"
+ instantiator + ");}});\n");
lazyLoadedWidgets.add(class1);
if (loadStyle == LoadStyle.DEFERRED) {
deferredWidgets.add(class1);
}
} else {
// widget implementation in initially loaded js script
sourceWriter.print("instmap.put(");
sourceWriter.print(clientClass.getName());
sourceWriter.print(".class, ");
sourceWriter.print(instantiator);
sourceWriter.print(");");
}
sourceWriter.print("}");
widgetsWithInstantiator.add(clientClass);
}
sourceWriter.println("}");
sourceWriter.println("}");
sourceWriter
.println("public Class<? extends Paintable>[] getDeferredLoadedWidgets() {");
sourceWriter.println("return new Class[] {");
first = true;
for (Class<?> class2 : deferredWidgets) {
if (!first) {
sourceWriter.println(",");
}
first = false;
ClientWidget annotation = class2.getAnnotation(ClientWidget.class);
Class<? extends com.vaadin.terminal.gwt.client.Paintable> value = annotation
.value();
sourceWriter.print(value.getName() + ".class");
}
sourceWriter.println("};");