org.cruxframework.crux.core.rebind.screen.widget
Class ViewFactoryCreator

java.lang.Object
  extended by org.cruxframework.crux.core.rebind.AbstractProxyCreator
      extended by org.cruxframework.crux.core.rebind.screen.widget.ViewFactoryCreator
Direct Known Subclasses:
DeviceAdaptiveViewFactoryCreator

public class ViewFactoryCreator
extends AbstractProxyCreator

Author:
Thiago da Rosa de Bustamante

Nested Class Summary
static class ViewFactoryCreator.EmptyWidgetConsumer
           
static interface ViewFactoryCreator.LazyCompatibleWidgetConsumer
           
static interface ViewFactoryCreator.WidgetConsumer
           
 
Nested classes/interfaces inherited from class org.cruxframework.crux.core.rebind.AbstractProxyCreator
AbstractProxyCreator.SourcePrinter
 
Field Summary
protected  ControllerAccessHandler controllerAccessHandler
           
protected  String iocContainerClassName
           
protected  String module
           
protected  View view
           
protected  ViewFactoryCreator.WidgetConsumer widgetConsumer
           
 
Fields inherited from class org.cruxframework.crux.core.rebind.AbstractProxyCreator
cacheable, cacheableVersionFound, context, logger
 
Constructor Summary
ViewFactoryCreator(com.google.gwt.core.ext.GeneratorContext context, com.google.gwt.core.ext.TreeLogger logger, View view, String device, String module)
          Constructor
 
Method Summary
protected  void commitPostProcessing(AbstractProxyCreator.SourcePrinter printer)
          Close the current postProcessing scope and schedule the execution of all scope commands.
protected  void createPostProcessingScope()
          Create a new scope for the post processing commands.
static String createVariableName(String varName)
          Creates a new unique name based off ofvarName and adds it to the list of known names.
protected  void generateCreateDataObjectMethod(AbstractProxyCreator.SourcePrinter printer)
           
protected  void generateGetIocContainerMethod(AbstractProxyCreator.SourcePrinter printer)
           
protected  void generateProxyContructor(AbstractProxyCreator.SourcePrinter printer)
          Generate the View Constructor
protected  void generateProxyFields(AbstractProxyCreator.SourcePrinter printer)
          Generate the View fields
protected  void generateProxyMethods(AbstractProxyCreator.SourcePrinter printer)
          Generate the View methods.
protected  void generateResources(AbstractProxyCreator.SourcePrinter printer)
          Create ClientBundles for the declared resources on View
protected  void generateSubTypes(AbstractProxyCreator.SourcePrinter srcWriter)
          Override this method to generate any nested type required by the proxy
protected  com.google.gwt.core.ext.GeneratorContext getContext()
           
protected  ControllerAccessHandler getControllerAccessHandler()
          Retrieve the object responsible for print controller access expressions on client JS
protected  String getDeclaredMessage(String property)
          Gets the code necessary to access a i18n declared property or the own property, if it is not in declarative i18n format.
protected  Map<String,String> getDeclaredMessages()
          Gets all messages declared on this screen
protected  String getDevice()
           
protected  String[] getKeyMessageParts(String text)
          Split the i18n message and separate the messageClass alias from the message method
protected  com.google.gwt.core.ext.TreeLogger getLogger()
           
protected  String getLoggerVariable()
          Retrieves the logger variable name
protected  String getMetaElementType(JSONObject cruxMetaElement)
          Return the type of a given crux meta tag.
 String getProxyQualifiedName()
          Return the qualified name of the ViewFactory class created for the associated screen
 String getProxySimpleName()
          Return the simple name of the ViewFactory class created for the associated screen
protected  String getResourceAccessExpression(String property)
          Gets the code necessary to access a resource property or the own property, if it is not in a resource reference format.
protected  String[] getResourceParts(String text)
          Split the resourceReference and separate the resourceClass alias from the requested property
protected  AbstractProxyCreator.SourcePrinter getSourcePrinter()
          Creates and returns a new SourceWriter
protected  AbstractProxyCreator.SourcePrinter getSubTypeWriter(String subType, String superClass, String[] interfaces, String[] imports)
          Create a new printer for a subType.
protected  AbstractProxyCreator.SourcePrinter getSubTypeWriter(String subType, String superClass, String[] interfaces, String[] imports, boolean isInterface)
          Create a new printer for a subType.
protected  AbstractProxyCreator.SourcePrinter getSubTypeWriter(String packageName, String subType, String superClass, String[] interfaces, String[] imports)
          Create a new printer for a subType.
protected  AbstractProxyCreator.SourcePrinter getSubTypeWriter(String packageName, String subType, String superClass, String[] interfaces, String[] imports, boolean isInterface)
          Create a new printer for a subType.
protected  View getView()
           
 String getViewSuperClassName()
           
static String getViewVariable()
          Retrieves the view variable name
protected  WidgetCreator<?> getWidgetCreator(String widgetType)
          Returns the creator of the widgets of the given type.
protected  WidgetCreatorHelper getWidgetCreatorHelper(String widgetType)
          Returns a helper object to create the code of the widgets of the given type.
protected  boolean isDataBindEnabled()
           
protected  boolean isKeyReference(String text)
          Returns true if the given text is an internationalization key.
protected  boolean isResourceReference(String text)
          Returns true if the given text is a reference to a resource.
protected  boolean isValidWidget(JSONObject metaElem)
          Check if the given metaElement refers to a valid widget
protected  String newWidget(AbstractProxyCreator.SourcePrinter printer, JSONObject metaElem, String widgetId, String widgetType)
          Creates a new widget based on its meta-data element.
protected  String newWidget(AbstractProxyCreator.SourcePrinter printer, JSONObject metaElem, String widgetId, String widgetType, ViewFactoryCreator.WidgetConsumer consumer, boolean allowWrapperForCreatedWidget)
          Creates a new widget based on its meta-data element.
protected  void prepare(com.google.gwt.core.ext.GeneratorContext context, com.google.gwt.core.ext.TreeLogger logger, String device)
           
protected  void printlnPostProcessing(String s)
          Print code that will be executed after the viewFactory completes the widgets construction.
protected  void processViewEvents(AbstractProxyCreator.SourcePrinter printer)
          Generate the code for the View events creation
 
Methods inherited from class org.cruxframework.crux.core.rebind.AbstractProxyCreator
cacheableVersionFound, create, findCacheableImplementationAndMarkForReuseIfAvailable, findCacheableImplementationAndMarkForReuseIfAvailable, generateLoggerField, generateMethodParameters, generateMethodTrhowsClause, generateProxyWrapperMethodDeclaration, getJsniSimpleSignature, isAlreadyGenerated, isCacheable, isCrux2OldInterfacesCompatibilityEnabled, logDebugMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

module

protected final String module

view

protected final View view

controllerAccessHandler

protected ControllerAccessHandler controllerAccessHandler

widgetConsumer

protected ViewFactoryCreator.WidgetConsumer widgetConsumer

iocContainerClassName

protected String iocContainerClassName
Constructor Detail

ViewFactoryCreator

public ViewFactoryCreator(com.google.gwt.core.ext.GeneratorContext context,
                          com.google.gwt.core.ext.TreeLogger logger,
                          View view,
                          String device,
                          String module)
Constructor

Parameters:
context -
logger -
view -
device -
module -
Method Detail

createVariableName

public static String createVariableName(String varName)
Creates a new unique name based off ofvarName and adds it to the list of known names.

Parameters:
varName -
Returns:

getControllerAccessHandler

protected ControllerAccessHandler getControllerAccessHandler()
Retrieve the object responsible for print controller access expressions on client JS

Returns:

generateProxyFields

protected void generateProxyFields(AbstractProxyCreator.SourcePrinter printer)
Generate the View fields

Overrides:
generateProxyFields in class AbstractProxyCreator
Parameters:
printer -

generateProxyContructor

protected void generateProxyContructor(AbstractProxyCreator.SourcePrinter printer)
                                throws CruxGeneratorException
Generate the View Constructor

Overrides:
generateProxyContructor in class AbstractProxyCreator
Throws:
CruxGeneratorException

generateResources

protected void generateResources(AbstractProxyCreator.SourcePrinter printer)
Create ClientBundles for the declared resources on View

Parameters:
printer -

generateProxyMethods

protected void generateProxyMethods(AbstractProxyCreator.SourcePrinter printer)
Generate the View methods.

Overrides:
generateProxyMethods in class AbstractProxyCreator
Parameters:
printer -

generateCreateDataObjectMethod

protected void generateCreateDataObjectMethod(AbstractProxyCreator.SourcePrinter printer)

generateGetIocContainerMethod

protected void generateGetIocContainerMethod(AbstractProxyCreator.SourcePrinter printer)

generateSubTypes

protected void generateSubTypes(AbstractProxyCreator.SourcePrinter srcWriter)
                         throws CruxGeneratorException
Description copied from class: AbstractProxyCreator
Override this method to generate any nested type required by the proxy

Overrides:
generateSubTypes in class AbstractProxyCreator
Throws:
CruxGeneratorException

getMetaElementType

protected String getMetaElementType(JSONObject cruxMetaElement)
Return the type of a given crux meta tag. This type could be "screen" or another string referencing a registered WidgetFactory.

Parameters:
cruxMetaElement -
Returns:

getWidgetCreator

protected WidgetCreator<?> getWidgetCreator(String widgetType)
Returns the creator of the widgets of the given type.

Parameters:
widgetType -
Returns:
the creator of the widgets of the given type.

getWidgetCreatorHelper

protected WidgetCreatorHelper getWidgetCreatorHelper(String widgetType)
Returns a helper object to create the code of the widgets of the given type.

Parameters:
widgetType -
Returns:
a helper object to create the code of the widgets of the given type.

newWidget

protected String newWidget(AbstractProxyCreator.SourcePrinter printer,
                           JSONObject metaElem,
                           String widgetId,
                           String widgetType)
                    throws CruxGeneratorException
Creates a new widget based on its meta-data element.

Parameters:
printer -
metaElem -
widgetId -
Returns:
Throws:
CruxGeneratorException

newWidget

protected String newWidget(AbstractProxyCreator.SourcePrinter printer,
                           JSONObject metaElem,
                           String widgetId,
                           String widgetType,
                           ViewFactoryCreator.WidgetConsumer consumer,
                           boolean allowWrapperForCreatedWidget)
                    throws CruxGeneratorException
Creates a new widget based on its meta-data element.

Parameters:
printer -
metaElem -
widgetId -
consumer -
allowWrapperForCreatedWidget -
Returns:
Throws:
CruxGeneratorException

commitPostProcessing

protected void commitPostProcessing(AbstractProxyCreator.SourcePrinter printer)
Close the current postProcessing scope and schedule the execution of all scope commands.

Parameters:
printer -

createPostProcessingScope

protected void createPostProcessingScope()
Create a new scope for the post processing commands. All commands added by printlnPostProcessing method will be added to this same scope, what means that they will be fired together. When commitPostProcessing method is called, the scope is closed and all scope commands are programmed for execution.


getLogger

protected com.google.gwt.core.ext.TreeLogger getLogger()
Returns:

getViewVariable

public static String getViewVariable()
Retrieves the view variable name

Returns:

getViewSuperClassName

public String getViewSuperClassName()
Returns:

getLoggerVariable

protected String getLoggerVariable()
Retrieves the logger variable name

Returns:

getView

protected View getView()
Returns:

getDeclaredMessage

protected String getDeclaredMessage(String property)
Gets the code necessary to access a i18n declared property or the own property, if it is not in declarative i18n format.

Parameters:
property -
Returns:

getResourceAccessExpression

protected String getResourceAccessExpression(String property)
Gets the code necessary to access a resource property or the own property, if it is not in a resource reference format.

Parameters:
property -
Returns:

isKeyReference

protected boolean isKeyReference(String text)
Returns true if the given text is an internationalization key.

Parameters:
text -
Returns:
true if the given text is an internationalization key.

isResourceReference

protected boolean isResourceReference(String text)
Returns true if the given text is a reference to a resource.

Parameters:
text -
Returns:
true if the given text is a reference to a resource.

getDeclaredMessages

protected Map<String,String> getDeclaredMessages()
Gets all messages declared on this screen

Returns:

getContext

protected com.google.gwt.core.ext.GeneratorContext getContext()
Returns:

getSubTypeWriter

protected AbstractProxyCreator.SourcePrinter getSubTypeWriter(String subType,
                                                              String superClass,
                                                              String[] interfaces,
                                                              String[] imports)
Create a new printer for a subType. That subType will be declared on the same package of the ViewFactory.

Parameters:
subType -
superClass -
interfaces -
imports -
Returns:

getSubTypeWriter

protected AbstractProxyCreator.SourcePrinter getSubTypeWriter(String packageName,
                                                              String subType,
                                                              String superClass,
                                                              String[] interfaces,
                                                              String[] imports)
Create a new printer for a subType. That subType will be declared on the same package of the ViewFactory.

Parameters:
packageName -
subType -
superClass -
interfaces -
imports -
isInterface -
Returns:

getSubTypeWriter

protected AbstractProxyCreator.SourcePrinter getSubTypeWriter(String subType,
                                                              String superClass,
                                                              String[] interfaces,
                                                              String[] imports,
                                                              boolean isInterface)
Create a new printer for a subType. That subType will be declared on the same package of the ViewFactory.

Parameters:
subType -
superClass -
interfaces -
imports -
isInterface -
Returns:

getSubTypeWriter

protected AbstractProxyCreator.SourcePrinter getSubTypeWriter(String packageName,
                                                              String subType,
                                                              String superClass,
                                                              String[] interfaces,
                                                              String[] imports,
                                                              boolean isInterface)
Create a new printer for a subType. That subType will be declared on the package name informed in the first parameter if packageName isEmpty, subType will be declared on the same package of the { @code ViewFactory }.

Parameters:
packageName -
subType -
superClass -
interfaces -
imports -
isInterface -
Returns:

isValidWidget

protected boolean isValidWidget(JSONObject metaElem)
Check if the given metaElement refers to a valid widget

Parameters:
element -
Returns:

prepare

protected void prepare(com.google.gwt.core.ext.GeneratorContext context,
                       com.google.gwt.core.ext.TreeLogger logger,
                       String device)
Parameters:
context -
logger -
device -

getDevice

protected String getDevice()
Returns:

printlnPostProcessing

protected void printlnPostProcessing(String s)
Print code that will be executed after the viewFactory completes the widgets construction. Note that this code will be executed from inside a Command class. Any variable accessed in this code and declared outside need to be declared as final.

Parameters:
s - code string

processViewEvents

protected void processViewEvents(AbstractProxyCreator.SourcePrinter printer)
Generate the code for the View events creation

Parameters:
printer -

getKeyMessageParts

protected String[] getKeyMessageParts(String text)
Split the i18n message and separate the messageClass alias from the message method

Parameters:
text -
Returns:

getResourceParts

protected String[] getResourceParts(String text)
Split the resourceReference and separate the resourceClass alias from the requested property

Parameters:
text -
Returns:

getProxyQualifiedName

public String getProxyQualifiedName()
Return the qualified name of the ViewFactory class created for the associated screen

Specified by:
getProxyQualifiedName in class AbstractProxyCreator
Returns:

getProxySimpleName

public String getProxySimpleName()
Return the simple name of the ViewFactory class created for the associated screen

Specified by:
getProxySimpleName in class AbstractProxyCreator
Returns:

getSourcePrinter

protected AbstractProxyCreator.SourcePrinter getSourcePrinter()
Creates and returns a new SourceWriter

Specified by:
getSourcePrinter in class AbstractProxyCreator
Returns:
a new SourceWriter

isDataBindEnabled

protected boolean isDataBindEnabled()
Returns:


Copyright © 2014. All rights reserved.