fa03e3aa3e5a304c87837e9897bd8293ed6fd5ec
[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         verticalGap="0"
6         width="100%"
7         toolTip="{fieldDescription}">
8
9   <mx:Label text="{fieldName}:"/>
10   <edit:ChoiceComboBox id="inputBox" dataProvider="{choices}" selectedItem="{selectFromTag}"
11       width="100%" change="value = inputBox.selectedItem.value"
12       open="inputBox.dropdown.variableRowHeight = true">
13       <edit:itemRenderer>
14         <mx:Component>
15         <mx:HBox toolTip="{data.description}">
16           <mx:Image source="{data.icon}"/>
17           <mx:Label htmlText="{data.label}"/>
18         </mx:HBox>
19         </mx:Component>
20       </edit:itemRenderer>
21   </edit:ChoiceComboBox>
22
23   <mx:Script><![CDATA[
24       import mx.collections.*;
25       import mx.utils.*;
26       import net.systemeD.potlatch2.mapfeatures.Feature;
27       
28       private var _choices:ArrayCollection = null;
29       private var _unknownChoice:Choice = null;
30
31       [Bindable(event="factory_set")]
32       protected function get choices():ArrayCollection {
33           if ( _choices == null ) {
34               _choices = new ArrayCollection();
35               for each ( var choice:Choice in ChoiceEditorFactory(_factory).choices )
36                   _choices.addItem(choice);
37               _choices.addItem(createUnsetChoice());
38           }
39           return _choices;
40       }
41       
42       [Bindable(event="tag_changed")]
43       protected function get selectFromTag():Object {
44           var tagValue:String = value;
45           for each(var choice:Choice in choices) {
46               if ( choice.isTagMatch(tagValue) )
47                   return choice;
48           }
49           
50           // set up the unknown choice
51           if ( _unknownChoice == null ) {
52               _unknownChoice = new Choice();
53               _unknownChoice.description = "Unknown value";
54               _choices.addItem(_unknownChoice);
55           }
56           _unknownChoice.label = "<i>Unknown:</i> "+Feature.htmlEscape(tagValue);
57           _unknownChoice.icon = null;
58           _unknownChoice.value = tagValue;
59           
60           return _unknownChoice;
61       }
62       
63       private function createUnsetChoice():Choice {
64           var choice:Choice = new Choice();
65           choice.icon = null;
66           choice.description = "Field not set";
67           choice.label = "<i>Unset</i>";
68           choice.value = null;
69           return choice;
70       }
71   ]]></mx:Script>
72 </edit:SingleTagEditor>
73