Overview | File | Class | Tree | Index | Help
| The Gravey 2.5 Framework and AIM RIA
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## Class MVCView

    Object
       |
       +--GrvObject
             |
             +--MVCView

Direct Known Subclasses:
  EDOCountersView, EDOAppPanelView, MVCController, EDOView, MVCListView, MVCScalarView, EDOHolderView, EDOControlPanelView

class MVCView
extends GrvObject

This class acts as the base class for each (MVC) View.

Views are responsible for keeping up-to-date the HTML associated with a particular portion of the web page identified via a "hook" (i.e. an HTML element ID).

The view should display the current state of the data in the model(s) that it "watches". [NOTE: Views do not "subscribe" to Models and react to their individual update events because all views need to draw in a coordinated top-down fashion.]

Each View is also a container of subviews (as needed) and coordinates their layout by managing some skeleton framework HTML (e.g. tables/divs/spans/etc) to which the subviews hook and manage [I.E. the GoF Composite design pattern].

Once set up, views just react to "draw" events where they draw "this" view and then recurse thru any subviews invoking their draw method. [This is so that any elements of this view that are to be "hooks" for any subviews can be generated by this view first.]

Whenever a MVCController event causes some MVCModel to change, (and after all observing data models have finished their updates), the global "root container" view will initiate a single draw event cascade to update all Views on the page.

"Drawing" entails first looking at the appropriate data model(s) for this view and deciding whether they require "rebuilding" the HTML of this view, and if so, replacing the current HTML with newly generated HTML [via the innerHTML of the HTML Element ID associated with this view]. Then the paint() method is invoked to "decorate" the view with the model(s) current data (i.e. set any HTML attributes that need updating e.g. background color). Normally, HTML need not be constantly rebuilt, only decorated. A special case is where a container needs to rebuild its HTML, all subviews are forced to as well (even if they wouldnt normally based on the views they are watching).

The HTML (in string form) is generated by the abstract method "buildHTMLstr". The abstract method "mustRebuild" decides whether the draw event requires the HTML to be rebuilt before calling "paintHTML" (which is called if "mustRepaint").

     Subclasses of View should define/override:
       (1) buildHTML() constructs this view's HTML
     OR, use the default buildHTML which builds, via innerHTML, the
     HTML string returned from buildHTMLstr(), hence you would
     override instead:
       (1) buildHTMLstr() generates this view's HTML (as string)

       (2) paintHTML() modifies/decorates existing HTML structures
       (3) mustRepaint() decides if this view's HTML needs repainting
       (4) mustRebuild() decides if this view's HTML needs rebuilding
     The default implementation of mustRebuild() requires that
     instead of overriding mustRebuild() instead override:
       (4) currentContext() returns an MVCContext subclass object
           containing the driver information for building this view.

Version: 2.0
Author: Bruce Wallace (PolyGlotInc.com)
See:

- konstructor()

Defined in grvMVC.js

Field Summary
`<static> Object` | `Depth`

Constructor Summary
`MVCView ()`

Method Summary
`void` | `addSubView( viewID, aView )` add the specified view/ID to our subview list
`void` | `block()` API to block/unblock view updating (to stop redraw thrashing)
`boolean` | `build( optForceRebuild )` Recursively build this view and entire subview tree.
`void` | `buildHTML()` Build the HTML for this view.
`String` | `buildHTMLstr()` return an HTML string of the basic structure for this view.
`boolean` | `buildsubviews( optForceRebuild )` Recursively invoke build on entire subview tree.
`void` | `clearSubViews( )` clear the list of subviews of this view
`boolean` | `contextChanged()` return true iff the view context has changed
`MVCContext` | `currentContext()` return the current "context" of this view.
`void` | `delSubView( viewID )` delete the specified view from our subview list
`void` | `disable( )` disable this view (and hence all subviews)
`void` | `draw( optForceRebuild )` if enabled, cause entire subview tree to be built/painted as needed
`String` | `embedAttr( <String> attrID, <MVCView> view )` same as embedHTML() but auto-creates viewID and saves reference to view based on specified "attribute" ID.
`String` | `embedHTML( viewID, view )` same as embedView() but return the HTML string of the view rather than the View object.
`MVCView` | `embedView( viewID, view )` add the specified view/ID as an "embedded" subview.
`void` | `enable( )` enable this view (thereby enabling all enabled subviews)
`element` | `getHook(forceReload)` return the HTML element of this view's hook tag
`MVCView` | `getSubView( viewID )` find the specified view in the tree of subviews
`element` | `getWidget(forceReload)` return the HTML element of this view's widget tag
`String` | `getWidgetID( optAttributeID )` Return the effective ID of the widget for this view.
`String` | `innerID()` return the "inner" view ID for this view
`boolean` | `isVisible()` return whether this view is visible
`void` | `konstructor( <String> optName, <String> optViewID, <boolean> optDisable )`
`boolean` | `mustRebuild()` return true IFF model(s) require the HTML rebuilt for THIS view default implementation: If there is a difference in the current "build context" and the current one then rebuild else not.
`boolean` | `mustRepaint()` return true IFF model(s) require HTML repaint.
`void` | `paint( optForceRepaint )` Recursively invoke paint on entire subview tree.
`void` | `paintHTML()` update/modify attributes of basic existing HTML for THIS view
`boolean` | `rebuildAny()` does this view or any embedded subview need rebuilding?
`void` | `redraw()` if enabled, force a "draw" of this view (and all enabled subviews)
`void` | `setParentView(v)` set the parent view of this view
`void` | `setSubViewsVisible(v)` set all subview visiblility
`void` | `setViewID(ID)` (re)define the view ID for this view
`void` | `setVisible(isVisible)` set this view as visible or not and manifest it via the HTML.
`void` | `unblock()` API to block/unblock view updating (to stop redraw thrashing)
`void` | `updateContext()` update and save the current MVCContext for this view
`void` | `watchModel(<MVCModel> m )` register the given model as our primary data model
`<static> void` | `DrawRoot()` Static method to draw the root view (and hence all views)

Methods inherited from class GrvObject
`souper`

Field Detail

### Depth

    <static> Object Depth

Constructor Detail

### MVCView

    MVCView()

Version: 2.0
Author: Bruce Wallace (PolyGlotInc.com)
See:

- konstructor()

Method Detail

### addSubView

    void addSubView( viewID, aView )

add the specified view/ID to our subview list

### block

    void block()

API to block/unblock view updating (to stop redraw thrashing)

### build

    boolean build( optForceRebuild )

Recursively build this view and entire subview tree.

Returns:

whether rebuild was done.

### buildHTML

    void buildHTML()

Build the HTML for this view. This can be overrided to directly build HTML via DOM operations or use this default implementation that takes an HTML string from buildHTMLstr() and puts it into the innerHTML of this view's hook HTML element. Note that building the HTML for this view implies rebuilding the HTML for all "embedded" subviews.

### buildHTMLstr

    String buildHTMLstr()

return an HTML string of the basic structure for this view. As a side effect, build/update subview list for this view. As a side effect, invoke this method on each nested subview.

Returns:

HTML (suitable for assigning to innerHTML)

### buildsubviews

    boolean buildsubviews( optForceRebuild )

Recursively invoke build on entire subview tree.

Returns:

whether rebuild was done.

### clearSubViews

    void clearSubViews( )

clear the list of subviews of this view

### contextChanged

    boolean contextChanged()

return true iff the view context has changed

### currentContext

    MVCContext currentContext()

return the current "context" of this view. Default is "no rebuild ever needed" (unless others force us to)

### delSubView

    void delSubView( viewID )

delete the specified view from our subview list

### disable

    void disable( )

disable this view (and hence all subviews)

### draw

    void draw( optForceRebuild )

if enabled, cause entire subview tree to be built/painted as needed

### embedAttr

    String embedAttr( <String> attrID, <MVCView> view )

same as embedHTML() but auto-creates viewID and saves reference to view based on specified "attribute" ID.

Parameters:

`attrID` - the identifier of the attribute

`view` - the attribute's subview to embed

Returns:

HTML string

### embedHTML

    String embedHTML( viewID, view )

same as embedView() but return the HTML string of the view rather than the View object.

Returns:

HTML string

### embedView

    MVCView embedView( viewID, view )

add the specified view/ID as an "embedded" subview. Embedded subviews are those whose HTML string is embedded in the HTML string of its parent view. I.E. When buildHTMLstr() is called for a view, it is expected to return a string containing its HTML and all the HTML for its embedded subviews. NOTE: If one subview is embedded then ALL subviews of this view must be embedded.

Returns:

view

### enable

    void enable( )

enable this view (thereby enabling all enabled subviews)

### getHook

    element getHook(forceReload)

return the HTML element of this view's hook tag

### getSubView

    MVCView getSubView( viewID )

find the specified view in the tree of subviews

### getWidget

    element getWidget(forceReload)

return the HTML element of this view's widget tag

### getWidgetID

    String getWidgetID( optAttributeID )

Return the effective ID of the widget for this view. Finesse the fact that the viewID is sometimes the ID of a wrapper tag (e.g. span) and other times is the ID of the actual view's tag. We assume that views that are "embedded" have no wrapper tag, otherwise they do. In any event, the MVCView subclass can say what the "inner" ID is when there is a wrapper.

### innerID

    String innerID()

return the "inner" view ID for this view

### isVisible

    boolean isVisible()

return whether this view is visible

### konstructor

    void konstructor( <String> optName, <String> optViewID, <boolean> optDisable )

Parameters:

`optName` - optional name of this instance

`optViewID` - optional ViewID of this instance. Note that while all views must have a view ID, they are usually assigned an ID at the point where a view is added as a subview to another view via addSubView(), embedView(), etc.

`optDisable` - optional "disable view" flag (default false)

### mustRebuild

    boolean mustRebuild()

return true IFF model(s) require the HTML rebuilt for THIS view default implementation: If there is a difference in the current "build context" and the current one then rebuild else not.

### mustRepaint

    boolean mustRepaint()

return true IFF model(s) require HTML repaint. NOTE: rebuilding view forces repaint of all subviews. NOTE: repainting THIS view does NOT force repaint of subviews.

### paint

    void paint( optForceRepaint )

Recursively invoke paint on entire subview tree.

### paintHTML

    void paintHTML()

update/modify attributes of basic existing HTML for THIS view

### rebuildAny

    boolean rebuildAny()

does this view or any embedded subview need rebuilding?

### redraw

    void redraw()

if enabled, force a "draw" of this view (and all enabled subviews)

### setParentView

    void setParentView(v)

set the parent view of this view

### setSubViewsVisible

    void setSubViewsVisible(v)

set all subview visiblility

### setViewID

    void setViewID(ID)

(re)define the view ID for this view

### setVisible

    void setVisible(isVisible)

set this view as visible or not and manifest it via the HTML. If setting to invisible then we also set all subviews to invisible BUT NOT THE OTHER WAY ROUND!

### unblock

    void unblock()

API to block/unblock view updating (to stop redraw thrashing)

### updateContext

    void updateContext()

update and save the current MVCContext for this view

### watchModel

    void watchModel(<MVCModel> m )

register the given model as our primary data model

Parameters:

`m` - the data model to "watch"

### DrawRoot

    <static> void DrawRoot()

Static method to draw the root view (and hence all views)

Overview | File | Class | Tree | Index | Help
| The Gravey 2.5 Framework and AIM RIA
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Documentation generated by JSDoc on Thu Jan 6 12:46:39 2011