 */
 package weave.ui
 {
+	import avmplus.getQualifiedClassName;
+	
 	import flash.display.DisplayObject;
 	import flash.display.DisplayObjectContainer;
 	
 	import mx.containers.Grid;
 	import mx.containers.GridItem;
 	import mx.containers.GridRow;
+	import mx.core.Container;
+	
+	import weave.core.ClassUtils;
 	
 	[DefaultProperty("dataProvider")]
 	

		 * Populates a Grid with a set of items.  It also copies the horizontalAlign and verticalAlign styles from the Grid to each GridItem.
		 * @param grid A Grid container.
		 * @param items A two-dimensional Array of items
		 * @param generator A function that accepts an item and returns a DisplayObject.
		 * @param visitor A function that accepts a GridItem object.
		 */
		public static function populateGrid(grid:Grid, dataProvider:Array, generator:Function = null, visitor:Function = null):void
		{
			var gridRows:Array = initChildren(grid, dataProvider.length, GridRow);
			for (var r:int = 0; r < gridRows.length; r++)

				for (var c:int = 0; c < gridItems.length; c++)
				{
					var gridItem:GridItem = gridItems[c] as GridItem;
					var children:Array = initChildren(gridItem, 1, generator as Class);
					gridRow.addChild(gridItem);
					var dataItem:Object = dataRow[c];
					var displayObject:DisplayObject = dataItem as DisplayObject;
					if (generator is Function)
					{
						displayObject = generator(dataItem) as DisplayObject;
					}
					else if (generator is Class)
					{
						if (!ClassUtils.classExtends(getQualifiedClassName(generator), getQualifiedClassName(Container)))
							throw new Error("If generator is a Class, it must extend Container.");
						var GeneratorClass:Class = generator as Class;
						var container:Container = (children[0] as GeneratorClass || new GeneratorClass()) as Container;
						if (container)
						{
							displayObject = container;
							container.data = dataItem;
						}
					}
					if (displayObject)
						gridItem.addChild(displayObject);
					for each (var style:String in ['horizontalAlign', 'verticalAlign'])
						gridItem.setStyle(style, grid.getStyle(style));
					
