1 Reply Latest reply on Mar 12, 2007 3:24 AM by Tauresul

    Flex & ModelLocator Patern


      I had checked out the ModelLocator pattern. The Caringorm says "centralize the application state and use a StackView for switching views when a workflow application state changes", isn't?.
      Well. The problem is, the StackView work fine while you use switiching views (a view "cover" previous view), but, if the view needs to appear like a Pupup (ussing PopUpManager class) the StackView don't work!. When the event has been dispatched the new thread begins, then I can't know the moment when the Remote operation has been successfull. To try to repair that I'use the next personal technique then I want to share with you for konw your oppinions. Here I go...

      The main app is like this:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      width="100%" height="100%" xmlns:local="*">
      import model.SampleModelLocator;
      import mx.controls.Alert;

      private function switchView( ) : void {

      public var samplemodel : SampleModelLocator = SampleModelLocator.getInstance();
      <mx:VBox width="100%" height="100%" id="sampleApplicationApp">
      <mx:HBox width="100%" height="50%">
      <local:Componente01 click="{ switchView() }"/>
      <local:Componente02 click="Alert.show('Hea Dos')"/>
      <mx:HBox width="100%" height="50%">
      <local:Componente03 click="Alert.show('Hea Tre')"/>
      <local:Componente04 click="Alert.show('Hea Cuatro')"/>

      The Component01's click event changes the application's state directly, but perfecly it can to dispatch an event and then the "Command" action script will do that. Let's check the model locator Action Script out...

      package model {
      import org.nevis.cairngorm.model.ModelLocator;
      import mx.managers.PopUpManager;
      import mx.core.Application;
      import mx.controls.Alert;
      import flash.display.DisplayObject;

      public class SampleModelLocator implements ModelLocator {
      // Código Singleton
      private static var instance : SampleModelLocator;

      public static function getInstance() : SampleModelLocator {
      if ( instance == null )
      instance = new SampleModelLocator();

      return instance;

      public function SampleModelLocator() {
      if ( instance != null )
      throw new Error( "Only one ModelLocator instance should be instantiated" );

      public function changeState(newState : String) : void {
      var isModal:Boolean = true;
      if(REALIZANDO_OPERACION == newState)
      PopUpManager.createPopUp( Application.application.sampleApplicationApp, PopUpSample, isModal);

      public static const INACTIVO : String = "INACTIVO";
      public static const REALIZANDO_OPERACION : String = "REALIZANDO_OPERACION";
      public static const EXITO_DE_LA_OPERACION : String = "EXITO_DE_LA_OPERACION";
      public static const OPERACION_REALIZADA : String = "OPERACION_REALIZADA";
      public var workflowState : String = INACTIVO;

      The state change function centralize the workflow transition, and this function work it self (without external parameters).
      That's work perfecly, but I want to know if you agree with me or know if there are more information about that.

      Regards for all.
        • 1. Re: Flex &amp; ModelLocator Patern
          Hi MeTaLeRoZ :
          I'm just a newbie with Cairngorm architechture, but I agree with you in your usage of ModelLocator. I have quite the same usage of the code, because as you say, there must be a ModelLocator to centralize data flow access.

          And a question for a Cairngorm user. Has anyone started to design applications with Cairngorm in a modular environment? Anyone can help me with this?