logger.debug( "securityTraitList: " + securityTraitList );
logger.debug( "rolesList: " + rolesList );
//Validate getWidgetMethodName and isWidget
if ( !isWidget && getWidgetMethodName == null ) {
throw new GenerationException( "The WorkbenchScreen must either extend IsWidget or provide a @WorkbenchPartView annotated method to return a com.google.gwt.user.client.ui.IsWidget.", packageName + "." + className );
}
if ( isWidget && getWidgetMethodName != null ) {
final String msg = "The WorkbenchScreen both extends com.google.gwt.user.client.ui.IsWidget and provides a @WorkbenchPartView annotated method. The annotated method will take precedence.";
processingEnvironment.getMessager().printMessage( Kind.WARNING,
msg );
logger.warn( msg );
}
//Validate onStartup0ParameterMethodName and onStartup1ParameterMethodName
if ( onStartup0ParameterMethodName != null && onStartup1ParameterMethodName != null ) {
final String msg = "Found multiple @OnStartup methods. Each class can declare at most one.";
throw new GenerationException( msg );
}
//Validate getTitleMethodName and getTitleWidgetMethodName
if ( getTitleMethodName == null ) {
throw new GenerationException( "The WorkbenchScreen must provide a @WorkbenchPartTitle annotated method to return a java.lang.String.", packageName + "." + className );
}
//Setup data for template sub-system
Map<String, Object> root = new HashMap<String, Object>();
root.put( "packageName",
packageName );
root.put( "className",
className );
root.put( "identifier",
identifier );
root.put( "preferredHeight",
preferredHeight );
root.put( "preferredWidth",
preferredWidth );
root.put( "getContextIdMethodName",
getContextIdMethodName );
root.put( "realClassName",
classElement.getSimpleName().toString() );
root.put( "onStartup0ParameterMethodName",
onStartup0ParameterMethodName );
root.put( "onStartup1ParameterMethodName",
onStartup1ParameterMethodName );
root.put( "onMayCloseMethodName",
onMayCloseMethodName );
root.put( "onCloseMethodName",
onCloseMethodName );
root.put( "onShutdownMethodName",
onShutdownMethodName );
root.put( "onOpenMethodName",
onOpenMethodName );
root.put( "onLostFocusMethodName",
onLostFocusMethodName );
root.put( "onFocusMethodName",
onFocusMethodName );
root.put( "getDefaultPositionMethodName",
getDefaultPositionMethodName );
root.put( "getTitleMethodName",
getTitleMethodName );
root.put( "getTitleWidgetMethodName",
getTitleWidgetMethodName );
root.put( "getWidgetMethodName",
getWidgetMethodName );
root.put( "isWidget",
isWidget );
root.put( "hasUberView",
hasUberView );
root.put( "getMenuBarMethodName",
getMenuBarMethodName );
root.put( "getToolBarMethodName",
getToolBarMethodName );
root.put( "securityTraitList",
securityTraitList );
root.put( "rolesList",
rolesList );
//Generate code
final StringWriter sw = new StringWriter();
final BufferedWriter bw = new BufferedWriter( sw );
try {
final Template template = config.getTemplate( "activityScreen.ftl" );
template.process( root,
bw );
} catch ( IOException ioe ) {
throw new GenerationException( ioe );
} catch ( TemplateException te ) {
throw new GenerationException( te );
} finally {
try {
bw.close();
sw.close();
} catch ( IOException ioe ) {
throw new GenerationException( ioe );
}
}
logger.debug( "Successfully generated code for [" + className + "]" );
return sw.getBuffer();