for (ProxyEventDescription desc : proxyEvents) {
composerFactory.addImplementedInterface(desc.handlerFullName);
}
// Get a source writer
SourceWriter writer = composerFactory.createSourceWriter(ctx, printWriter);
// Private variable to store the gingector
writer.println();
writer.println("private " + ginjectorClassName + " ginjector;");
if (nameToken == null) {
// Not a place proxy
if (tabContainerClass != null) {
// A TabContentProxy
writeGetTabDataInternalMethod(ginjectorClassName, presenterClassName,
tabLabel, tabPriority, tabInfoFunctionDescription, writer);
}
} else {
// Place proxy
// BEGIN Enclosed proxy class
writer.println();
writer.println("public static class WrappedProxy");
if (tabContainerClass == null) {
writer.println("extends " + proxyImplClassName + "<"
+ presenterClassName + "> {");
} else {
writer.println("extends " + tabContentProxyImplClassName + "<"
+ presenterClassName + "> {");
}
writer.indent();
if (tabContainerClass != null) {
// A TabContentProxy
writeGetTabDataInternalMethod(ginjectorClassName, presenterClassName,
tabLabel, tabPriority, tabInfoFunctionDescription, writer);
}
// Enclosed proxy construcotr
writer.println();
writer.println("public WrappedProxy() {}");
// BEGIN Enclosed proxy Bind method
writer.println();
writer.println("private void delayedBind(" + ginjectorClassName
+ " ginjector) {");
writer.indent();
if (tabContainerClass != null) {
writeRequestTabHandler(logger, presenterClassName, nameToken,
tabContainerClass, tabContainerClassName, tabPriority, tabLabel,
tabInfoFunctionDescription, writer);
}
// Call ProxyImpl bind method.
writer.println("bind(ginjector.getProxyFailureHandler(),ginjector.getEventBus());");
writePresenterProvider(logger, ctx, writer, proxyCodeSplitAnnotation,
proxyCodeSplitBundleAnnotation, ginjectorClass, ginjectorClassName,
presenterClass, presenterClassName);
writeSlotHandlers(logger, ctx, proxyCodeSplitAnnotation,
proxyCodeSplitBundleAnnotation, presenterClass, presenterClassName,
ginjectorClassName, ginjectorClass, writer);
writer.outdent();
writer.println("}");
// END Enclosed proxy class
writer.outdent();
writer.println("}");
// Check if title override if needed
// Simple string title
if (title != null) {
writer.println();
writer.println("protected void getPlaceTitle(GetPlaceTitleEvent event) {");
writer.indent();
writer.println("event.getHandler().onSetPlaceTitle( \"" + title
+ "\" );");
writer.outdent();
writer.println("}");
}
// Presenter static title method returning string
if (titleFunctionDescription != null && titleFunctionDescription.isStatic
&& titleFunctionDescription.returnString) {
writer.println();
writer.println("protected void getPlaceTitle(GetPlaceTitleEvent event) {");
writer.indent();
writer.print("String title = " + presenterClassName + ".");
writeTitleFunction(titleFunctionDescription, writer);
writer.println();
writer.println("event.getHandler().onSetPlaceTitle( title );");
writer.outdent();
writer.println("}");
}
// Presenter static title method taking a handler (not returning a string)
if (titleFunctionDescription != null && titleFunctionDescription.isStatic
&& !titleFunctionDescription.returnString) {
writer.println();
writer.println("protected void getPlaceTitle(GetPlaceTitleEvent event) {");
writer.indent();
writer.print(presenterClassName + ".");
writeTitleFunction(titleFunctionDescription, writer);
writer.println();
writer.println("}");
}
// Presenter non-static title method returning a string
if (titleFunctionDescription != null
&& !titleFunctionDescription.isStatic
&& titleFunctionDescription.returnString) {
writer.println();
writer.println("protected void getPlaceTitle(final GetPlaceTitleEvent event) {");
writer.indent();
writer.println("getPresenter( new AsyncCallback<" + presenterClassName
+ ">(){");
writer.indent();
writer.indent();
writer.println("public void onSuccess(" + presenterClassName + " p ) {");
writer.indent();
writer.print("String title = p.");
writeTitleFunction(titleFunctionDescription, writer);
writer.println();
writer.println("event.getHandler().onSetPlaceTitle( title );");
writer.outdent();
writer.println(" }");
writer.println("public void onFailure(Throwable t) { event.getHandler().onSetPlaceTitle(null); }");
writer.outdent();
writer.println("} );");
writer.outdent();
writer.println("}");
}
// Presenter non-static title method taking a handler (not returning a string)
if (titleFunctionDescription != null
&& !titleFunctionDescription.isStatic
&& !titleFunctionDescription.returnString) {
writer.println();
writer.println("protected void getPlaceTitle(final GetPlaceTitleEvent event) {");
writer.indent();
writer.println("getPresenter( new AsyncCallback<" + presenterClassName
+ ">(){");
writer.indent();
writer.indent();
writer.print("public void onSuccess(" + presenterClassName
+ " p ) { p.");
writeTitleFunction(titleFunctionDescription, writer);
writer.println(" }");
writer.println("public void onFailure(Throwable t) { event.getHandler().onSetPlaceTitle(null); }");
writer.outdent();
writer.println("} );");
writer.outdent();
writer.println("}");
}
}
// Constructor
writer.println();
writer.println("public " + implClassName + "() {");
writer.indent();
writer.println("DelayedBindRegistry.register(this);");
writer.outdent();
writer.println("}");
// BEGIN Bind method
writer.println();
writer.println("@Override");
writer.println("public void delayedBind(Ginjector baseGinjector) {");
writer.indent();
writeGinjector(writer, ginjectorClassName);
if (nameToken == null) {
// Standard proxy (not a Place)
if (tabContainerClass != null) {
writeRequestTabHandler(logger, presenterClassName, tabNameToken,
tabContainerClass, tabContainerClassName, tabPriority, tabLabel,
tabInfoFunctionDescription, writer);
}
// Call ProxyImpl bind method.
writer.println("bind(ginjector.getProxyFailureHandler(),ginjector.getEventBus());");
writePresenterProvider(logger, ctx, writer, proxyCodeSplitAnnotation,
proxyCodeSplitBundleAnnotation, ginjectorClass, ginjectorClassName,
presenterClass, presenterClassName);
writeSlotHandlers(logger, ctx, proxyCodeSplitAnnotation,
proxyCodeSplitBundleAnnotation, presenterClass, presenterClassName,
ginjectorClassName, ginjectorClass, writer);
} else {
// Place proxy
// Call ProxyPlaceAbstract bind method.
writer.println("bind(ginjector.getProxyFailureHandler(), ");
writer.println(" ginjector.getPlaceManager(),");
writer.println(" ginjector.getEventBus());");
writer.println("WrappedProxy wrappedProxy = GWT.create(WrappedProxy.class);");
writer.println("wrappedProxy.delayedBind( ginjector ); ");
writer.println("proxy = wrappedProxy; ");
writer.println("String nameToken = \"" + nameToken + "\"; ");
if (newPlaceCode == null) {
if (getGatekeeperMethod == null) {
writer.println("place = new " + placeImplClassName + "( nameToken );");
} else {
writer.println("place = new " + placeWithGatekeeperClassName
+ "( nameToken, ginjector." + getGatekeeperMethod + "() );");
}
} else {
writer.println("place = " + newPlaceCode + ";");
}
}
// Register all @ProxyEvent
for (ProxyEventDescription desc : proxyEvents) {
writer.println("getEventBus().addHandler( " + desc.eventFullName
+ ".getType(), this );");
}
// END Bind method
writer.outdent();
writer.println("}");
// Write all handler methods
for (ProxyEventDescription desc : proxyEvents) {
writer.println("");
writeHandlerMethod(presenterClassName, desc, writer);
}
writer.commit(logger);
return generatedClassName;
}