]> git.openstreetmap.org Git - potlatch2.git/blob - net/systemeD/potlatch2/mapfeatures/editors/ChoiceEditor.mxml
That's some messed up stuff right there
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / ChoiceEditor.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <edit:SingleTagEditor
3         xmlns:fx="http://ns.adobe.com/mxml/2009"
4         xmlns:mx="library://ns.adobe.com/flex/mx"
5         xmlns:s="library://ns.adobe.com/flex/spark"
6         xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
7         toolTip="{fieldDescription}"
8     direction="{fieldDirection}" styleName="titledEditor">
9
10   <mx:Label text="{fieldName}:"/>
11   <s:DropDownList id="inputBox" dataProvider="{choices}" selectedItem="{selectFromTag}"
12       change="value = inputBox.selectedItem.value" labelField="label">
13       <s:itemRenderer>
14         <fx:Component>
15         <mx:HBox toolTip="{data.description}" horizontalScrollPolicy="off">
16           <mx:Image source="{Choice(data).icon}"/>
17           <mx:Label htmlText="{data.label}"/>
18         </mx:HBox>
19         </fx:Component>
20       </s:itemRenderer>
21   </s:DropDownList>
22
23   <fx: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               trace("factory is "+ _factory);
35               trace("processing choices for "+ _factory.key); // or .direcction
36               trace("factory is now "+ _factory);
37               _choices = new ArrayCollection();
38               for each ( var choice:Choice in ChoiceEditorFactory(_factory).choices )
39                   trace("added item: "+choice.value);
40                   _choices.addItem(choice);
41               _choices.addItem(createUnsetChoice());
42           }
43           return _choices;
44       }
45       
46       [Bindable(event="tag_changed")]
47       protected function get selectFromTag():Object {
48           var tagValue:String = value;
49           for each(var choice:Choice in choices) {
50               if ( choice.isTagMatch(tagValue) )
51                   return choice;
52           }
53           
54           // set up the unknown choice
55           if ( _unknownChoice == null ) {
56               _unknownChoice = new Choice();
57               _unknownChoice.description = "Unknown value";
58               _choices.addItem(_unknownChoice);
59           }
60           _unknownChoice.label = "<i>Unknown:</i> "+Feature.htmlEscape(tagValue);
61           _unknownChoice.icon = null;
62           _unknownChoice.value = tagValue;
63           
64           return _unknownChoice;
65       }
66       
67       private function createUnsetChoice():Choice {
68           var choice:Choice = new Choice();
69           choice.icon = null;
70           choice.description = "Field not set";
71           choice.label = "<font color='#a0a0a0'><i>Unset</i></font>";
72           choice.value = null;
73           return choice;
74       }
75   ]]></fx:Script>
76 </edit:SingleTagEditor>
77