1//////////////////////////////////////////////////////////////////////////////// 2// 3// ADOBE SYSTEMS INCORPORATED 4// Copyright 2009 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.automation.delegates.containers 13{ 14 import flash.display.DisplayObject; 15 16 import mx.automation.Automation; 17 import mx.automation.AutomationIDPart; 18 import mx.automation.IAutomationObject; 19 import mx.automation.IAutomationObjectHelper; 20 import mx.automation.delegates.core.ContainerAutomationImpl; 21 import mx.containers.FormItem; 22 import mx.core.mx_internal; 23 24 use namespace mx_internal; 25 26 [Mixin] 27 /** 28 * 29 * Defines the methods and properties required to perform instrumentation for the 30 * FormItem class. 31 * 32 * @see mx.containers.FormItem 33 * 34 * 35 * @langversion 3.0 36 * @playerversion Flash 9 37 * @playerversion AIR 1.1 38 * @productversion Flex 3 39 */ 40 public class FormItemAutomationImpl extends ContainerAutomationImpl 41 { 42 include "../../../core/Version.as"; 43 44 //-------------------------------------------------------------------------- 45 // 46 // Class methods 47 // 48 //-------------------------------------------------------------------------- 49 50 /** 51 * Registers the delegate class for a component class with automation manager. 52 * 53 * @param root The SystemManger of the application. 54 * 55 * @langversion 3.0 56 * @playerversion Flash 9 57 * @playerversion AIR 1.1 58 * @productversion Flex 3 59 */ 60 public static function init(root:DisplayObject):void 61 { 62 Automation.registerDelegateClass(FormItem, FormItemAutomationImpl); 63 } 64 65 /** 66 * @private 67 * storage for the owner component 68 */ 69 protected function get formItem():FormItem 70 { 71 return uiComponent as FormItem; 72 } 73 74 //-------------------------------------------------------------------------- 75 // 76 // Constructor 77 // 78 //-------------------------------------------------------------------------- 79 80 /** 81 * Constructor. 82 * 83 * @param obj The FormItem object to be automated. 84 * 85 * @langversion 3.0 86 * @playerversion Flash 9 87 * @playerversion AIR 1.1 88 * @productversion Flex 3 89 */ 90 public function FormItemAutomationImpl(obj:FormItem) 91 { 92 super(obj); 93 94 } 95 96 97 //---------------------------------- 98 // automationValue 99 //---------------------------------- 100 101 /** 102 * @private 103 */ 104 override public function get automationValue():Array 105 { 106 var label:IAutomationObject = formItem.itemLabel as IAutomationObject; 107 var result:Array = [ label ? label.automationName : null ]; 108 /* 109 for (var i:int = 0; i < numAutomationChildren; i++) 110 { 111 var child:IAutomationObject = getAutomationChildAt(i); 112 if (child == label) 113 continue; 114 var x:Array = child.automationValue; 115 if (x && x.length != 0) 116 result.push(x); 117 }*/ 118 // changing the above code to avoid the usage of getAutomationChildAt. 119 var childArray:Array = getAutomationChildren(); 120 if (childArray) 121 { 122 var n:int = childArray.length; 123 for (var i:int = 0; i < n; i++) 124 { 125 var child:IAutomationObject = childArray[i] as IAutomationObject; 126 if (child == label) 127 continue; 128 var x:Array = child.automationValue; 129 if (x && x.length != 0) 130 result.push(x); 131 } 132 } 133 return result; 134 } 135 136 //---------------------------------- 137 // numAutomationChildren 138 //---------------------------------- 139 140 /** 141 * @private 142 */ 143 override public function get numAutomationChildren():int 144 { 145 return formItem.numChildren + (formItem.itemLabel != null ? 1 : 0); 146 } 147 148 /** 149 * @private 150 */ 151 override public function createAutomationIDPart(child:IAutomationObject):Object 152 { 153 var help:IAutomationObjectHelper = Automation.automationObjectHelper; 154 return help.helpCreateIDPart(uiAutomationObject, child, getItemAutomationName); 155 } 156 157 override public function createAutomationIDPartWithRequiredProperties(child:IAutomationObject, properties:Array):Object 158 { 159 var help:IAutomationObjectHelper = Automation.automationObjectHelper; 160 return help.helpCreateIDPartWithRequiredProperties(uiAutomationObject, child,properties, getItemAutomationName); 161 } 162 163 /** 164 * @private 165 */ 166 override public function getAutomationChildAt(index:int):IAutomationObject 167 { 168 var labelObj:IAutomationObject = formItem.itemLabel as IAutomationObject; 169 return (index == formItem.numChildren && labelObj != null 170 ? (labelObj) 171 : super.getAutomationChildAt(index)); 172 } 173 174 /** 175 * @private 176 */ 177 override public function getAutomationChildren():Array 178 { 179 var childList:Array = new Array(); 180 var labelObj:IAutomationObject = formItem.itemLabel as IAutomationObject; 181 // we need to add the label object and the children of the form also 182 183 var tempArray1:Array = super.getAutomationChildren(); 184 if(tempArray1) 185 { 186 var n:int = tempArray1.length; 187 for (var i:int = 0; i < n ; i++) 188 { 189 childList.push(tempArray1[i]); 190 } 191 } 192 193 if(labelObj) 194 childList.push(labelObj); 195 196 return childList; 197 } 198 /** 199 * @private 200 */ 201 private function getItemAutomationName(child:IAutomationObject):String 202 { 203 var labelObj:IAutomationObject = formItem.itemLabel as IAutomationObject; 204 var label:String = labelObj ? labelObj.automationName : ""; 205 var result:String = null; 206 if (child.automationName && child.automationName.length != 0) 207 result = (((label)&&(label.length != 0)) 208 ? label + ":" + child.automationName 209 : child.automationName); 210 else 211 { 212 /* 213 for (var i:uint = 0; !result && i < numAutomationChildren; i++) 214 { 215 if (getAutomationChildAt(i) == child) 216 { 217 result = (i == 0 && 218 numAutomationChildren == (labelObj ? 2 : 1) 219 ? label 220 : label + ":" + i); 221 } 222 } 223 */ 224 // changing the above code to avoid the usage of getAutomationChildAt. 225 var childArray:Array = getAutomationChildren(); 226 if (childArray) 227 { 228 var n:int = childArray.length; 229 for (var i:uint = 0; !result && i < n; i++) 230 { 231 if (childArray[i] == child) 232 { 233 result = (i == 0 && 234 n == (labelObj ? 2 : 1) 235 ? label 236 : label + ":" + i); 237 } 238 } 239 } 240 } 241 return result; 242 } 243 244 245 246 } 247} 248