Merge branch 'master' into history
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / SpeedEditor.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:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
6         toolTip="{fieldDescription}"
7         label="{fieldName}:"
8     styleName="titledEditor">
9
10   <mx:VBox> <!-- This wrapper shouldn't be necessary, but without it the layout goes nuts -->
11     <edit:ChoiceComboBox id="inputBox" dataProvider="{choices}" selectedItem="{selectFromTag}"
12         dropdownFactory="mx.controls.TileList"
13         change="value = inputBox.selectedItem.value"
14         itemRenderer="net.systemeD.potlatch2.mapfeatures.editors.RestrictionRenderer"
15         dropdownWidth="250" rowCount="4"
16         fontWeight="normal">
17     </edit:ChoiceComboBox>
18   </mx:VBox>
19
20   <fx:Script><![CDATA[
21       import mx.collections.*;
22       import mx.utils.*;
23       import net.systemeD.potlatch2.mapfeatures.Feature;
24       
25       private var _choices:ArrayCollection = null;
26       private var _unknownChoice:SpeedChoice = null;
27
28       [Bindable(event="factory_set")]
29       protected function get choices():ArrayCollection {
30           if ( _choices == null ) {
31               _choices = new ArrayCollection();
32               for each(var sp:String in
33                   ["5 mph", "10 mph", "15 mph", "20 mph", "25 mph", "30 mph", "35 mph",
34                    "40 mph", "45 mph", "50 mph", "55 mph", "60 mph", "65 mph", "70 mph", "75 mph",
35                    "10", "20", "30", "40", "50", "60", "70", "80", "90", "100", "110", "120", "130"])
36                   _choices.addItem(new SpeedChoice(sp));
37               _choices.addItem(new SpeedChoice(null));
38           }
39           return _choices;
40       }
41       
42       [Bindable(event="tag_changed")]
43       protected function get selectFromTag():Object {
44           if ( _entity == null )
45               return new SpeedChoice(null);
46           
47           var tagValue:String = value;
48           for each(var choice:SpeedChoice in choices) {
49               if ( choice.isTagMatch(tagValue) )
50                   return choice;
51           }
52           
53           // set up the unknown choice
54           if ( _unknownChoice == null ) {
55               _unknownChoice = new SpeedChoice(tagValue);
56               _choices.addItem(_unknownChoice);
57           }
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   ]]></fx:Script>
72 </edit:SingleTagEditor>
73