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