org.cruxframework.crux.core.rebind.screen.widget
Class WidgetCreator<C extends WidgetCreatorContext>

java.lang.Object
  extended by org.cruxframework.crux.core.rebind.screen.widget.WidgetCreator<C>
Direct Known Subclasses:
AbstractCellFactory, AbstractCellTreeFactory, AbstractLabelFactory, AbstractNativeScrollbarFactory, AbstractPagerFactory, AbstractPagerFactory, CompositeFactory, DateLabelFactory, FileUploadFactory, FocusWidgetFactory, FrameFactory, HasDataProviderFactory, HiddenFactory, HyperlinkFactory, ImageFactory, InlineHyperlinkFactory, MenuBarFactory, NamedFrameFactory, NotificationMoleFactory, NumberLabelFactory, PanelFactory, StackLayoutPanelFactory, TreeFactory

public abstract class WidgetCreator<C extends WidgetCreatorContext>
extends Object

Generate code for gwt widgets creation. Generates code based on a JSON meta data array containing the information declared on crux pages.

Author:
Thiago da Rosa de Bustamante

Nested Class Summary
static class WidgetCreator.StyleNameProcessor
           
static class WidgetCreator.StyleProcessor
           
static class WidgetCreator.ViewPermissionAttributeProcessor
          Process viewPermission attribute
 
Constructor Summary
WidgetCreator()
           
 
Method Summary
protected  void commitPostProcessing(AbstractProxyCreator.SourcePrinter printer)
          Close the current postProcessing scope and schedule the execution of all scope commands.
 String createChildWidget(AbstractProxyCreator.SourcePrinter out, JSONObject metaElem, String widgetId, String widgetType, ViewFactoryCreator.WidgetConsumer consumer, boolean allowWrapperForCreatedWidget, WidgetCreatorContext context)
          Used by widgets that need to create new widgets as children.
 String createChildWidget(AbstractProxyCreator.SourcePrinter out, JSONObject metaElem, ViewFactoryCreator.WidgetConsumer consumer, boolean allowWrapperForCreatedWidget, WidgetCreatorContext context)
          Used by widgets that need to create new widgets as children.
 String createChildWidget(AbstractProxyCreator.SourcePrinter out, JSONObject metaElem, WidgetCreatorContext context)
          Used by widgets that need to create new widgets as children.
protected  C createContext(AbstractProxyCreator.SourcePrinter out, JSONObject metaElem, String widgetId, ViewFactoryCreator.WidgetConsumer consumer)
           
protected  void createPostProcessingScope()
          Create a new post-processing scope
 String createVariableName(String varName)
           
 String createWidget(AbstractProxyCreator.SourcePrinter out, JSONObject metaElem, String widgetId, ViewFactoryCreator.WidgetConsumer consumer)
          Generates the code for the given widget creation.
 JSONArray ensureChildren(JSONObject metaElem, boolean acceptsNoChild, String parentWidgetId)
           
 JSONObject ensureFirstChild(JSONObject metaElem, boolean acceptsNoChild, String parentWidgetId)
           
 String ensureHtmlChild(JSONObject metaElem, boolean acceptsNoChild, String parentWidgetId)
           
 String ensureTextChild(JSONObject metaElem, boolean acceptsNoChild, String parentWidgetId, boolean addQuotes)
           
 JSONObject ensureWidget(JSONObject metaElem, String parentWidgetId)
           
static String getChildName(JSONObject childElement)
          Retrieve the widget child element name
 Class<?> getChildWidgetClass(JSONObject metaElem)
           
 String getChildWidgetClassName(JSONObject metaElem)
           
 com.google.gwt.core.ext.GeneratorContext getContext()
           
protected  ControllerAccessHandler getControllerAccessorHandler()
          Retrieve the object responsible for print controller access expressions on client JS
 String getDeclaredMessage(String property)
           
protected  Map<String,String> getDeclaredMessages()
           
 DeviceAdaptive.Device getDevice()
           
 com.google.gwt.core.ext.TreeLogger getLogger()
           
protected  String getLoggerVariable()
           
 String getResourceAccessExpression(String property)
           
 AbstractProxyCreator.SourcePrinter getSubTypeWriter(String subType, String superClass, String[] interfaces, String[] imports)
           
 AbstractProxyCreator.SourcePrinter getSubTypeWriter(String subType, String superClass, String[] interfaces, String[] imports, boolean isInterface)
          Create a new printer for a subType.
 AbstractProxyCreator.SourcePrinter getSubTypeWriter(String packageName, String subType, String superClass, String[] interfaces, String[] imports, boolean isInterface)
          Create a new printer for a subType.
 View getView()
           
protected  String getViewVariable()
           
 Class<?> getWidgetClass()
           
 Class<?> getWidgetClass(String widgetDeclaration)
           
 String getWidgetClassName()
           
 String getWidgetFactoryDeclaration()
           
 boolean hasChildPartialSupport(JSONObject metaElem)
           
static boolean hasHeight(JSONObject metaElem)
           
 boolean hasPartialSupport()
           
static boolean hasWidth(JSONObject metaElem)
           
abstract  C instantiateContext()
           
 void instantiateWidget(AbstractProxyCreator.SourcePrinter out, C context)
           
protected  boolean isCurrentDeviceSupported(DeviceAdaptive.Device[] supported)
           
static boolean isHtmlChild(JSONObject metaElem)
           
 boolean isResourceReference(String property)
           
static boolean isTextChild(JSONObject metaElem)
           
 boolean isWidget(JSONObject metaElem)
           
 void postProcess(AbstractProxyCreator.SourcePrinter out, C context)
          Process element children
protected  void printlnPostProcessing(String s)
          Print code that will be executed after the viewFactory completes the widgets construction
 void processAttributes(AbstractProxyCreator.SourcePrinter out, C context)
          Process widget attributes
 void processChildren(AbstractProxyCreator.SourcePrinter out, C context)
          Process element children
 void processEvents(AbstractProxyCreator.SourcePrinter out, C context)
          Process widget events
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WidgetCreator

public WidgetCreator()
Method Detail

ensureChildren

public JSONArray ensureChildren(JSONObject metaElem,
                                boolean acceptsNoChild,
                                String parentWidgetId)
                         throws CruxGeneratorException
Parameters:
metaElem -
acceptsNoChild -
Returns:
Throws:
CruxGeneratorException

ensureFirstChild

public JSONObject ensureFirstChild(JSONObject metaElem,
                                   boolean acceptsNoChild,
                                   String parentWidgetId)
                            throws CruxGeneratorException
Parameters:
metaElem -
acceptsNoChild -
Returns:
Throws:
CruxGeneratorException

ensureHtmlChild

public String ensureHtmlChild(JSONObject metaElem,
                              boolean acceptsNoChild,
                              String parentWidgetId)
                       throws CruxGeneratorException
Parameters:
metaElem -
acceptsNoChild -
Returns:
Throws:
CruxGeneratorException

ensureTextChild

public String ensureTextChild(JSONObject metaElem,
                              boolean acceptsNoChild,
                              String parentWidgetId,
                              boolean addQuotes)
                       throws CruxGeneratorException
Parameters:
metaElem -
acceptsNoChild -
Returns:
Throws:
CruxGeneratorException

getChildName

public static String getChildName(JSONObject childElement)
Retrieve the widget child element name

Parameters:
childElement - element representing the child
Returns:
child name

hasHeight

public static boolean hasHeight(JSONObject metaElem)
Parameters:
metaElem -
Returns:

hasWidth

public static boolean hasWidth(JSONObject metaElem)
Parameters:
metaElem -
Returns:

isHtmlChild

public static boolean isHtmlChild(JSONObject metaElem)
                           throws CruxGeneratorException
Parameters:
metaElem -
Returns:
Throws:
CruxGeneratorException

isTextChild

public static boolean isTextChild(JSONObject metaElem)
                           throws CruxGeneratorException
Parameters:
metaElem -
Returns:
Throws:
CruxGeneratorException

createChildWidget

public String createChildWidget(AbstractProxyCreator.SourcePrinter out,
                                JSONObject metaElem,
                                WidgetCreatorContext context)
                         throws CruxGeneratorException
Used by widgets that need to create new widgets as children.

Parameters:
out -
metaElem -
context -
Returns:
Throws:
CruxGeneratorException

createChildWidget

public String createChildWidget(AbstractProxyCreator.SourcePrinter out,
                                JSONObject metaElem,
                                ViewFactoryCreator.WidgetConsumer consumer,
                                boolean allowWrapperForCreatedWidget,
                                WidgetCreatorContext context)
                         throws CruxGeneratorException
Used by widgets that need to create new widgets as children.

Parameters:
out -
metaElem -
consumer -
allowWrapperForCreatedWidget -
context -
Returns:
Throws:
CruxGeneratorException

createChildWidget

public String createChildWidget(AbstractProxyCreator.SourcePrinter out,
                                JSONObject metaElem,
                                String widgetId,
                                String widgetType,
                                ViewFactoryCreator.WidgetConsumer consumer,
                                boolean allowWrapperForCreatedWidget,
                                WidgetCreatorContext context)
                         throws CruxGeneratorException
Used by widgets that need to create new widgets as children.

Parameters:
out -
metaElem -
widgetId -
widgetType -
consumer -
allowWrapperForCreatedWidget -
context -
Returns:
Throws:
CruxGeneratorException

createVariableName

public String createVariableName(String varName)
Parameters:
varName -
Returns:

createWidget

public String createWidget(AbstractProxyCreator.SourcePrinter out,
                           JSONObject metaElem,
                           String widgetId,
                           ViewFactoryCreator.WidgetConsumer consumer)
                    throws CruxGeneratorException
Generates the code for the given widget creation.

Parameters:
out -
metaElem -
widgetId -
consumer -
Returns:
Throws:
CruxGeneratorException

ensureWidget

public JSONObject ensureWidget(JSONObject metaElem,
                               String parentWidgetId)
Parameters:
element -
Returns:

getChildWidgetClassName

public String getChildWidgetClassName(JSONObject metaElem)
Parameters:
metaElem -
Returns:

getChildWidgetClass

public Class<?> getChildWidgetClass(JSONObject metaElem)
Parameters:
metaElem -
Returns:

getContext

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

getSubTypeWriter

public AbstractProxyCreator.SourcePrinter getSubTypeWriter(String subType,
                                                           String superClass,
                                                           String[] interfaces,
                                                           String[] imports)
Parameters:
subType -
superClass -
interfaces -
imports -
Returns:

getSubTypeWriter

public 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

public 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

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

getDeclaredMessage

public String getDeclaredMessage(String property)
Parameters:
property -
Returns:

getResourceAccessExpression

public String getResourceAccessExpression(String property)
Parameters:
property -
Returns:

isResourceReference

public boolean isResourceReference(String property)
Parameters:
property -
Returns:

getLogger

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

getView

public View getView()
Returns:

getDevice

public DeviceAdaptive.Device getDevice()
Returns:

getWidgetClass

public Class<?> getWidgetClass()
Returns:

getWidgetClass

public Class<?> getWidgetClass(String widgetDeclaration)
Returns:

getWidgetClassName

public String getWidgetClassName()
Returns:

getWidgetFactoryDeclaration

public String getWidgetFactoryDeclaration()
Returns:

hasChildPartialSupport

public boolean hasChildPartialSupport(JSONObject metaElem)
Parameters:
metaElem -
Returns:

hasPartialSupport

public boolean hasPartialSupport()
Returns:

instantiateContext

public abstract C instantiateContext()
Returns:

instantiateWidget

public void instantiateWidget(AbstractProxyCreator.SourcePrinter out,
                              C context)
                       throws CruxGeneratorException
Parameters:
out -
context -
Throws:
CruxGeneratorException

isWidget

public boolean isWidget(JSONObject metaElem)
Parameters:
metaElem -
Returns:

postProcess

public void postProcess(AbstractProxyCreator.SourcePrinter out,
                        C context)
                 throws CruxGeneratorException
Process element children

Parameters:
out -
context -
Throws:
CruxGeneratorException

processAttributes

public void processAttributes(AbstractProxyCreator.SourcePrinter out,
                              C context)
                       throws CruxGeneratorException
Process widget attributes

Parameters:
out -
element - page DOM element representing the widget (Its <span> tag)
Throws:
CruxGeneratorException

processChildren

public void processChildren(AbstractProxyCreator.SourcePrinter out,
                            C context)
                     throws CruxGeneratorException
Process element children

Parameters:
out -
context -
Throws:
CruxGeneratorException

processEvents

public void processEvents(AbstractProxyCreator.SourcePrinter out,
                          C context)
                   throws CruxGeneratorException
Process widget events

Parameters:
out -
context -
Throws:
CruxGeneratorException

createContext

protected C createContext(AbstractProxyCreator.SourcePrinter out,
                          JSONObject metaElem,
                          String widgetId,
                          ViewFactoryCreator.WidgetConsumer consumer)
                                                throws CruxGeneratorException
Parameters:
srcWriter -
element -
widgetId -
consumer -
Returns:
Throws:
CruxGeneratorException

isCurrentDeviceSupported

protected boolean isCurrentDeviceSupported(DeviceAdaptive.Device[] supported)
Parameters:
supported -
Returns:

createPostProcessingScope

protected void createPostProcessingScope()
Create a new post-processing scope


commitPostProcessing

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

Parameters:
printer -

printlnPostProcessing

protected void printlnPostProcessing(String s)
Print code that will be executed after the viewFactory completes the widgets construction

Parameters:
s - code string

getControllerAccessorHandler

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

Returns:

getLoggerVariable

protected String getLoggerVariable()

getViewVariable

protected String getViewVariable()

getDeclaredMessages

protected Map<String,String> getDeclaredMessages()


Copyright © 2014. All rights reserved.