stop erroring every time a category is selected for an untagged way
[potlatch2.git] / net / systemeD / potlatch2 / CategorySelector.mxml
index 69fdbf3..e71da79 100644 (file)
@@ -1,11 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
 <mx:VBox
        xmlns:mx="http://www.adobe.com/2006/mxml" 
-       xmlns:halcyon="net.systemeD.halcyon.*">
+       xmlns:halcyon="net.systemeD.halcyon.*"
+       backgroundColor="white" borderStyle="inset">
 
   <mx:HBox horizontalGap="0"> 
   <mx:ToggleButtonBar height="100%" dataProvider="{categoryStack}" direction="vertical"/>
   <mx:ViewStack id="categoryStack" width="100%" height="100%"
+      change="_formerIndex=event.newIndex;" 
       creationComplete="setSelectedFeature(_selectedType);">
       <mx:Repeater id="catRep" dataProvider="{MapFeatures.getInstance().getCategoriesForType(limit)}">
           <mx:VBox label="{catRep.currentItem.name}">
 
       import mx.controls.*;
       import mx.containers.*;
+      import mx.events.IndexChangedEvent;
       
       private var settingSelection:Boolean = false;
       private var _selectedType:Feature;
       private var _limit:String;
+      private var _formerIndex:int=0;
       
       [Bindable(event="selectedType")]
       public function get selectedType():Feature {
           if ( categoryStack == null )
               return;
 
+          // set the tab to the selected item's category
+          // (we have to manually fire the IndexChangedEvent because Flex's ViewStack.as isn't competent 
+          //  enough to do it reliably. This is basically a direct crib from dispatchChangeEvent)
+          var index:int=0;
           if ( feature != null ) {
               var primaryCategory:Category = feature.findFirstCategory();
-          
-              // set the tab to the selected item's category
-              var index:int = MapFeatures.getInstance().getCategoriesForType(limit).indexOf(primaryCategory);
-              categoryStack.selectedIndex = index;
+              index = MapFeatures.getInstance().getCategoriesForType(limit).indexOf(primaryCategory);
+              if (index==-1) { index=0; }      // not found, so just show the default for now
           }
+          var event:IndexChangedEvent = new IndexChangedEvent(IndexChangedEvent.CHANGE);
+          event.oldIndex = _formerIndex;
+          event.newIndex = index;
+          event.relatedObject = categoryStack.getChildAt(index);
+          categoryStack.selectedIndex = index;
+          categoryStack.dispatchEvent(event);
+          _formerIndex=index;
           
           // finalise the item selection
           ensureSelection();
       }
+      public function setNoSelectedFeature():void {
+           _selectedType=null;
+         }
       
       /**
        * Sets the selected feature on each category page to the current