org.cruxframework.crux.core.client.screen.views
Class View

java.lang.Object
  extended by org.cruxframework.crux.core.client.screen.views.View
All Implemented Interfaces:
HasOrientationChangeHandler, HasViewActivateHandlers, HasViewLoadHandlers, HasViewResizeHandlers, HasWindowCloseHandlers
Direct Known Subclasses:
BindableView

public abstract class View
extends Object
implements HasViewResizeHandlers, HasWindowCloseHandlers, HasViewActivateHandlers, HasOrientationChangeHandler, HasViewLoadHandlers

Author:
Thiago da Rosa de Bustamante

Nested Class Summary
static interface View.RenderCallback
           
 
Field Summary
protected  boolean active
           
protected  FastList<ViewActivateHandler> attachHandlers
           
protected  FastList<ViewDeactivateHandler> detachHandlers
           
protected  String height
           
protected  FastList<com.google.gwt.event.logical.shared.ValueChangeHandler<String>> historyHandlers
           
protected  Map<String> lazyWidgets
           
protected  boolean loaded
           
protected  FastList<ViewLoadHandler> loadHandlers
           
protected  FastList<OrientationChangeHandler> orientationHandlers
           
protected  FastList<com.google.gwt.event.logical.shared.ResizeHandler> resizeHandlers
           
protected  FastList<ViewUnloadHandler> unloadHandlers
           
protected  FastMap<com.google.gwt.user.client.ui.Widget> widgets
           
protected  String width
           
protected  FastList<com.google.gwt.event.logical.shared.CloseHandler<com.google.gwt.user.client.Window>> windowCloseHandlers
           
protected  FastList<com.google.gwt.user.client.Window.ClosingHandler> windowClosingHandlers
           
 
Constructor Summary
View(String id)
          Constructor
 
Method Summary
 com.google.gwt.event.shared.HandlerRegistration addResizeHandler(com.google.gwt.event.logical.shared.ResizeHandler handler)
           
protected static void addResource(String id, com.google.gwt.resources.client.ClientBundle resource)
           
static void addToHistory(String token)
          Adds a new token for history control.
static void addToHistory(String token, boolean issueEvent)
          Adds a new token for history control.
 com.google.gwt.event.shared.HandlerRegistration addViewActivateHandler(ViewActivateHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addViewDeactivateHandler(ViewDeactivateHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addViewLoadHandler(ViewLoadHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addViewUnloadHandler(ViewUnloadHandler handler)
           
 void addWidget(String id, com.google.gwt.user.client.ui.IsWidget widget)
          Add a new widget into this view
 void addWidget(String id, com.google.gwt.user.client.ui.Widget widget)
          Add a new widget into this view
 com.google.gwt.event.shared.HandlerRegistration addWindowCloseHandler(com.google.gwt.event.logical.shared.CloseHandler<com.google.gwt.user.client.Window> handler)
           
 com.google.gwt.event.shared.HandlerRegistration addWindowClosingHandler(com.google.gwt.user.client.Window.ClosingHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addWindowHistoryChangedHandler(com.google.gwt.event.logical.shared.ValueChangeHandler<String> handler)
           
 com.google.gwt.event.shared.HandlerRegistration addWindowOrientationChangeHandler(OrientationChangeHandler handler)
           
protected  void checkRuntimeLazyDependency(String id, String lazyPanelId)
          When we have multi-level inner lazy panels, the most inside panel is dependent from the most outside one.
protected  void cleanLazyDependentWidgets(String widgetId)
           
protected  void clearViewObjects()
          When view is unloaded, we must free its allocated memory.
static boolean containsResource(String id)
          Returns true if a resource associated with the given identifiers was loaded by application
 boolean containsWidget(String id)
          Verify if the view contains an widget associated with the given identifier
abstract  DataSource<?> createDataSource(String dataSource)
          Create a new DataSource instance
protected abstract  void createWidgets()
          Called by View container to create the view widgets
protected  void fireHistoryChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent<String> event)
           
protected  void fireLoadEvent(Object paramenter)
          Fires the load event
protected  void fireOrientationEvent()
           
protected  void fireResizeEvent(com.google.gwt.event.logical.shared.ResizeEvent event)
           
protected  boolean fireUnloadEvent()
          Fires the unload event.
protected  void fireWindowCloseEvent(com.google.gwt.event.logical.shared.CloseEvent<com.google.gwt.user.client.Window> event)
           
protected  void fireWindowClosingEvent(com.google.gwt.user.client.Window.ClosingEvent event)
           
 ViewContainer getContainer()
          Retrieve the container that holds this view
<T> T
getController(String controller)
          Retrieve the requested controller from this view
 String getHeight()
          Retrieve the view height;
 String getId()
          Retrieve the view identifier
abstract  IocContainer getIocContainer()
          Retrieve the IoCContainer instance associated with this view
protected  String getPrefix()
          Retrieve the view prefix.
abstract  RegisteredControllers getRegisteredControllers()
          Retrieve the list of controllers registered into this view
static com.google.gwt.resources.client.ClientBundle getResource(String id)
          Retrieve the client bundle associated with the given id.
 String getTitle()
          Retrieve the view title
static
<T extends View>
T
getView(String id)
          Retrieve the view by its identifier
 com.google.gwt.user.client.ui.Widget getWidget(String id)
          Retrieve a widget contained on this view.
 com.google.gwt.user.client.ui.Widget getWidget(String id, boolean checkLazyDependencies)
          Retrieve a widget contained on this screen.
<T extends com.google.gwt.user.client.ui.IsWidget>
T
getWidget(String id, Class<T> clazz)
          Retrieve a widget contained on this screen, casting it to the given class
 String getWidth()
          Retrieve the view width;
protected  boolean hasHistoryHandlers()
           
protected  boolean hasOrientationChangeHandlers()
           
protected  boolean hasResizeHandlers()
           
protected  boolean hasWindowCloseHandlers()
           
protected  boolean hasWindowClosingHandlers()
           
protected abstract  Map<String> initializeLazyDependencies()
          Called when the view are loaded to initialize the lazy dependencies map
protected  boolean initializeLazyDependentWidget(String widgetId)
          Call the LazyPanel.ensureWidget() method of the given lazyPanel.
 boolean isActive()
          Reads the active property.
 boolean isLoaded()
          Return true if the view was loaded into a container.
static boolean isOrientationChangeSupported()
           
 FastList<com.google.gwt.user.client.ui.Widget> listWidgets()
           
 FastList<String> listWidgetsId()
           
protected  void load(Object paramenter)
          Called by the ViewContainer when the view is added to the container.
static
<T extends View>
T
of(Object viewAware)
          Retrieve the current view associated with a controller, datasource, or other ViewAware object
protected  void prepareViewObjects()
           
protected  void registerLoadedView()
          Register current view into the loaded views list
 boolean removeFromContainer()
          Remove the current view from its container, if the view is loaded into a container
 void removeWidget(String id)
          Removes the given widget from this view.
 void removeWidget(String id, boolean removeFromDOM)
          Removes the given widget from this view.
protected abstract  void render(com.google.gwt.user.client.ui.Panel rootPanel, View.RenderCallback renderCallback)
          Called by View container to render the view into the screen
protected  void setActive(Object parameter)
          Mark this view as active
protected  void setContainer(ViewContainer viewContainer)
          Bind the view to a container.
protected  boolean setDeactivated(boolean skipEvent)
          Mark this view as active
 void setHeight(String height)
          Set the views height;
 void setTitle(String title)
           
 void setWidth(String width)
          Set the view width;
protected  boolean unload()
          Called by the ViewContainer when the view is removed from the container.
protected  void unregisterLoadedView()
          Remove current view from the loaded views list
protected abstract  void updateViewHeight(String height)
           
protected abstract  void updateViewWidth(String width)
           
 FastList<String> widgetsIdList()
          Retrieve a list with all widgets identifiers present into this view
 FastList<com.google.gwt.user.client.ui.Widget> widgetsList()
          Retrieve a list with all widgets present into this view
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lazyWidgets

protected Map<String> lazyWidgets

widgets

protected FastMap<com.google.gwt.user.client.ui.Widget> widgets

active

protected boolean active

resizeHandlers

protected FastList<com.google.gwt.event.logical.shared.ResizeHandler> resizeHandlers

windowCloseHandlers

protected FastList<com.google.gwt.event.logical.shared.CloseHandler<com.google.gwt.user.client.Window>> windowCloseHandlers

windowClosingHandlers

protected FastList<com.google.gwt.user.client.Window.ClosingHandler> windowClosingHandlers

attachHandlers

protected FastList<ViewActivateHandler> attachHandlers

detachHandlers

protected FastList<ViewDeactivateHandler> detachHandlers

historyHandlers

protected FastList<com.google.gwt.event.logical.shared.ValueChangeHandler<String>> historyHandlers

orientationHandlers

protected FastList<OrientationChangeHandler> orientationHandlers

loadHandlers

protected FastList<ViewLoadHandler> loadHandlers

unloadHandlers

protected FastList<ViewUnloadHandler> unloadHandlers

loaded

protected boolean loaded

width

protected String width

height

protected String height
Constructor Detail

View

public View(String id)
Constructor

Parameters:
id -
Method Detail

getId

public String getId()
Retrieve the view identifier

Returns:

getTitle

public String getTitle()
Retrieve the view title

Returns:

setTitle

public void setTitle(String title)
Parameters:
title -

isLoaded

public boolean isLoaded()
Return true if the view was loaded into a container.

Returns:

getWidth

public String getWidth()
Retrieve the view width;

Returns:

setWidth

public void setWidth(String width)
Set the view width;


getHeight

public String getHeight()
Retrieve the view height;

Returns:

setHeight

public void setHeight(String height)
Set the views height;


updateViewHeight

protected abstract void updateViewHeight(String height)

updateViewWidth

protected abstract void updateViewWidth(String width)

createDataSource

public abstract DataSource<?> createDataSource(String dataSource)
Create a new DataSource instance

Parameters:
dataSource - dataSource name, declared with @DataSource annotation
Returns:
new dataSource instance

addWidget

public void addWidget(String id,
                      com.google.gwt.user.client.ui.Widget widget)
Add a new widget into this view

Parameters:
id - widget identifier
widget - the widget

addWidget

public void addWidget(String id,
                      com.google.gwt.user.client.ui.IsWidget widget)
Add a new widget into this view

Parameters:
id - widget identifier
widget - the widget

containsWidget

public boolean containsWidget(String id)
Verify if the view contains an widget associated with the given identifier

Parameters:
id - widget identifier
Returns:
true if widget is present

addToHistory

public static void addToHistory(String token)
Adds a new token for history control.

Parameters:
token -

addToHistory

public static void addToHistory(String token,
                                boolean issueEvent)
Adds a new token for history control.

Parameters:
token -
issueEvent -

getWidget

public com.google.gwt.user.client.ui.Widget getWidget(String id)
Retrieve a widget contained on this view. If the the requested widget does not exists, we check if a request for a lazy creation of this widget was previously done. If so, we initialize the wrapper required panel (according with lazyWidgets map) and try again.

Parameters:
id - widget identifier
Returns:
the widget

getController

public <T> T getController(String controller)
Retrieve the requested controller from this view

Type Parameters:
T - Controller type
Parameters:
controller - Controller name
Returns:

getContainer

public ViewContainer getContainer()
Retrieve the container that holds this view

Returns:
Parent container or null if this view does not belong to any container.

getWidget

public com.google.gwt.user.client.ui.Widget getWidget(String id,
                                                      boolean checkLazyDependencies)
Retrieve a widget contained on this screen.

Parameters:
id - widget identifier
checkLazyDependencies - if false, lazy dependencies will not be loaded
Returns:
the widget

getWidget

public <T extends com.google.gwt.user.client.ui.IsWidget> T getWidget(String id,
                                                                      Class<T> clazz)
Retrieve a widget contained on this screen, casting it to the given class

Type Parameters:
T -
Parameters:
id - widget identifier
clazz - The class to be used to cast the widget
Returns:
the widget

removeWidget

public void removeWidget(String id)
Removes the given widget from this view.

Parameters:
id - widget identifier

removeWidget

public void removeWidget(String id,
                         boolean removeFromDOM)
Removes the given widget from this view.

Parameters:
id - widget identifier
removeFromDOM - if true, also removes the widget from this parent widget

listWidgetsId

public FastList<String> listWidgetsId()
Returns:

listWidgets

public FastList<com.google.gwt.user.client.ui.Widget> listWidgets()
Returns:

isActive

public boolean isActive()
Reads the active property.

Specified by:
isActive in interface HasViewActivateHandlers
Returns:

addResizeHandler

public com.google.gwt.event.shared.HandlerRegistration addResizeHandler(com.google.gwt.event.logical.shared.ResizeHandler handler)
Specified by:
addResizeHandler in interface HasViewResizeHandlers
Parameters:
handler -
Returns:

isOrientationChangeSupported

public static boolean isOrientationChangeSupported()
Returns:
true is this page supports orientationChange and false otherwise.

addWindowOrientationChangeHandler

public com.google.gwt.event.shared.HandlerRegistration addWindowOrientationChangeHandler(OrientationChangeHandler handler)
Specified by:
addWindowOrientationChangeHandler in interface HasOrientationChangeHandler

addWindowCloseHandler

public com.google.gwt.event.shared.HandlerRegistration addWindowCloseHandler(com.google.gwt.event.logical.shared.CloseHandler<com.google.gwt.user.client.Window> handler)
Specified by:
addWindowCloseHandler in interface HasWindowCloseHandlers
Parameters:
handler -
Returns:

addWindowClosingHandler

public com.google.gwt.event.shared.HandlerRegistration addWindowClosingHandler(com.google.gwt.user.client.Window.ClosingHandler handler)
Parameters:
handler -
Returns:

addViewActivateHandler

public com.google.gwt.event.shared.HandlerRegistration addViewActivateHandler(ViewActivateHandler handler)
Specified by:
addViewActivateHandler in interface HasViewActivateHandlers

addViewDeactivateHandler

public com.google.gwt.event.shared.HandlerRegistration addViewDeactivateHandler(ViewDeactivateHandler handler)
Specified by:
addViewDeactivateHandler in interface HasViewActivateHandlers

addViewLoadHandler

public com.google.gwt.event.shared.HandlerRegistration addViewLoadHandler(ViewLoadHandler handler)
Specified by:
addViewLoadHandler in interface HasViewLoadHandlers

addViewUnloadHandler

public com.google.gwt.event.shared.HandlerRegistration addViewUnloadHandler(ViewUnloadHandler handler)
Specified by:
addViewUnloadHandler in interface HasViewLoadHandlers

addWindowHistoryChangedHandler

public com.google.gwt.event.shared.HandlerRegistration addWindowHistoryChangedHandler(com.google.gwt.event.logical.shared.ValueChangeHandler<String> handler)
Parameters:
handler -
Returns:

widgetsIdList

public FastList<String> widgetsIdList()
Retrieve a list with all widgets identifiers present into this view

Returns:

widgetsList

public FastList<com.google.gwt.user.client.ui.Widget> widgetsList()
Retrieve a list with all widgets present into this view

Returns:

removeFromContainer

public boolean removeFromContainer()
Remove the current view from its container, if the view is loaded into a container

Returns:
true if the view is unloaded

hasResizeHandlers

protected boolean hasResizeHandlers()
Returns:

hasOrientationChangeHandlers

protected boolean hasOrientationChangeHandlers()
Returns:

hasWindowCloseHandlers

protected boolean hasWindowCloseHandlers()
Returns:

hasWindowClosingHandlers

protected boolean hasWindowClosingHandlers()
Returns:

hasHistoryHandlers

protected boolean hasHistoryHandlers()
Returns:

fireResizeEvent

protected void fireResizeEvent(com.google.gwt.event.logical.shared.ResizeEvent event)
Parameters:
event -

fireOrientationEvent

protected void fireOrientationEvent()

fireWindowCloseEvent

protected void fireWindowCloseEvent(com.google.gwt.event.logical.shared.CloseEvent<com.google.gwt.user.client.Window> event)
Parameters:
event -

fireWindowClosingEvent

protected void fireWindowClosingEvent(com.google.gwt.user.client.Window.ClosingEvent event)
Parameters:
event -

fireHistoryChangeEvent

protected void fireHistoryChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent<String> event)
Parameters:
event -

fireLoadEvent

protected void fireLoadEvent(Object paramenter)
Fires the load event


fireUnloadEvent

protected boolean fireUnloadEvent()
Fires the unload event.

Returns:
true if the view can be unloaded. If any event handler cancel the event, the view is not unloaded

setActive

protected void setActive(Object parameter)
Mark this view as active

Parameters:
parameter - to be passed to activate event

setDeactivated

protected boolean setDeactivated(boolean skipEvent)
Mark this view as active

Parameters:
skipEvent -

load

protected void load(Object paramenter)
Called by the ViewContainer when the view is added to the container. This method creates the view widgets

Parameters:
parameter - parameter sent to view and accessible through ViewLoadEvent event

unload

protected boolean unload()
Called by the ViewContainer when the view is removed from the container.

Returns:
true if the view is not loaded

registerLoadedView

protected void registerLoadedView()
Register current view into the loaded views list


unregisterLoadedView

protected void unregisterLoadedView()
Remove current view from the loaded views list


prepareViewObjects

protected void prepareViewObjects()

clearViewObjects

protected void clearViewObjects()
When view is unloaded, we must free its allocated memory.


cleanLazyDependentWidgets

protected void cleanLazyDependentWidgets(String widgetId)
Parameters:
widgetId -

checkRuntimeLazyDependency

protected void checkRuntimeLazyDependency(String id,
                                          String lazyPanelId)
When we have multi-level inner lazy panels, the most inside panel is dependent from the most outside one. If the most outside is loaded, a new dependency must be created for the inner lazy panels not yet loaded.

Parameters:
id -
lazyPanelId -

initializeLazyDependentWidget

protected boolean initializeLazyDependentWidget(String widgetId)
Call the LazyPanel.ensureWidget() method of the given lazyPanel. This method can trigger other dependent lazyPanel initialization, through a recursive call to View.getWidget(String).

Parameters:
widgetId - lazyPanel to be loaded
Returns:
true if some lazyPanel was really loaded for this request

getRegisteredControllers

public abstract RegisteredControllers getRegisteredControllers()
Retrieve the list of controllers registered into this view

Returns:

getIocContainer

public abstract IocContainer getIocContainer()
Retrieve the IoCContainer instance associated with this view

Returns:

render

protected abstract void render(com.google.gwt.user.client.ui.Panel rootPanel,
                               View.RenderCallback renderCallback)
Called by View container to render the view into the screen

Parameters:
rootPanel - The root element where the view elements will be rendered.

createWidgets

protected abstract void createWidgets()
                               throws InterfaceConfigException
Called by View container to create the view widgets

Throws:
InterfaceConfigException

initializeLazyDependencies

protected abstract Map<String> initializeLazyDependencies()
Called when the view are loaded to initialize the lazy dependencies map


getPrefix

protected String getPrefix()
Retrieve the view prefix. It is used to isolate all elements from this view on DOM

Returns:

setContainer

protected void setContainer(ViewContainer viewContainer)
Bind the view to a container. Called by the ViewContainer add method.

Parameters:
viewContainer -

getView

public static <T extends View> T getView(String id)
Retrieve the view by its identifier

Parameters:
id - view identifier
Returns:
the view or null if there is no view loaded into the screen with this identifier

of

public static <T extends View> T of(Object viewAware)
Retrieve the current view associated with a controller, datasource, or other ViewAware object

Parameters:
viewAware -
Returns:

getResource

public static com.google.gwt.resources.client.ClientBundle getResource(String id)
Retrieve the client bundle associated with the given id. To map a client bundle interface to an identifier, use the Resource annotation

Parameters:
id -
Returns:

addResource

protected static void addResource(String id,
                                  com.google.gwt.resources.client.ClientBundle resource)
Parameters:
id -
resource -

containsResource

public static boolean containsResource(String id)
Returns true if a resource associated with the given identifiers was loaded by application

Parameters:
id -
Returns:


Copyright © 2014. All rights reserved.