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 spark.automation.tabularData 13{ 14 import mx.automation.Automation; 15 import mx.automation.IAutomationObject; 16 import mx.automation.IAutomationTabularData; 17 import mx.core.mx_internal; 18 19 import spark.components.IItemRenderer; 20 import spark.components.supportClasses.ListBase; 21 import spark.layouts.HorizontalLayout; 22 import spark.layouts.VerticalLayout; 23 import mx.events.DragEvent; 24 25 use namespace mx_internal; 26 27 /** 28 * @private 29 */ 30 public class SparkListBaseTabularData 31 implements IAutomationTabularData 32 { 33 34 private var sparkList:spark.components.supportClasses.ListBase; 35 36 /** 37 * Constructor 38 * 39 * @langversion 3.0 40 * @playerversion Flash 9 41 * @playerversion AIR 1.1 42 * @productversion Flex 4 43 */ 44 public function SparkListBaseTabularData(l:spark.components.supportClasses.ListBase) 45 { 46 super(); 47 48 sparkList = l; 49 } 50 51 /** 52 * private 53 */ 54 private function getVisibleRows():Array 55 { 56 var visibleRows:Array = new Array(); 57 58 var count:int = sparkList.dataGroup.numElements; 59 for (var i:int = 0; i<count ; i++) 60 { 61 var currentObj:Object = sparkList.dataGroup.getElementAt(i); 62 if( currentObj is IItemRenderer) 63 visibleRows.push(currentObj); 64 } 65 return visibleRows; 66 } 67 68 69 70 71 /** 72 * @inheritDoc 73 * 74 * @langversion 3.0 75 * @playerversion Flash 9 76 * @playerversion AIR 1.1 77 * @productversion Flex 4 78 */ 79 public function get firstVisibleRow():int 80 { 81 if(sparkList.layout is VerticalLayout) 82 return (sparkList.layout as VerticalLayout).firstIndexInView; 83 else if(sparkList.layout is HorizontalLayout) 84 return (sparkList.layout as HorizontalLayout).firstIndexInView; 85 return 0; 86 87 } 88 89 /** 90 * @inheritDoc 91 * 92 * @langversion 3.0 93 * @playerversion Flash 9 94 * @playerversion AIR 1.1 95 * @productversion Flex 4 96 */ 97 public function get lastVisibleRow():int 98 { 99 if(sparkList.layout is VerticalLayout) 100 return (sparkList.layout as VerticalLayout).lastIndexInView ; 101 else if(sparkList.layout is HorizontalLayout) 102 return (sparkList.layout as HorizontalLayout).lastIndexInView ; 103 104 105 // this is index based data. so we need to subtract one from the number of rows. 106 //http://bugs.adobe.com/jira/browse/FLEXENT-1100 107 return numRows-1; 108 109 } 110 111 /** 112 * @inheritDoc 113 * 114 * @langversion 3.0 115 * @playerversion Flash 9 116 * @playerversion AIR 1.1 117 * @productversion Flex 4 118 */ 119 public function get numRows():int 120 { 121 return (sparkList.dataGroup ? sparkList.dataGroup.numElements:0); 122 } 123 124 /** 125 * @inheritDoc 126 * 127 * @langversion 3.0 128 * @playerversion Flash 9 129 * @playerversion AIR 1.1 130 * @productversion Flex 4 131 */ 132 public function get numColumns():int 133 { 134 return 1; 135 } 136 137 /** 138 * @inheritDoc 139 * 140 * @langversion 3.0 141 * @playerversion Flash 9 142 * @playerversion AIR 1.1 143 * @productversion Flex 4 144 */ 145 public function get columnNames():Array 146 { 147 return [ "" ]; 148 } 149 150 /** 151 * @inheritDoc 152 * 153 * @langversion 3.0 154 * @playerversion Flash 9 155 * @playerversion AIR 1.1 156 * @productversion Flex 4 157 */ 158 public function getValues(start:uint = 0, end:uint = 0):Array 159 { 160 // note: getElementAt(i) is based on total elements and it returns 161 // null for the item rendereres if they are not visible 162 // if the useVirtualLayout is true. so we dont need 163 // special handing of the index 164 165 var values:Array = [ ]; 166 if (sparkList.dataGroup) 167 { 168 var alreadyProcessedCount:int = 0; 169 170 if(sparkList.useVirtualLayout == true) 171 { 172 var stopIndex:int = firstVisibleRow; 173 for( var x:int=start; x < stopIndex ; x++ ) 174 { 175 var currentObj1:Object = sparkList.dataGroup.createItemRendererFor(x); 176 // this is only of one column list. Ohter components need to override this metod 177 // to handle appropritely 178 if( currentObj1 is IAutomationObject) 179 { 180 values.push([(currentObj1 as IAutomationObject).automationName]); 181 alreadyProcessedCount++; 182 } 183 } 184 } 185 for (var i:int = start+alreadyProcessedCount; i<=end ; i++) 186 { 187 var currentObj:Object = sparkList.dataGroup.getElementAt(i); 188 // this is only of one column list. Ohter components need to override this metod 189 // to handle appropritely 190 if( currentObj is IAutomationObject) 191 values.push([(currentObj as IAutomationObject).automationName]); 192 } 193 194 if(sparkList.useVirtualLayout == true) 195 { 196 197 for( var x1:int=lastVisibleRow+1; x1 <= end ; x1++ ) 198 { 199 var currentObj2:Object = sparkList.dataGroup.createItemRendererFor(x1); 200 // this is only of one column list. Ohter components need to override this metod 201 // to handle appropritely 202 if( currentObj2 is IAutomationObject) 203 values.push([(currentObj2 as IAutomationObject).automationName]); 204 } 205 } 206 207 } 208 209 210 211 return values; 212 } 213 214 /** 215 * @inheritDoc 216 * 217 * @langversion 3.0 218 * @playerversion Flash 9 219 * @playerversion AIR 1.1 220 * @productversion Flex 4 221 */ 222 public function getAutomationValueForData(data:Object):Array 223 { 224 // convert the data (which is the data corresponding to the selected Item) 225 var itemIndex:int = sparkList.dataProvider.getItemIndex(data) 226 if(sparkList.dataGroup) 227 { 228 var delegate:IAutomationObject = sparkList.dataGroup.getElementAt(itemIndex) as IAutomationObject; 229 if(delegate) 230 { 231 var automationValueArray:Array = delegate.automationValue; 232 if(automationValueArray) 233 return [ automationValueArray.join(" | ") ]; 234 } 235 } 236 else 237 { 238 // we may need to get the renderer deails for the dropdown list in a 239 // different way as no renderers are available (and hence no datagroup) 240 // itslef not present when the dropDown list is not visible. 241 var message:String = "To be handled in SparkListBaseTabularData and it is happening in DropDownList - while getting selected item"; 242 Automation.automationDebugTracer.traceMessage("SparkListBaseTabularData","getAutomationValueForData()",message); 243 } 244 245 return []; 246 } 247 248 249 250 } 251} 252