Fork me on GitHub
Blog
The journal that this archive was targeting has been deleted. Please update your configuration.
Wednesday
Oct102012

Transition Event

A Transition Event is an application Event fired by the Controller after a Behavior Event referencing a Bound Behavior is fired. A Behavior Event by itself just wraps a Behavior Reference and contains an instance of a View Model. If the Behavior is bound to a View, then the Controller has to transition the current View to the bound View, therefore wraps the Behavior Event causing a transition between two Views into a Transition Event object containing the Behavior Event, the View Model and two View References (VR), one referencing the View sending the Behavior Event and the other referencing the receiving View.
//part of JUIPP core
public class TransitionEvent<T> where T : IViewModel, new() 
{
    public BehaviorEvent<T> BehaviorEvent { get; private set; }

    public TransitionEvent(BehaviorEvent<T> behaviorEvent)
    {
        this.BehaviorEvent = behaviorEvent;
    }

    public T ViewModel
    {
        get
        {
            return this.BehaviorEvent.ViewModel;
        } 
        set
        {
            this.BehaviorEvent.ViewModel = value;
        }
    }
    public string ViewReference { get; set; }
    public string PreviousViewReference { get; set; }
}
Wednesday
Oct102012

Behavior Reference 

For every behavior in your application, JUIPP generates a constant identifier matching your behavior name and puts it in the BehaviorReference class for you to be able to refer to a behavior wiout you knowing the actual concrete implementation of the view. It enables Views to reference a Behavior when sending a Behavior Event (BE) to the Controller (C) without being aware of the concrete Behavior and how it is created.

//Generated by JUIPP
public static class BehaviorReference 
{
   public const string OpenHomeBehavior = "OpenHomeBehavior";
   public const string OpenStudentProfileBehavior = "OpenStudentProfileBehavior";
}
Wednesday
Oct102012

View Reference

For every view in your application, JUIPP generates a constant identifier matching your view name and puts it in the ViewReference class for you to be able to refer to a view without you knowing to actual concrete implementation of the view.
//Generated by JUIPP
public static class ViewReference
{
    public const string HomeAdminView = "HomeAdminView";
    public const string HomeView = "HomeView";
    public const string StudentProfileView = "StudentProfileView";
}
Wednesday
Oct102012

Container

The container contains the controller and the main views, and it's in charge of behavior binding by dynamically mapping Behaviors to Views. Depending on runtime conditions such as the role of the current user or any other application level variables the container would bind a Behavior Reference (BR) to a View Reference (VR) which translates later to a Transition Event.
public partial class Container {

    protected override void OnBehaviorBinding()
    {
        base.OnBehaviorBinding();

        // runtime conditional application context
        var isAdminRole = false;

        //dynamic behavior binding
        if(isAdminRole) 
            base.BehaviorBinding.Add(
                BehaviorReference.OpenHomeBehavior, 
                ViewReference.HomeAdminView);
        else 
            base.BehaviorBinding.Add(
                BehaviorReference.OpenHomeBehavior, 
                ViewReference.HomeView);

        base.BehaviorBinding.Add(
            BehaviorReference.OpenStudentProfileBehavior, 
            ViewReference.StudentProfileView);

    }
}
Wednesday
Oct102012

Controller

A Controller (C) is the center of the pattern where all Behavior Events sent by different Views are catched, processed and translated into Transition Events. A controller can determine the concrete Behavior referenced from a Behavior Event and executes the Behavior and if the Behavior is bound to a View then it would transition the current View to the bound View.

public partial class Controller
{
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (this.Page.IsPostBack) return;
        
        //first behavior event of your application
        //that would open the home (default) view
        this.FireBehaviorEvent(
            new BehaviorEvent<StudentViewModel>()
        {
            BehaviorReference = BehaviorReference.OpenHomeBehavior
        });
    }
}