stop erroring every time a category is selected for an untagged way
[potlatch2.git] / net / systemeD / potlatch2 / CategorySelector.mxml
index 9a334c9..e71da79 100644 (file)
@@ -1,15 +1,17 @@
 <?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().categories}">
+      <mx:Repeater id="catRep" dataProvider="{MapFeatures.getInstance().getCategoriesForType(limit)}">
           <mx:VBox label="{catRep.currentItem.name}">
-          <mx:TileList dataProvider="{catRep.currentItem.features}"
+          <mx:TileList dataProvider="{catRep.currentItem.getFeaturesForType(limit)}"
                        width="100%" height="100%" change="itemSelected(event);"
                        creationComplete="ensureSelection();">
               <mx:itemRenderer>
@@ -28,7 +30,7 @@
   </mx:ViewStack>
   </mx:HBox>
   
-  <mx:Label id="hoverInfo" text="Hover Info goes here"/>
+  <!-- mx:Label id="hoverInfo" text="Hover Info goes here"/>-->
   
   <mx:Script><![CDATA[
       import net.systemeD.halcyon.connection.*;
 
       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 {
           return _selectedType;
       }
       
+      [Bindable(event="limitChanged")]
+      public function get limit():String {
+          return _limit;
+      }
+      
       private function itemSelected(event:Event):void {
           _selectedType = Feature(TileList(event.currentTarget).selectedItem);
           if ( !settingSelection )
               dispatchEvent(new Event("selectedType"));
       }
       
+      public function setLimitTypes(type:String):void {
+          _limit = type;
+          dispatchEvent(new Event("limitChanged"));
+      }
+      
       /**
        * Set the selected feature displayed in the selector.
        *
           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
-              categoryStack.selectedIndex = primaryCategory.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