Merge pull request #16 from gravitystorm/documentation
[potlatch2.git] / net / systemeD / controls / DataGridWarningField.as
1 package net.systemeD.controls {
2         import mx.controls.Label;
3         import mx.controls.listClasses.*;
4         import flash.display.DisplayObject;
5         import mx.controls.Image;
6
7     /**
8     * The DataGridWarningField is a custom Label component that highlights values containing semicolons.
9     * It does so using colour and a warning icon. Simply use in place of a standard Label component, or use
10     * as a custom itemRenderer for a DataGridColumn.
11     *
12     * @see PromptingTextInputWarning
13     */
14
15         public class DataGridWarningField extends Label {
16
17                 private var _image:Image;
18                 [Embed(source="../../../embedded/warning.png")] private var warningIcon:Class;
19                 private var _whiteList:Array = ["source","collection_times","service_times","smoking_hours","opening_hours"];
20
21                 function DataGridWarningField():void {
22                         super();
23                         setStyle('paddingLeft',2);
24                 }
25
26                 override protected function createChildren():void {
27                         super.createChildren();
28                         _image = new Image();
29                         _image.source = warningIcon;
30                         _image.width = 16;
31                         _image.height = 16;
32                         addChild(DisplayObject(_image));
33                 }
34
35                 override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
36                         super.updateDisplayList(unscaledWidth, unscaledHeight);
37
38                         if (data.value && (_whiteList.indexOf(data.key)==-1) && (data.value.indexOf(';')>-1)) { 
39                                 setStyle('color',0xFF0000);
40                                 _image.visible=true;
41                                 _image.x = width -_image.width -5;
42                                 _image.y = height-_image.height-3;
43                                 _image.toolTip = "The tag contains more than one value - please check";
44                                 textField.width = width-_image.width-5;
45                         } else {
46                                 setStyle('color',0);
47                                 _image.visible=false;
48                         }
49                 }
50         }
51 }