home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / sky-chopper.swf / scripts / __Packages / mx / data / binding / ComponentMixins.as < prev    next >
Encoding:
Text File  |  2005-09-29  |  7.2 KB  |  249 lines

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