org.sapia.gumby.view
Class View

java.lang.Object
  |
  +--org.sapia.gumby.view.View
All Implemented Interfaces:
Scope

public class View
extends Object
implements Scope

A View (the V of MVC) is a kind of Scope that allows associating user interface components to a model (the M of MVC). Such associations are materialized by Binding instances. The whole process goes as follows:

Components are registered with the view at creation time (this can be done through XML configuration, by using gumby:Register tags).

Then, Binding instances are mapped to these components (through their ID) - this can also be done through XML configuration. A Binding is meant to bind part(s) of the model to a given UI components, and vice-versa - the Binding interface specifies callbacks corresponding to the different use-cases.

Once bindings have been set up, the model (which is an arbitrary, application-specific object) is assigned to the view. When this is done for the first time, the view calls the onBind() method of all its bindings.

It is up to applications to trigger the different operations corresponding to a given MVC lifecycle; more precisely, applications are in charge of implementing the C in MVC.

The following situations can arise:

  1. The user performs input and then clicks a button to indicate that input has completed. An application-specific listener is registered with the button and is notified of the input completion. The listener calls the fireUpateModel() on the View. This internally calls the updateModel() method of all Bindings registered with the view (typically, the bindings assign the input data to the model). Then the listener is in charge of actually handling the newly updated model (for example by performing an SQL update with the model's new data.
  2. The application changes the model by calling setModel() on the View. Then, internally, the onChanged() method of all bindings is called; the bindings should then update their corresponding UI components accordingly.
  3. The model instance remains the same, but its state as somehow been changed. The application should then notify the view that this has occurred by calling fireUpdate() on it. The view then calls onUpdated on all the Bindings that it holds.

Note that developpers are responsible for performant event-handling code: long-running operations can freeze the user interface, a characteristic that is often blamed on Swing, but is in fact the result of poor code.

Author:
Yanick Duchesne
Copyright:
Copyright © 2002-2005 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site
See Also:
Binding

Constructor Summary
View(RenderContext context)
           
 
Method Summary
 Object acquire(String name)
          Returns the object that is mapped to the given name.
 void addBinding(Binding binding)
           
 void fireUpdated()
          Internally calls the onUpdate() method of all bindings held by this instance.
 void fireUpdated(String id)
          Internally calls the onUpdated() method of the binding corresponding to the given identifier.
 void fireUpdateModel()
          Internally calls the updateModel() method of all bindings held by this instance.
 void fireUpdateModel(String id)
          Internally calls the updateModel() method of the binding corresponding to the given identifier.
 Object get(String name)
           
 RenderContext getContext()
           
 Object getModel()
           
 void put(String name, Object o)
           
 void removeBinding(String id)
          Removes the Binding corresponding to the given identifier from ths instance.
 void setModel(Object model)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

View

public View(RenderContext context)
Method Detail

getContext

public RenderContext getContext()
Returns:
this instance's RenderContext.

acquire

public Object acquire(String name)
               throws IllegalArgumentException
Returns the object that is mapped to the given name.

Parameters:
name - a name.
Returns:
an Object.
Throws:
IllegalArgumentException - if no such object could be found.

get

public Object get(String name)
Specified by:
get in interface Scope
Parameters:
name - the name of the object to retrieve.
Returns:
the Object corresponding to the given name, or null if no such object exists.
See Also:
Scope.get(java.lang.String)

put

public void put(String name,
                Object o)
Specified by:
put in interface Scope
Parameters:
name - the name under which to keep the object.
o - an Object.
See Also:
Scope.put(java.lang.String, java.lang.Object)

setModel

public void setModel(Object model)
Parameters:
model - an arbitratry Object.

getModel

public Object getModel()
Returns:
this instance's model.

addBinding

public void addBinding(Binding binding)
Parameters:
binding - a Binding.

removeBinding

public void removeBinding(String id)
Removes the Binding corresponding to the given identifier from ths instance.

Parameters:
id - an binding identifier.

fireUpdated

public void fireUpdated(String id)
Internally calls the onUpdated() method of the binding corresponding to the given identifier.

Parameters:
id - the identifier of a Binding held within this instance.
See Also:
Binding.onUpdated(View, Object)

fireUpdated

public void fireUpdated()
Internally calls the onUpdate() method of all bindings held by this instance.

See Also:
Binding.onUpdated(View, Object)

fireUpdateModel

public void fireUpdateModel(String id)
Internally calls the updateModel() method of the binding corresponding to the given identifier.

Parameters:
id - the identifier of a Binding held within this instance.
See Also:
Binding.updateModel(View, Object)

fireUpdateModel

public void fireUpdateModel()
Internally calls the updateModel() method of all bindings held by this instance.

See Also:
Binding.updateModel(View, Object)


Copyright © 2002 Sapia Open Community, Inc. All Rights Reserved.