kill stupid tab bug
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / ChoiceEditor.mxml
index bd24994041f001031ac736016f0123fe80884d46..deb1dedb8258947f7636cf4769b67819d3203e06 100644 (file)
@@ -2,43 +2,71 @@
 <edit:SingleTagEditor
        xmlns:mx="http://www.adobe.com/2006/mxml" 
        xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
-       verticalGap="0"
-       width="100%"
-       toolTip="{fieldDescription}">
+       toolTip="{fieldDescription}"
+    direction="{fieldDirection}" styleName="titledEditor">
 
   <mx:Label text="{fieldName}:"/>
   <edit:ChoiceComboBox id="inputBox" dataProvider="{choices}" selectedItem="{selectFromTag}"
-      width="100%" change="value = inputBox.selectedItem.value"
+      change="value = inputBox.selectedItem.value"
       open="inputBox.dropdown.variableRowHeight = true">
       <edit:itemRenderer>
         <mx:Component>
-        <mx:HBox toolTip="{data.description}">
+        <mx:HBox toolTip="{data.description}" horizontalScrollPolicy="off">
           <mx:Image source="{data.icon}"/>
-          <mx:Label text="{data.label}"/>
+          <mx:Label htmlText="{data.label}"/>
         </mx:HBox>
         </mx:Component>
       </edit:itemRenderer>
   </edit:ChoiceComboBox>
 
   <mx:Script><![CDATA[
+      import mx.collections.*;
+      import mx.utils.*;
+      import net.systemeD.potlatch2.mapfeatures.Feature;
+      
+      private var _choices:ArrayCollection = null;
+      private var _unknownChoice:Choice = null;
 
       [Bindable(event="factory_set")]
-      private function get choices():Array {
-          return ChoiceEditorFactory(_factory).choices;
+      protected function get choices():ArrayCollection {
+          if ( _choices == null ) {
+              _choices = new ArrayCollection();
+              for each ( var choice:Choice in ChoiceEditorFactory(_factory).choices )
+                  _choices.addItem(choice);
+              _choices.addItem(createUnsetChoice());
+          }
+          return _choices;
       }
       
       [Bindable(event="tag_changed")]
-      private function get selectFromTag():Object {
+      protected function get selectFromTag():Object {
           var tagValue:String = value;
-          for each(var choice:Object in choices) {
-              if ( choice.value == tagValue )
+          for each(var choice:Choice in choices) {
+              if ( choice.isTagMatch(tagValue) )
                   return choice;
           }
           
-          inputBox.prompt = tagValue == null ? "" : tagValue;
-          return null;
+          // set up the unknown choice
+          if ( _unknownChoice == null ) {
+              _unknownChoice = new Choice();
+              _unknownChoice.description = "Unknown value";
+              _choices.addItem(_unknownChoice);
+          }
+          _unknownChoice.label = "<i>Unknown:</i> "+Feature.htmlEscape(tagValue);
+          _unknownChoice.icon = null;
+          _unknownChoice.value = tagValue;
+          
+          return _unknownChoice;
       }
       
+      private function createUnsetChoice():Choice {
+          var choice:Choice = new Choice();
+          choice.icon = null;
+          choice.description = "Field not set";
+          choice.label = "<font color='#a0a0a0'><i>Unset</i></font>";
+          choice.value = null;
+          return choice;
+      }
   ]]></mx:Script>
 </edit:SingleTagEditor>