package custom { import flash.display.Graphics; import flash.display.Shape; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.*; import mx.controls.DataGrid; import mx.controls.Label; import mx.core.BitmapAsset; import mx.core.EdgeMetrics; import mx.core.UIComponent; import mx.events.ResizeEvent; public class ExtendedDataGrid extends DataGrid { [Embed(source="/images/headerBackground.png")] [Bindable] public var imgCls:Class; private var disabledLabel:Label; private var disabledBox:Shape = new Shape(); private var _disabled:Boolean = false; public function ExtendedDataGrid() { super(); } //Remove Header Roll Over Color override protected function mouseOverHandler(event:MouseEvent):void{ super.mouseOverHandler(event); if(selectionLayer.getChildByName("headerSelection")) selectionLayer.removeChild(selectionLayer.getChildByName("headerSelection")); } override protected function mouseDownHandler(event:MouseEvent):void{ super.mouseDownHandler(event); if(selectionLayer.getChildByName("headerSelection")) selectionLayer.removeChild(selectionLayer.getChildByName("headerSelection")); } //Added Background Image for header override protected function drawHeaderBackground(headerBG:UIComponent):void { var g:Graphics = headerBG.graphics; var imgObj:BitmapAsset = new imgCls() as BitmapAsset; g.clear(); var bm:EdgeMetrics = borderMetrics; var adjustedWidth:Number = unscaledWidth - (bm.left + bm.right); maskShape.width = adjustedWidth; var hh:Number = rowInfo.length ? rowInfo[0].height : headerHeight; var vdistance:int; var vstart:int; var vstartOffset:int; var vdistanceOffset:int; // filling in header with embedded background image g.lineStyle(0, 0x000000, 0); g.beginBitmapFill(imgObj.bitmapData); g.moveTo(0, 0); g.lineTo(adjustedWidth, 0); g.lineTo(adjustedWidth, hh); g.lineTo(0, hh); g.lineStyle(0, 0x000000, 0); g.endFill(); } //removed vertical lines from header override protected function drawVerticalLine(s:Sprite, colIndex:int, color:uint, x:Number):void { //draw our vertical lines var g:Graphics = s.graphics; if (lockedColumnCount > 0 && colIndex == lockedColumnCount - 1) g.lineStyle(1, 0, 100); else g.lineStyle(1, color, 100); g.moveTo(x, 20); // add space for header g.lineTo(x, listContent.height); } public function set message(value:String):void{ if (value!=""){ disabledLabel = new Label(); disabledLabel.text = value; disabledLabel.width = 400; disabledLabel.name="disabledLabel"; disabledLabel.x = width/2-70; disabledLabel.y = height/2+120; disabledLabel.includeInLayout = false; parentApplication.addChild(disabledLabel); } else{ if (parentApplication.getChildByName("disabledLabel")) parentApplication.removeChild(disabledLabel); } } public function get disabled():Boolean{ return _disabled; } public function set disabled(value:Boolean):void{ _disabled = value; if (value == true){ disabledBox.name = "disabledBox"; disabledBox.graphics.clear(); disabledBox.graphics.beginFill(0xFFFFFF,.7); disabledBox.graphics.drawRect(0, 25, width, height-25); disabledBox.graphics.endFill(); addEventListener(ResizeEvent.RESIZE,redrawDisable); disabledLabel.name="disabledLabel"; disabledLabel.x = width/2-70; disabledLabel.y = height/2+120; disabledLabel.includeInLayout = false; addChild(disabledBox); parentApplication.addChild(disabledLabel); } else{ if (getChildByName("disabledBox")) removeChild(disabledBox); if (parentApplication.getChildByName("disabledLabel")) parentApplication.removeChild(disabledLabel); removeEventListener(ResizeEvent.RESIZE,redrawDisable); } } private function redrawDisable(evt:ResizeEvent):void{ if (getChildByName("disabledBox")) removeChild(disabledBox); if (parentApplication.getChildByName("disabledLabel")) parentApplication.removeChild(disabledLabel); disabledBox.graphics.clear(); disabledBox.graphics.beginFill(0xCCCCCC,.3); disabledBox.graphics.drawRect(0, 25, width, height-25); disabledBox.graphics.endFill(); addEventListener(ResizeEvent.RESIZE,redrawDisable); disabledLabel.x = width/2-70; disabledLabel.y = height/2+120; disabledLabel.includeInLayout = false; addChild(disabledBox); parentApplication.addChild(disabledLabel); height == 0 ? disabledLabel.visible = false : disabledLabel.visible = true; } } }