Merge branch 'master' into snapshotserver
authorAndy Allan <andy@gravitystorm.co.uk>
Fri, 30 Sep 2011 18:04:47 +0000 (19:04 +0100)
committerAndy Allan <andy@gravitystorm.co.uk>
Fri, 30 Sep 2011 18:04:47 +0000 (19:04 +0100)
Conflicts:
net/systemeD/potlatch2/panels/BackgroundPanel.mxml

1  2 
net/systemeD/halcyon/connection/Connection.as
net/systemeD/potlatch2/TagViewer.mxml
net/systemeD/potlatch2/panels/BackgroundPanel.mxml

index ea6da9c301e3a9580b20e47e82940ee130543699,07a43b7037236d6bfc4d6b8b97e8c30a1cc6862a..5893d8491f3a151fe99c3922ceb3ad6521807df6
@@@ -13,7 -13,6 +13,7 @@@ package net.systemeD.halcyon.connectio
  
                public var name:String;
                public var statusFetcher:StatusFetcher;
 +              public var inlineStatus:Boolean = false;
          protected var apiBaseURL:String;
          protected var policyURL:String;
          protected var params:Object;
@@@ -91,7 -90,7 +91,7 @@@
                public var nodecount:int=0;
                public var waycount:int=0;
                public var relationcount:int=0;
-         private var traces:Array = [];
+         private var traces:Vector.<Trace> = new Vector.<Trace>();
          private var nodePositions:Object = {};
          protected var traces_loaded:Boolean = false;
                private var loadedBboxes:Array = [];
              return changeset;
          }
  
-         public function addTrace(t:Object):void {
+         public function addTrace(t:Trace):void {
              traces.push(t);
          }
  
          protected function clearTraces():void {
-             traces = [];
+             traces = new Vector.<Trace>();
          }
  
                public function findTrace(id:int):Trace {
                        return null;
                }
  
-         public function getTraces():Array {
+         public function getTraces():Vector.<Trace> {
              return traces;
          }
  
  
          // these are functions that the Connection implementation is expected to
          // provide. This class has some generic helpers for the implementation.
 +        /**
 +        * Load data for the bounding box given. Usually called in response to pan / zoom requests
 +        */
                public function loadBbox(left:Number, right:Number,
                                                                top:Number, bottom:Number):void {
            }
index a5d43a06bd1d99a25c799e085625fd78da24db61,b2b62fddee728583b8892c2b697e272a20ee7fee..1e1070de2feb39e088d5afb7008b1d84b5203a6f
@@@ -1,6 -1,7 +1,7 @@@
  <?xml version="1.0" encoding="utf-8"?>
  <mx:VBox
-       xmlns:mx="http://www.adobe.com/2006/mxml"
+     xmlns:fx="http://ns.adobe.com/mxml/2009"
+       xmlns:mx="library://ns.adobe.com/flex/mx"
        xmlns:flexlib="flexlib.containers.*"
        xmlns:controls="net.systemeD.controls.*"
        xmlns:potlatch2="net.systemeD.potlatch2.*"
@@@ -23,9 -24,9 +24,9 @@@
                <mx:TileList dataProvider="{dndRep.currentItem.getFeaturesForType('point', true)}" width="100%" height="1"
                                     rowHeight="32" columnWidth="32" updateComplete="resizePOIGrid(event)" styleName="dndPanelTileList">
                        <mx:itemRenderer>
-                               <mx:Component>
+                               <fx:Component>
                                        <mx:VBox toolTip="{data.name}">
-                                               <mx:Script><![CDATA[
+                                               <fx:Script><![CDATA[
                                                        import mx.events.DragEvent;
                                                        import mx.managers.DragManager;
                                                        import mx.core.DragSource;
                                                                dragProxy.height = dragInitiator.height; // for non-embedded images
                                                                DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
                                                        }
-                                               ]]></mx:Script>
+                                               ]]></fx:Script>
                                                <mx:Image id="foo" source="{data.dndimage}" height="24" width="24" mouseMove="dragPOI(event, data.tags)" toolTip="{data.name}" />
                                        </mx:VBox>
-                               </mx:Component>
+                               </fx:Component>
                        </mx:itemRenderer>
                </mx:TileList>
        </mx:Repeater>
                  <mx:DataGridColumn editable="false" dataField="description" headerText="Relation"/>
                  <mx:DataGridColumn editable="false" dataField="id_idx" headerText="ID"/>
                  <mx:DataGridColumn editable="true" dataField="role" headerText="Role">
-                     <mx:itemEditor><mx:Component><mx:TextInput restrict="&#x0020;-&#x10FFFF;" /></mx:Component></mx:itemEditor>
+                     <mx:itemEditor><fx:Component><mx:TextInput restrict="&#x0020;-&#x10FFFF;" /></fx:Component></mx:itemEditor>
                  </mx:DataGridColumn>
                                <mx:DataGridColumn width="20" editable="false">
                                        <mx:itemRenderer>
-                                               <mx:Component>
+                                               <fx:Component>
                                    <mx:HBox horizontalAlign="center" verticalAlign="middle">
                                                                <mx:PopUpButton arrowButtonWidth="12" paddingLeft="0" paddingRight="0" width="12" height="12" 
                                                                                open="{outerDocument.updateRelationMenu(event);}" 
                                                                                creationComplete="{outerDocument.createRelationMenu(PopUpButton(event.target));}"/>
                                                        </mx:HBox>
-                                               </mx:Component>
+                                               </fx:Component>
                                        </mx:itemRenderer>
                                </mx:DataGridColumn>
              </mx:columns>
              <mx:DataGridColumn editable="false" dataField="type" headerText="Type"/>
              <mx:DataGridColumn editable="false" dataField="id" headerText="ID"/>
              <mx:DataGridColumn editable="true" dataField="role" headerText="Role">
-                               <mx:itemEditor><mx:Component><mx:TextInput restrict="&#x0020;-&#x10FFFF;" /></mx:Component></mx:itemEditor>
+                               <mx:itemEditor><fx:Component><mx:TextInput restrict="&#x0020;-&#x10FFFF;" /></fx:Component></mx:itemEditor>
                        </mx:DataGridColumn>
            </mx:columns>
          </mx:DataGrid>
                        disabledIcon="@Embed('../../../embedded/view_accordion_disabled.png')"
                        click="setEditorStackUI(false)" id="accordionLabel" paddingTop="6"
                        toolTip="Show in sliding windows"
-                       enabled="{editorStack is SuperTabNavigator &amp;&amp; stack.selectedIndex==0}" />
+                       enabled="{editorStack is TabNavigator &amp;&amp; stack.selectedIndex==0}" />
          </mx:HBox>
    </mx:VBox>
  
              <mx:DataGridColumn editable="false" dataField="description" headerText="Relation"/>
              <mx:DataGridColumn editable="false" dataField="id_idx" headerText="ID"/>
              <mx:DataGridColumn editable="true" dataField="role" headerText="Role">
-                 <mx:itemEditor><mx:Component><mx:TextInput restrict="&#x0020;-&#x10FFFF;" /></mx:Component></mx:itemEditor>
+                 <mx:itemEditor><fx:Component><mx:TextInput restrict="&#x0020;-&#x10FFFF;" /></fx:Component></mx:itemEditor>
              </mx:DataGridColumn>
                        <mx:DataGridColumn width="20" editable="false">
                                <mx:itemRenderer>
-                                       <mx:Component>
+                                       <fx:Component>
                            <mx:HBox horizontalAlign="center" verticalAlign="middle">
                                                        <mx:PopUpButton arrowButtonWidth="12" paddingLeft="0" paddingRight="0" width="12" height="12" 
                                                                        open="{outerDocument.updateRelationMenu(event);}" 
                                                                        creationComplete="{outerDocument.createRelationMenu(PopUpButton(event.target));}"/>
                                                </mx:HBox>
-                                       </mx:Component>
+                                       </fx:Component>
                                </mx:itemRenderer>
                        </mx:DataGridColumn>
          </mx:columns>
      <sidepanel:BackgroundPanel id="backgroundPanelContents" width="100%"/>
    </mx:VBox>
  
 +  <!-- merge tags from background layer -->
 +
 +  <mx:VBox id="backgroundMergePanel" width="100%" height="100%" horizontalScrollPolicy="off" styleName="dndPanelVbox">
 +    <sidepanel:BackgroundMergePanel id="backgroundMergePanelContents" width="100%" />
 +  </mx:VBox>
 +
  </mx:ViewStack>
  
-   <mx:Script><![CDATA[
+   <fx:Script><![CDATA[
        import net.systemeD.halcyon.connection.*;
        import net.systemeD.halcyon.MapPaint;
 +      import net.systemeD.potlatch2.EditController;
        import net.systemeD.potlatch2.mapfeatures.*;
        import net.systemeD.potlatch2.utils.*;
+       import net.systemeD.controls.CollapsiblePanel;
  
        import mx.collections.*;
        import mx.containers.*;
        import mx.managers.DragManager;
        import mx.core.DragSource;
        import mx.controls.TabBar;
-       import flexlib.containers.SuperTabNavigator;
+ //    import flexlib.containers.SuperTabNavigator;
+       [Bindable] [Embed(source="../../../embedded/tab_basic.png"       )] private var tabIconBasic:Class;
+       [Bindable] [Embed(source="../../../embedded/tab_address.png"     )] private var tabIconAddress:Class;
+       [Bindable] [Embed(source="../../../embedded/tab_cycle.png"       )] private var tabIconCycle:Class;
+       [Bindable] [Embed(source="../../../embedded/tab_details.png"     )] private var tabIconDetails:Class;
+       [Bindable] [Embed(source="../../../embedded/tab_restrictions.png")] private var tabIconRestrictions:Class;
+       [Bindable] [Embed(source="../../../embedded/tab_transport.png"   )] private var tabIconTransport:Class;
+       [Bindable] [Embed(source="../../../embedded/tab_walk.png"        )] private var tabIconWalk:Class;
+       private var tabIcons:Object= { Basic:tabIconBasic, Details:tabIconDetails, Address:tabIconAddress, Walk:tabIconWalk, Cycle:tabIconCycle, 
+                                        Transport:tabIconTransport, Restrictions:tabIconRestrictions};
  
        [Bindable]
        public var dndPrompt:String="Add new points by dragging them onto the map";
  
-       private var editorStackTabNavigator:SuperTabNavigator;
+       private var editorStackTabNavigator:TabNavigator;
        private var editorStackAccordion:Accordion;
        [Bindable] private var editorStack:Container;
  
        public var mapFeatures:MapFeatures;
 +      public var controller:EditController;
        private var selectedEntity:Entity;
        private var connection:Connection;
        private var currentCategorySelector:CategorySelector;
                sidebar.selectedChild = tagsPanel;
              }
  
 +        } else if (entities.length==2
 +                      && xor(entities[0].connection is SnapshotConnection, entities[1].connection is SnapshotConnection)
 +                      && xor(!controller.map.getLayerForEntity(entities[0]).isBackground, !controller.map.getLayerForEntity(entities[1]).isBackground) ) {
 +            backgroundMergePanelContents.init(entities);
 +            sidebar.selectedChild = backgroundMergePanel;
 +
                } else if(isMultipleEditable(entities)) {
                        selectedEntity = new EntityCollection(entities);
                        selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged);
                UIComponent.resumeBackgroundProcessing();
        }
  
 +      private function xor(a:Boolean, b:Boolean):Boolean {
 +          return ( a || b) && !(a && b);
 +      }
 +
        private function refreshFeatureIcon():void {
            var oldFeature:Feature = feature;
            feature = selectedEntity == null ? null : mapFeatures.findMatchingFeature(selectedEntity);
        }
  
        private var tabComponents:Object = {};
+       private var subpanelComponents:Object = {};
  
        private function initialiseEditors():void {
-           // reset tab to 0 to work around TabNavigator bug (#3444)
-           if (editorStack is TabNavigator) {
-               try {
-                   var tabBar:TabBar=TabBar(TabNavigator(editorStack).getTabAt(0).parent);
-                   tabBar.selectedIndex=0;
-                   tabBar.validateNow();
-               } catch(errObject:Error) {}
-           }
+               editorStack.removeAllChildren();
+               if ( selectedEntity == null || feature == null )
+                       return;
+               var basicEditorBox:VBox = createEditorBox();
+               basicEditorBox.label = "Basic";
+               basicEditorBox.icon=tabIconBasic;
+               editorStack.addChild(basicEditorBox);
+               var tabs:Object = {};
+               var tabList:Array = [];
+               tabComponents = {};
+               var subpanels:Object = {};
+               subpanelComponents = {};
+               // First create the tabs
+               for each (var factory:EditorFactory in feature.editors) {
+                       var category:String = factory.category;
+                       if (category!='') {
+                               var tab:VBox = tabs[category];
+                               if ( tab == null) {
+                                       tab = createEditorBox();
+                                       tab.label = category;
+                                       if (tabIcons[category]) tab.icon=tabIcons[category];
+                                       tabs[category] = tab;
+                                       tabList.push(tab);      
+                               }
+                       }
+               }
  
-           editorStack.removeAllChildren();
-           if ( selectedEntity == null || feature == null )
-               return;
+               // Put the tabs on-screen in order
+               tabList.sort(sortCategories,16);
+               for each (tab in tabList) {
+                       editorStack.addChild(tab);
+                       tabComponents[tab] = [];
+               }
  
-           var editorBox:VBox = createEditorBox();
-           editorBox.label = "Basic";
-           editorStack.addChild(editorBox);
+               // Then add the individual editors to them
+               for each (factory in feature.editors) {
  
-           var tabs:Object = {};
-           tabComponents = {};
+                       // Add to basic editor box first
+                       if ( factory.presence.isEditorPresent(factory, selectedEntity, null) ) {
+                               var editor:DisplayObject = factory.createEditorInstance(selectedEntity);
+                               if (editor) basicEditorBox.addChild(editor);
+                       }
  
-           for each (var factory:EditorFactory in feature.editors) {
-               if ( factory.presence.isEditorPresent(factory, selectedEntity, null) ) {
-                   var editor:DisplayObject = factory.createEditorInstance(selectedEntity);
-                   if ( editor != null )
-                       editorBox.addChild(editor);
-               }
-               var category:String = factory.category;
-               if (category!='') {
-                     var tab:VBox = tabs[category];
-                     if ( tab == null) {
-                         tab = createEditorBox();
-                         tab.label = category;
-                         editorStack.addChild(tab);
-                         tabs[category] = tab;
-                         tabComponents[tab] = [];
-                     }
-                     var catEditor:DisplayObject = factory.createEditorInstance(selectedEntity);
-                     if ( catEditor != null )
-                         tabComponents[tab].push(catEditor);
-                     //    tab.addChild(catEditor);
-               }
-           }
+                       // Then prepare to add to category panel
+                       category=factory.category;
+                       if (factory.category=='') continue;
+                       var catEditor:DisplayObject = factory.createEditorInstance(selectedEntity);
+                       if (!catEditor) continue;
+                       tab=tabs[category];
+                       
+                       // Create subcategory panel if needed
+                       if (factory.subcategory) {
+                               var subcategory:String = factory.subcategory;
+                               if (!subpanels[category]) { subpanels[category]={}; }
+                               var subpanel:CollapsiblePanel = subpanels[category][subcategory];
+                               if (!subpanel) {
+                                       subpanel=new CollapsiblePanel(false);
+                                       subpanel.percentWidth=100;
+                                       subpanel.styleName="subcategoryPanel";
+                                       subpanel.title=subcategory;
+                                       subpanels[category][subcategory]=subpanel;
+                                       tabComponents[tab].push(subpanel);
+                               }
+                               subpanel.addChild(catEditor);
+                       } else {
+                               tabComponents[tab].push(catEditor);
+                       }
+               }
        }
  
+       // ** FIXME: Order probably shouldn't be hard-coded, but configurable
+       private static var categoryOrder:Array=["Restrictions","Transport","Cycle","Walk","Address","Details"]; // reverse order
+       private function sortCategories(a:VBox,b:VBox):int {
+               var a1:int=categoryOrder.indexOf(a.label);
+               var a2:int=categoryOrder.indexOf(b.label);
+               if (a1<a2) { return 1; }
+               else if (a1>a2) { return -1; }
+               return 0;
+       }
+       
        private function createEditorBox():VBox {
            var box:VBox = new VBox();
            box.percentWidth = 100;
        }
  
        private function initEditorStackUIs():void {
-               editorStackTabNavigator = new SuperTabNavigator();
              editorStackTabNavigator.allowTabSqueezing=false;
              editorStackTabNavigator.minTabWidth=10;
              editorStackTabNavigator.closePolicy="close_never";
              editorStackTabNavigator.scrollSpeed=20;
+               editorStackTabNavigator = new TabNavigator();
//            editorStackTabNavigator.allowTabSqueezing=false;
//            editorStackTabNavigator.minTabWidth=10;
//            editorStackTabNavigator.closePolicy="close_never";
//            editorStackTabNavigator.scrollSpeed=20;
                editorStackTabNavigator.creationPolicy="auto";
                editorStackTabNavigator.percentWidth=100;
                editorStackTabNavigator.percentHeight=100;
                editorStackTabNavigator.styleName="dndStackTab";
              editorStackTabNavigator.popUpButtonPolicy="off"
//            editorStackTabNavigator.popUpButtonPolicy="off"
  
  
                editorStackAccordion = new Accordion();
                editorStackAccordion.percentHeight=100;
                editorStackAccordion.creationPolicy="auto";
                editorStackAccordion.styleName="dndStackAccordion";
+               /* FIXME: the accordion icons should be right-aligned. See:
+               http://www.kristoferjoseph.com/blog/2008/11/06/positioning-the-flex-accordion-header-icon
+               http://blog.flexexamples.com/2007/09/13/changing-text-alignment-in-an-flex-accordion-header/
+               */
  
                setEditorStackUI(true);
        }
        }
  
        private function editorStackUIUpdate(event:Event):void {
-               if (editorStack is SuperTabNavigator) {
-                       var e:SuperTabNavigator = editorStack as SuperTabNavigator;
+               if (editorStack is TabNavigator) {
+                       var e:TabNavigator = editorStack as TabNavigator;
                        if (e.selectedIndex<0) { return; }
                        for (var i:uint=0; i<e.numChildren; i++) {
                                e.getTabAt(i).selected=(i==e.selectedIndex);
  
        private function editRelation(id:Number):void {
            var panel:RelationEditorPanel = RelationEditorPanel(
-               PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
+               PopUpManager.createPopUp(Application(FlexGlobals.topLevelApplication), RelationEditorPanel, true));
            panel.setRelation(connection.getRelation(id));
            PopUpManager.centerPopUp(panel);
        }
        public function selectRelationMenu(event:MenuEvent):void {
                var rel:Relation=rowData.relation;
                var entities:Array;
-               var controller:EditController=Application.application.theController;
+               var controller:EditController=FlexGlobals.topLevelApplication.theController;
                switch (event.index) {
                        case 0: // Select all members
                                entities=selectedEntity.entities.concat(rel.memberEntities);
                if (rows!=Math.floor(rows)) { rows=Math.floor(rows+1); }
                event.target.height=rows*(event.target.rowHeight+1);
        }
-   ]]></mx:Script>
+   ]]></fx:Script>
  </mx:VBox>
  
index aaa44df0eb78916d52e6d16a4a753f2a57ae318d,9030a8bd6378695cd170fe47128e57a169fbfa12..2895e75560c87703e5165b7d8d8c1e110a1d2492
@@@ -4,7 -4,10 +4,10 @@@
      Background Panel
  -->
  
- <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" height="100%">
+ <mx:VBox
+     xmlns:fx="http://ns.adobe.com/mxml/2009"
+     xmlns:mx="library://ns.adobe.com/flex/mx"
+     height="100%">
    <mx:Text id="backgroundPanelText" text="You have selected a Background Feature." width="100%" styleName="helpInfo" />
    <mx:DataGrid editable="false" id="backgroundPanelDG" width="100%" height="50%">
      <mx:columns>
        <mx:DataGridColumn editable="false" dataField="value" headerText="value" />
      </mx:columns>
    </mx:DataGrid>
 -  <mx:Text text="All the data copied to the main layer? Click 'complete'!" />
 -  <mx:Button label="Complete" click="markComplete()"/>
 +  <mx:ViewStack id="statusStack" resizeToContent="true" width="100%">
 +    <mx:VBox id="empty" />
 +    <mx:VBox id="not_complete">
 +      <mx:Text text="All the data copied to the main layer? Click 'complete'!" />
 +      <mx:Button label="Complete" click="markComplete()"/>
 +    </mx:VBox>
 +    <mx:VBox id="complete">
 +      <mx:Text text="This feature has been marked as complete. If this is wrong, press the button below." />
 +      <mx:Button label="Not complete" click="markNotComplete()"/>
 +    </mx:VBox>
 +  </mx:ViewStack>
-   <mx:Script><![CDATA[
+   <fx:Script><![CDATA[
  
        import net.systemeD.halcyon.connection.*;
        import net.systemeD.halcyon.MapPaint;
        private var layer:MapPaint;
  
        public function init(entity:Entity, layer:MapPaint):void {
 -            this.layer = layer;
 -            if ( tagDataProvider == null ) {
 -                tagDataProvider = new ArrayCollection();
 -                backgroundPanelDG.dataProvider = tagDataProvider;
 -            }
 -
 -            selectedEntity=entity;
 -            updateTagDataProvider();
 +          this.layer = layer;
 +          if ( tagDataProvider == null ) {
 +              tagDataProvider = new ArrayCollection();
 +              backgroundPanelDG.dataProvider = tagDataProvider;
 +          }
 +
 +          selectedEntity=entity;
 +          selectedEntity.addEventListener(Connection.STATUS_CHANGED, statusEvent, false, 0, true);
 +          setStatusStack();
 +          updateTagDataProvider();
        }
  
        private function updateTagDataProvider():void {
 -            tagDataProvider.removeAll();
 -            if (selectedEntity==null) { return; }
 -            var tags:Array = selectedEntity.getTagArray();
 -            tags.sortOn("key");
 -            for each(var tag:Tag in tags) { tagDataProvider.addItem(tag); }
 +          tagDataProvider.removeAll();
 +          if (selectedEntity==null) { return; }
 +          var tags:Array = selectedEntity.getTagArray();
 +          tags.sortOn("key");
 +          for each(var tag:Tag in tags) { tagDataProvider.addItem(tag); }
 +      }
 +
 +      private function statusEvent(e:Event):void {
 +            setStatusStack();
 +      }
 +
 +      private function setStatusStack():void {
 +          switch (selectedEntity.status) {
 +              case 'incomplete':
 +                  statusStack.selectedChild = not_complete;
 +                  break;
 +              case 'complete':
 +                  statusStack.selectedChild = complete;
 +                  break;
 +              default:
 +                  statusStack.selectedChild = empty;
 +          }
        }
  
        private function markComplete():void {
 -            if (selectedEntity.connection is SnapshotConnection) {
 -                SnapshotConnection(selectedEntity.connection).markComplete(selectedEntity);
 -            }
 +          if (selectedEntity.connection is SnapshotConnection) {
 +              SnapshotConnection(selectedEntity.connection).markComplete(selectedEntity);
 +          }
 +      }
 +
 +      private function markNotComplete():void {
 +          if (selectedEntity.connection is SnapshotConnection) {
 +              SnapshotConnection(selectedEntity.connection).markNotComplete(selectedEntity);
 +          }
        }
        ]]>
-   </mx:Script>
+   </fx:Script>
  </mx:VBox>