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