37a81f0b39be61fca753d013cd77d69e77f35abd
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / SpeedEditor.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       dropdownFactory="mx.controls.TileList"
12       width="100%" change="value = inputBox.selectedItem.value"
13       open="inputBox.dropdown.variableRowHeight = true"
14       itemRenderer="net.systemeD.potlatch2.mapfeatures.editors.RestrictionRenderer">
15   </edit:ChoiceComboBox>
16
17   <mx:Script><![CDATA[
18       import mx.collections.*;
19       import mx.utils.*;
20       import net.systemeD.potlatch2.mapfeatures.Feature;
21       
22       private var _choices:ArrayCollection = null;
23       private var _unknownChoice:SpeedChoice = null;
24
25       [Bindable(event="factory_set")]
26       protected function get choices():ArrayCollection {
27           if ( _choices == null ) {
28               _choices = new ArrayCollection();
29               for each(var sp:String in
30                   ["5mph", "10mph", "15mph", "20mph", "30mph", "40mph", "50mph", "60mph","70mph",
31                    "10", "20", "50", "60", "90", "100", "110", "130"])
32                   _choices.addItem(new SpeedChoice(sp));
33               _choices.addItem(new SpeedChoice(null));
34           }
35           return _choices;
36       }
37       
38       [Bindable(event="tag_changed")]
39       protected function get selectFromTag():Object {
40           if ( _entity == null )
41               return new SpeedChoice(null);
42           
43           var tagValue:String = value;
44           for each(var choice:SpeedChoice 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 SpeedChoice(tagValue);
52               _choices.addItem(_unknownChoice);
53           }
54           _unknownChoice.value = tagValue;
55           
56           return _unknownChoice;
57       }
58       
59       private function createUnsetChoice():Choice {
60           var choice:Choice = new Choice();
61           choice.icon = null;
62           choice.description = "Field not set";
63           choice.label = "<i>Unset</i>";
64           choice.value = null;
65           return choice;
66       }
67   ]]></mx:Script>
68 </edit:SingleTagEditor>
69