home *** CD-ROM | disk | FTP | other *** search
/ One Click 21 (Special) / OC021.iso / Interface / it.dig / scripts / __Packages / mx / data / binding / ComponentMixins.as < prev    next >
Encoding:
Text File  |  2006-07-04  |  8.6 KB  |  286 lines

  1. class mx.data.binding.ComponentMixins
  2. {
  3.    var __refreshing;
  4.    var __bindings;
  5.    var __schema;
  6.    var __fieldCache;
  7.    var _eventDispatcher;
  8.    var dispatchQueue;
  9.    var __highPrioEvents;
  10.    var _databinding_original_dispatchEvent;
  11.    function ComponentMixins()
  12.    {
  13.    }
  14.    function refreshFromSources()
  15.    {
  16.       if(this.__refreshing != null)
  17.       {
  18.          return undefined;
  19.       }
  20.       this.__refreshing = true;
  21.       _global.__dataLogger.logData(this,"Refreshing from sources");
  22.       _global.__dataLogger.nestLevel = _global.__dataLogger.nestLevel + 1;
  23.       mx.data.binding.Binding.refreshFromSources(this,null,this.__bindings);
  24.       _global.__dataLogger.nestLevel--;
  25.       this.__refreshing = null;
  26.    }
  27.    function refreshDestinations()
  28.    {
  29.       _global.__dataLogger.logData(this,"Refreshing Destinations");
  30.       _global.__dataLogger.nestLevel = _global.__dataLogger.nestLevel + 1;
  31.       mx.data.binding.Binding.refreshDestinations(this,this.__bindings);
  32.       _global.__dataLogger.nestLevel--;
  33.    }
  34.    function validateProperty(property, initialMessages)
  35.    {
  36.       var _loc4_ = null;
  37.       var _loc3_ = this.getField(property);
  38.       if(_loc3_ != null)
  39.       {
  40.          _loc4_ = _loc3_.validateAndNotify(null,null,initialMessages);
  41.       }
  42.       else
  43.       {
  44.          _global.__dataLogger.logData(this,"Can\'t validate property \'<property>\' because it doesn\'t exist",{property:property});
  45.       }
  46.       return _loc4_;
  47.    }
  48.    function addBinding(binding)
  49.    {
  50.       if(this.__bindings == undefined)
  51.       {
  52.          this.__bindings = new Array();
  53.       }
  54.       this.__bindings.push(binding);
  55.       var _loc3_ = false;
  56.       if(binding.source.component == this)
  57.       {
  58.          this.getField(binding.source.property,binding.source.location);
  59.          _loc3_ = true;
  60.       }
  61.       if(binding.dest.component == this)
  62.       {
  63.          this.getField(binding.dest.property,binding.dest.location);
  64.          _loc3_ |= Object(binding).is2way;
  65.       }
  66.       if(_loc3_)
  67.       {
  68.          var _loc4_ = binding.dest.component.findSchema(binding.dest.property,binding.dest.location);
  69.          if(_loc4_.readonly)
  70.          {
  71.             binding.source.component.__setReadOnly(true);
  72.          }
  73.       }
  74.    }
  75.    static function initComponent(component)
  76.    {
  77.       var _loc2_ = mx.data.binding.ComponentMixins.prototype;
  78.       if(component.refreshFromSources == undefined)
  79.       {
  80.          component.refreshFromSources = _loc2_.refreshFromSources;
  81.       }
  82.       if(component.refreshDestinations == undefined)
  83.       {
  84.          component.refreshDestinations = _loc2_.refreshDestinations;
  85.       }
  86.       if(component.validateProperty == undefined)
  87.       {
  88.          component.validateProperty = _loc2_.validateProperty;
  89.       }
  90.       if(component.createFieldAccessor == undefined)
  91.       {
  92.          component.createFieldAccessor = _loc2_.createFieldAccessor;
  93.       }
  94.       if(component.createField == undefined)
  95.       {
  96.          component.createField = _loc2_.createField;
  97.       }
  98.       if(component.addBinding == undefined)
  99.       {
  100.          component.addBinding = _loc2_.addBinding;
  101.       }
  102.       if(component.findSchema == undefined)
  103.       {
  104.          component.findSchema = _loc2_.findSchema;
  105.       }
  106.       if(component.getField == undefined)
  107.       {
  108.          component.getField = _loc2_.getField;
  109.       }
  110.       if(component.refreshAndValidate == undefined)
  111.       {
  112.          component.refreshAndValidate = _loc2_.refreshAndValidate;
  113.       }
  114.       if(component.getFieldFromCache == undefined)
  115.       {
  116.          component.getFieldFromCache = _loc2_.getFieldFromCache;
  117.       }
  118.       if(component.getBindingMetaData == undefined)
  119.       {
  120.          component.getBindingMetaData = _loc2_.getBindingMetaData;
  121.       }
  122.       if(component.__setReadOnly == undefined)
  123.       {
  124.          component.__setReadOnly = _loc2_.__setReadOnly;
  125.       }
  126.       if(component.__addHighPrioEventListener == undefined)
  127.       {
  128.          component.__addHighPrioEventListener = _loc2_.__addHighPrioEventListener;
  129.       }
  130.    }
  131.    function createFieldAccessor(property, location, mustExist)
  132.    {
  133.       return mx.data.binding.FieldAccessor.createFieldAccessor(this,property,location,mx.data.binding.FieldAccessor.findElementType(this.__schema,property),mustExist);
  134.    }
  135.    function findSchema(property, location)
  136.    {
  137.       if(typeof location == "string")
  138.       {
  139.          return null;
  140.       }
  141.       var _loc5_ = mx.data.binding.FieldAccessor.findElementType(this.__schema,property);
  142.       if(location != null)
  143.       {
  144.          if(location.path != null)
  145.          {
  146.             location = location.path;
  147.          }
  148.          if(!(location instanceof Array))
  149.          {
  150.             return null;
  151.          }
  152.          var _loc2_ = 0;
  153.          while(_loc2_ < location.length)
  154.          {
  155.             var _loc4_ = location[_loc2_];
  156.             _loc5_ = mx.data.binding.FieldAccessor.findElementType(_loc5_,_loc4_);
  157.             _loc2_ = _loc2_ + 1;
  158.          }
  159.       }
  160.       return _loc5_;
  161.    }
  162.    function createField(property, location)
  163.    {
  164.       var _loc3_ = this.findSchema(property,location);
  165.       var _loc2_ = undefined;
  166.       if(_loc3_.validation != null)
  167.       {
  168.          _loc2_ = mx.data.binding.Binding.getRuntimeObject(_loc3_.validation);
  169.       }
  170.       else
  171.       {
  172.          _loc2_ = new mx.data.binding.DataType();
  173.       }
  174.       _loc2_.setupDataAccessor(this,property,location);
  175.       return _loc2_;
  176.    }
  177.    static function deepEqual(a, b)
  178.    {
  179.       if(a == b)
  180.       {
  181.          return true;
  182.       }
  183.       if(typeof a != typeof b)
  184.       {
  185.          return false;
  186.       }
  187.       if(typeof a != "object")
  188.       {
  189.          return false;
  190.       }
  191.       var _loc3_ = new Object();
  192.       for(var _loc4_ in a)
  193.       {
  194.          if(!mx.data.binding.ComponentMixins.deepEqual(a[_loc4_],b[_loc4_]))
  195.          {
  196.             return false;
  197.          }
  198.          _loc3_[_loc4_] = 1;
  199.       }
  200.       for(_loc4_ in b)
  201.       {
  202.          if(_loc3_[_loc4_] != 1)
  203.          {
  204.             return false;
  205.          }
  206.       }
  207.       return true;
  208.    }
  209.    function getFieldFromCache(property, location)
  210.    {
  211.       for(var _loc5_ in this.__fieldCache)
  212.       {
  213.          var _loc2_ = this.__fieldCache[_loc5_];
  214.          if(_loc2_.property == property && mx.data.binding.ComponentMixins.deepEqual(_loc2_.location,location))
  215.          {
  216.             return _loc2_;
  217.          }
  218.       }
  219.       return null;
  220.    }
  221.    function getField(property, location)
  222.    {
  223.       var _loc2_ = this.getFieldFromCache(property,location);
  224.       if(_loc2_ != null)
  225.       {
  226.          return _loc2_;
  227.       }
  228.       _loc2_ = this.createField(property,location);
  229.       if(this.__fieldCache == null)
  230.       {
  231.          this.__fieldCache = new Array();
  232.       }
  233.       this.__fieldCache.push(_loc2_);
  234.       return _loc2_;
  235.    }
  236.    function refreshAndValidate(property)
  237.    {
  238.       _global.__dataLogger.logData(this,"Refreshing and validating " + property);
  239.       _global.__dataLogger.nestLevel = _global.__dataLogger.nestLevel + 1;
  240.       var _loc3_ = mx.data.binding.Binding.refreshFromSources(this,property,this.__bindings);
  241.       _loc3_ = this.validateProperty(property,_loc3_);
  242.       _global.__dataLogger.nestLevel--;
  243.       return _loc3_ == null;
  244.    }
  245.    function getBindingMetaData(name)
  246.    {
  247.       return this["__" + name];
  248.    }
  249.    function __setReadOnly(setting)
  250.    {
  251.       if(Object(this).editable != undefined)
  252.       {
  253.          Object(this).editable = !setting;
  254.       }
  255.    }
  256.    function __addHighPrioEventListener(event, handler)
  257.    {
  258.       var _loc3_ = this._eventDispatcher == undefined ? this : this._eventDispatcher;
  259.       if(_loc3_.__highPrioEvents == undefined)
  260.       {
  261.          _loc3_.__highPrioEvents = new Object();
  262.       }
  263.       var _loc4_ = "__q_" + event;
  264.       if(_loc3_.__highPrioEvents[_loc4_] == undefined)
  265.       {
  266.          _loc3_.__highPrioEvents[_loc4_] = new Array();
  267.       }
  268.       _global.ASSetPropFlags(_loc3_.__highPrioEvents,_loc4_,1);
  269.       mx.events.EventDispatcher._removeEventListener(_loc3_.__highPrioEvents[_loc4_],event,handler);
  270.       _loc3_.__highPrioEvents[_loc4_].push(handler);
  271.       if(_loc3_._databinding_original_dispatchEvent == undefined)
  272.       {
  273.          _loc3_._databinding_original_dispatchEvent = _loc3_.dispatchEvent;
  274.          _loc3_.dispatchEvent = function(eventObj)
  275.          {
  276.             if(eventObj.target == undefined)
  277.             {
  278.                eventObj.target = this;
  279.             }
  280.             this.dispatchQueue(this.__highPrioEvents,eventObj);
  281.             this._databinding_original_dispatchEvent(eventObj);
  282.          };
  283.       }
  284.    }
  285. }
  286.