1//////////////////////////////////////////////////////////////////////////////// 2// 3// ADOBE SYSTEMS INCORPORATED 4// Copyright 2006-2007 Adobe Systems Incorporated 5// All Rights Reserved. 6// 7// NOTICE: Adobe permits you to use, modify, and distribute this file 8// in accordance with the terms of the license agreement accompanying it. 9// 10//////////////////////////////////////////////////////////////////////////////// 11 12package mx.binding 13{ 14 15import flash.events.Event; 16import mx.core.mx_internal; 17 18use namespace mx_internal; 19 20[ExcludeClass] 21 22/** 23 * @private 24 */ 25public class RepeaterComponentWatcher extends PropertyWatcher 26{ 27 include "../core/Version.as"; 28 29 //-------------------------------------------------------------------------- 30 // 31 // Constructor 32 // 33 //-------------------------------------------------------------------------- 34 35 /** 36 * @private 37 * 38 * Create a RepeaterComponentWatcher 39 * 40 * @param prop The name of the property to watch. 41 * @param event The event type that indicates the property has changed. 42 * @param listeners The binding objects that are listening to this Watcher. 43 * @param propertyGetter A helper function used to access non-public variables. 44 */ 45 public function RepeaterComponentWatcher(propertyName:String, 46 events:Object, 47 listeners:Array, 48 propertyGetter:Function = null) 49 { 50 super(propertyName, events, listeners, propertyGetter); 51 } 52 53 //-------------------------------------------------------------------------- 54 // 55 // Properties 56 // 57 //-------------------------------------------------------------------------- 58 59 /** 60 * @private 61 */ 62 private var clones:Array; 63 64 /** 65 * @private 66 */ 67 private var original:Boolean = true; 68 69 //-------------------------------------------------------------------------- 70 // 71 // Overridden methods: Watcher 72 // 73 //-------------------------------------------------------------------------- 74 75 /** 76 * @private 77 */ 78 override public function updateChildren():void 79 { 80 if (original) 81 { 82 updateClones(); 83 } 84 else 85 { 86 super.updateChildren(); 87 } 88 } 89 90 /** 91 * @private 92 */ 93 override protected function shallowClone():Watcher 94 { 95 return new RepeaterComponentWatcher(propertyName, events, listeners, propertyGetter); 96 } 97 98 /** 99 * @private 100 */ 101 private function updateClones():void 102 { 103 var components:Array = value as Array; 104 105 if (components) 106 { 107 if (clones) 108 clones = clones.splice(0, components.length); 109 else 110 clones = []; 111 112 for (var i:int = 0; i < components.length; i++) 113 { 114 var clone:RepeaterComponentWatcher = RepeaterComponentWatcher(clones[i]); 115 116 if (!clone) 117 { 118 clone = RepeaterComponentWatcher(deepClone(i)); 119 clone.original = false; 120 clones[i] = clone; 121 } 122 123 clone.value = components[i]; 124 clone.updateChildren(); 125 } 126 } 127 } 128 129 //-------------------------------------------------------------------------- 130 // 131 // Event handlers 132 // 133 //-------------------------------------------------------------------------- 134 135 /** 136 * Invokes super's notifyListeners() on each of the clones. 137 */ 138 override public function notifyListeners(commitEvent:Boolean):void 139 { 140 if (original) 141 { 142 if (clones) 143 { 144 for (var i:int = 0; i < clones.length; i++) 145 { 146 RepeaterComponentWatcher(clones[i]).notifyListeners(commitEvent); 147 } 148 } 149 } 150 151 super.notifyListeners(commitEvent); 152 } 153} 154 155} 156