deb1dedb8258947f7636cf4769b67819d3203e06
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / ChoiceEditor.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <edit:SingleTagEditor
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
5         toolTip="{fieldDescription}"
6     direction="{fieldDirection}" styleName="titledEditor">
7
8   <mx:Label text="{fieldName}:"/>
9   <edit:ChoiceComboBox id="inputBox" dataProvider="{choices}" selectedItem="{selectFromTag}"
10       change="value = inputBox.selectedItem.value"
11       open="inputBox.dropdown.variableRowHeight = true">
12       <edit:itemRenderer>
13         <mx:Component>
14         <mx:HBox toolTip="{data.description}" horizontalScrollPolicy="off">
15           <mx:Image source="{data.icon}"/>
16           <mx:Label htmlText="{data.label}"/>
17         </mx:HBox>
18         </mx:Component>
19       </edit:itemRenderer>
20   </edit:ChoiceComboBox>
21
22   <mx:Script><![CDATA[
23       import mx.collections.*;
24       import mx.utils.*;
25       import net.systemeD.potlatch2.mapfeatures.Feature;
26       
27       private var _choices:ArrayCollection = null;
28       private var _unknownChoice:Choice = null;
29
30       [Bindable(event="factory_set")]
31       protected function get choices():ArrayCollection {
32           if ( _choices == null ) {
33               _choices = new ArrayCollection();
34               for each ( var choice:Choice in ChoiceEditorFactory(_factory).choices )
35                   _choices.addItem(choice);
36               _choices.addItem(createUnsetChoice());
37           }
38           return _choices;
39       }
40       
41       [Bindable(event="tag_changed")]
42       protected function get selectFromTag():Object {
43           var tagValue:String = value;
44           for each(var choice:Choice in choices) {
45               if ( choice.isTagMatch(tagValue) )
46                   return choice;
47           }
48           
49           // set up the unknown choice
50           if ( _unknownChoice == null ) {
51               _unknownChoice = new Choice();
52               _unknownChoice.description = "Unknown value";
53               _choices.addItem(_unknownChoice);
54           }
55           _unknownChoice.label = "<i>Unknown:</i> "+Feature.htmlEscape(tagValue);
56           _unknownChoice.icon = null;
57           _unknownChoice.value = tagValue;
58           
59           return _unknownChoice;
60       }
61       
62       private function createUnsetChoice():Choice {
63           var choice:Choice = new Choice();
64           choice.icon = null;
65           choice.description = "Field not set";
66           choice.label = "<font color='#a0a0a0'><i>Unset</i></font>";
67           choice.value = null;
68           return choice;
69       }
70   ]]></mx:Script>
71 </edit:SingleTagEditor>
72