Merge branch 'master' into history
[potlatch2.git] / net / systemeD / potlatch2 / TagViewer.mxml
index 3517a78..dd1fefb 100644 (file)
@@ -1,6 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
+<!---
+  The TagViewer is the container for the entire sidebar. It has a number of components, and subpanels, in a ViewStack that change
+  depending on what is selected, i.e. the ControllerState.
+
+  @see net.systemeD.potlatch2.controller.ControllerState
+    -->
 <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.*"
     initialize="loadFeatures()">
 
 <mx:ViewStack id="sidebar" width="100%" height="100%" creationPolicy="all">
+
+  <!-- Drag & drop icon panel -->
+
   <mx:VBox id="dndPanel" width="100%" height="100%" horizontalScrollPolicy="off" styleName="dndPanelVbox">
     <mx:Text id="dndPanelText" text="{dndPrompt}" width="100%" styleName="helpInfo" />
-       <mx:Repeater id="dndRep" dataProvider="{MapFeatures.getInstance().getCategoriesForType('point')}">
-               <mx:HBox width="100%"><mx:Label text="{dndRep.currentItem.name}:" styleName="dndPanelCategoryLabel"/></mx:HBox>
+       <mx:Repeater id="dndRep" dataProvider="{MapFeatures.getInstance().getCategoriesForType('point')}" styleName="dndRepeater">
+               <mx:HBox width="100%" styleName="dndPanelCategory">
+                       <mx:Label text="{dndRep.currentItem.name}:" styleName="dndPanelCategoryLabel"/>
+               </mx:HBox>
 
-               <mx:TileList dataProvider="{dndRep.currentItem.getFeaturesForType('point')}" width="100%" height="1"
+               <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;
 
                                                        private function dragPOI(event:MouseEvent, tags:Array):void {
+                                                               if (outerDocument.controller.map.dragstate==outerDocument.controller.map.DRAGGING) return;
+
                                                                // Get the drag initiator component from the event object.
                                                                var dragInitiator:Image = event.currentTarget as Image;
                                                                var dragSource:DragSource = new DragSource();
                                                                dragProxy.height = dragInitiator.height; // for non-embedded images
                                                                DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
                                                        }
-                                               ]]></mx:Script>
-                                               <mx:Image id="foo" source="{data.image}" height="24" width="24" mouseMove="dragPOI(event, data.tags)" toolTip="{data.name}" />
+                                               ]]></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:VBox>
-  
-  <mx:VBox id="tagsPanel" width="100%" height="100%" creationPolicy="auto">
-    <mx:ViewStack id="stack" width="100%" height="100%">
+
+  <!-- Standard tagging panel -->
+
+  <mx:VBox id="tagsPanel" width="100%" height="100%" creationPolicy="auto" tabChildren="true">
+    <mx:ViewStack id="stack" width="100%" height="100%" change="tagsPanel.tabChildren=(event.newIndex==0)">
       <mx:VBox width="100%" height="100%" label="Simple" id="editorContainer" creationComplete="initEditorStackUIs()" styleName="dndPanelVbox">
         <mx:VBox width="100%" verticalGap="1" styleName="dndTagHeader">
           <mx:HBox width="100%" id="iconContainer" styleName="featureSelector">
             <mx:Image id="iconImage"/>
             <mx:Text condenseWhite="true" width="100%" id="iconText" styleName="dndIconText"/>
-            <mx:LinkButton label="?" click="openDescription()" id="helpLabel" styleName="helpInfo"/>
           </mx:HBox>
-          <mx:PopUpButton id="popupChange" creationComplete="initFeatureBox()" openAlways="true" width="100%" styleName="dndTagPopUpMenu"/>
+          <mx:HBox width="100%">
+            <mx:PopUpButton id="popupChange" openAlways="true" width="100%" styleName="dndTagPopUpMenu" closeDuration="0" />
+            <mx:LinkButton icon="@Embed('../../../embedded/information.svg')" click="openDescription()" id="helpLabel" styleName="helpInfo"/>
+          </mx:HBox>
         </mx:VBox>
       </mx:VBox>
       <mx:VBox width="100%" height="100%" label="Advanced" id="advancedContainer" initialize="checkAdvanced()" verticalGap="1">
-        <mx:Label id="advancedID" click="openEntityPage()">
+        <mx:Label id="advancedID" click="new HistoryDialog().init(selectedEntity);">
           <mx:htmlText><![CDATA[<i>No Selection</i>]]></mx:htmlText>
         </mx:Label>
 
                <potlatch2:TagGrid id="advancedTagGrid" width="100%" height="75%" />
 
         <mx:HBox horizontalAlign="right" width="100%">
-          <mx:LinkButton label="Delete" click="advancedTagGrid.removeTag()" enabled="{advancedTagGrid.selectedItem != null? true : false}"/>
+          <mx:LinkButton label="Delete" click="advancedTagGrid.removeTag()" id="advancedDeleteButton" enabled="{advancedTagGrid.selectedItem != null? true : false}"/>
           <mx:LinkButton label="Add" click="advancedTagGrid.addNewTag()" id="advancedAddButton"/>
         </mx:HBox>
-        
+
         <mx:DataGrid editable="true" width="100%" height="25%" id="relationsGrid"
             doubleClickEnabled="true"
             itemDoubleClick="editRelation(relationsGrid.selectedItem.id)"
             <mx:columns>
                 <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:DataGridColumn editable="true" dataField="role" headerText="Role">
+                    <mx:itemEditor><fx:Component><mx:TextInput restrict="&#x0020;-&#x10FFFF;" /></fx:Component></mx:itemEditor>
+                </mx:DataGridColumn>
+                               <mx:DataGridColumn width="20" editable="false">
+                                       <mx:itemRenderer>
+                                               <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>
+                                               </fx:Component>
+                                       </mx:itemRenderer>
+                               </mx:DataGridColumn>
             </mx:columns>
         </mx:DataGrid>
 
         <mx:HBox horizontalAlign="right" width="100%">
-          <mx:LinkButton label="Remove from" click="removeFromRelation(relationsGrid.selectedItem.id, relationsGrid.selectedItem.index)" 
+          <mx:LinkButton label="Remove from" click="removeFromRelation(relationsGrid.selectedItem.id, relationsGrid.selectedItem.index)"
                           enabled="{relationsGrid.selectedItem != null? true : false}"/>
           <mx:LinkButton label="Add to" click="addToRelation()"/>
         </mx:HBox>
           <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:DataGridColumn editable="true" dataField="role" headerText="Role">
+                               <mx:itemEditor><fx:Component><mx:TextInput restrict="&#x0020;-&#x10FFFF;" /></fx:Component></mx:itemEditor>
+                       </mx:DataGridColumn>
           </mx:columns>
         </mx:DataGrid>
       </mx:VBox>
-      
+
       </mx:ViewStack>
 
          <mx:HBox width="100%">
                <mx:LinkBar dataProvider="{stack}"/>
                <mx:Spacer width="100%"/>
-               <mx:LinkButton 
+               <mx:LinkButton
                        icon="@Embed('../../../embedded/view_tabbed.png')"
                        disabledIcon="@Embed('../../../embedded/view_tabbed_disabled.png')"
-                       click="setEditorStackUI(true)" id="tabNavigatorLabel" paddingTop="6" 
+                       click="setEditorStackUI(true)" id="tabNavigatorLabel" paddingTop="6"
                        toolTip="Show in tabs"
                        enabled="{editorStack is Accordion &amp;&amp; stack.selectedIndex==0}" />
                <mx:LinkButton
-                       icon="@Embed('../../../embedded/view_accordion.png')" 
+                       icon="@Embed('../../../embedded/view_accordion.png')"
                        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>
 
+  <!-- Multiple selection -->
+
   <mx:VBox id="multiplePanel" width="100%" height="100%" horizontalScrollPolicy="off" styleName="dndPanelVbox">
-    <mx:Text id="multiplePanelText" text="You have selected multiple items." width="100%" styleName="helpInfo" />
+    <potlatch2:TagGrid id="multiAdvancedTagGrid" width="100%" height="75%" />
+       <mx:HBox horizontalAlign="right" width="100%">
+         <mx:LinkButton label="Delete" click="multiAdvancedTagGrid.removeTag()" enabled="{multiAdvancedTagGrid.selectedItem != null? true : false}"/>
+         <mx:LinkButton label="Add" click="multiAdvancedTagGrid.addNewTag()" />
+       </mx:HBox>
+
+    <mx:DataGrid editable="true" width="100%" height="25%" id="multiRelationsGrid"
+        doubleClickEnabled="true"
+        itemDoubleClick="editRelation(multiRelationsGrid.selectedItem.id)"
+        doubleClick="if (event.target.parent==multiRelationsGrid) { addToRelation(); }">
+        <mx:columns>
+            <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><fx:Component><mx:TextInput restrict="&#x0020;-&#x10FFFF;" /></fx:Component></mx:itemEditor>
+            </mx:DataGridColumn>
+                       <mx:DataGridColumn width="20" editable="false">
+                               <mx:itemRenderer>
+                                       <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>
+                                       </fx:Component>
+                               </mx:itemRenderer>
+                       </mx:DataGridColumn>
+        </mx:columns>
+    </mx:DataGrid>
+    <mx:HBox horizontalAlign="right" width="100%">
+      <mx:LinkButton label="Remove from" click="removeFromRelation(multiRelationsGrid.selectedItem.id)"
+                      enabled="{multiRelationsGrid.selectedItem != null? true : false}"/>
+      <mx:LinkButton label="Add to" click="addToRelation()"/>
+    </mx:HBox>
+
   </mx:VBox>
 
+  <!-- Multiple selection but items cannot be edited -->
+
+  <mx:VBox id="multipleInvalidPanel" width="100%" height="100%" horizontalScrollPolicy="off" styleName="dndPanelVbox">
+       <mx:Text id="multipleInvalidPanelText" text="You have selected multiple items." width="100%" styleName="helpInfo" />
+  </mx:VBox>
+
+  <!-- Generic marker panel -->
+
   <mx:VBox id="markerPanel" width="100%" height="100%" horizontalScrollPolicy="off" styleName="dndPanelVbox">
     <sidepanel:MarkerPanel id="markerPanelContents" width="100%"/>
   </mx:VBox>
 
+  <!-- Bug editing panel -->
+
   <mx:VBox id="bugPanel" width="100%" height="100%" horizontalScrollPolicy="off" styleName="dndPanelVbox">
     <sidepanel:BugPanel id="bugPanelContents" width="100%"/>
   </mx:VBox>
 
+  <!-- Background layer selection -->
+
+  <mx:VBox id="backgroundPanel" width="100%" height="100%" horizontalScrollPolicy="off" styleName="dndPanelVbox">
+    <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.VectorLayer;
+      import net.systemeD.halcyon.MapPaint;
+      import net.systemeD.potlatch2.EditController;
       import net.systemeD.potlatch2.mapfeatures.*;
+      import net.systemeD.potlatch2.history.HistoryDialog;
+      import net.systemeD.potlatch2.mapfeatures.editors.*;
+      import net.systemeD.potlatch2.utils.*;
+      import net.systemeD.controls.CollapsiblePanel;
 
       import mx.collections.*;
-      import mx.containers.*;
+      import mx.containers.VBox;
+      import mx.containers.HBox;
+      import mx.containers.TabNavigator;
+      import mx.containers.Accordion;
       import mx.events.*;
       import mx.core.*;
       import mx.managers.PopUpManager;
+      import mx.controls.Menu;
+      import mx.controls.Alert;
       import flash.geom.Point;
       import flash.net.*;
       import mx.events.DragEvent;
       import mx.managers.DragManager;
       import mx.core.DragSource;
-      import flexlib.containers.SuperTabNavigator;
-
-      private static const dndPrompt:String="Add new points by dragging them onto the map";
-
-      private var editorStackTabNavigator:SuperTabNavigator;
+      import mx.controls.TabBar;
+      import spark.components.Form;
+      import spark.layouts.FormLayout;
+//    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:TabNavigator;
       private var editorStackAccordion:Accordion;
       [Bindable] private var editorStack:Container;
 
       public var mapFeatures:MapFeatures;
+      public var controller:EditController;
       private var selectedEntity:Entity;
-      private var tw:CategorySelector = null;
+      private var connection:Connection;
+      private var currentCategorySelector:CategorySelector;
+      private var categorySelectors:Object = {};       // hash of categorySelectors for each limitType
       private var feature:Feature = null;
 
-         public function setEntity(entities:Array, layer:VectorLayer=null):void {
+      private var rowData:Object;              // relation membership reference, needed so it's accessible from relation actions menu
+
+         public function setEntity(entities:Array, layer:MapPaint=null):void {
                UIComponent.suspendBackgroundProcessing();
-               
+               connection=null;
+
                var firstSelected:Entity=null;
                if (entities.length==1) { firstSelected=entities[0]; }
-               
+
                if (selectedEntity!=firstSelected && selectedEntity!=null) {
                        selectedEntity.removeEventListener(Connection.TAG_CHANGED, tagChanged);
+                       selectedEntity.removeEventListener(Connection.ADDED_TO_RELATION, addedToRelation);
+                       selectedEntity.removeEventListener(Connection.REMOVED_FROM_RELATION, removedFromRelation);
+                       if (selectedEntity is EntityCollection) EntityCollection(selectedEntity).releaseListeners();
                }
-               
+
                if (entities.length==0) {
                        // Nothing selected, so show drag-and-drop panel
                        sidebar.selectedChild = dndPanel;
-               
+
                } else if (entities.length==1) {
                        // Single entity selected, so show tag panel
                        selectedEntity=firstSelected;
+                       connection=firstSelected.connection;
                        if (selectedEntity!=null) { selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged); }
                        if (advancedID!=null) { setupAdvanced(firstSelected); }
                        if (firstSelected is Relation) { stack.addChild(membersVBox); }
-            if (selectedEntity is Marker && layer is BugLayer) {
-              bugPanelContents.init(selectedEntity, layer);
+            if (selectedEntity is Marker && connection is BugConnection) {
+              bugPanelContents.init(selectedEntity, BugConnection(connection));
               sidebar.selectedChild = bugPanel;
             } else if (selectedEntity is Marker) {
               markerPanelContents.init(selectedEntity, layer);
               sidebar.selectedChild = markerPanel;
+            } else if (connection is SnapshotConnection) {
+              backgroundPanelContents.init(selectedEntity);
+              sidebar.selectedChild = backgroundPanel;
             } else {
               refreshFeatureIcon();
               initialiseEditors();
               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);
+            sidebar.selectedChild = multiplePanel;
+                       setupMultiAdvanced(selectedEntity);
+                       connection=entities[0].connection;
+                       
                } else {
-                       // Multiple selection, so for now show a largely blank panel/
-                       // ** TODO - proper multiple selection tagging
-                       sidebar.selectedChild = multiplePanel;
+                       //The selection contains elements which can't be edited all together.
+                       sidebar.selectedChild = multipleInvalidPanel;
                }
                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);
               if ( feature != null )
                   feature.addEventListener("imageChanged", featureImageChanged);
           }
-
-          if ( feature != null && feature.name != null ) {
-              setFeatureIcon(selectedEntity, feature);
-          } else {
-              blankFeatureIcon(selectedEntity);
-          }
+          setCategorySelector(selectedEntity, feature);
       }
 
       private function featureImageChanged(event:Event):void {
-          setFeatureIcon(selectedEntity, feature);
+          setCategorySelector(selectedEntity, feature);
       }
-      
-      private function setFeatureIcon(entity:Entity, feature:Feature):void {
-          //blankFeatureIcon(entity);
-          
-          iconImage.source = feature.image;
-
-          var txt:String = feature.htmlDetails(entity);
-          iconText.htmlText = txt;
-          popupChange.label = feature.name;
-          setLimitTypes(entity);
-          tw.setSelectedFeature(feature);
-          helpLabel.visible = feature.hasHelpURL();
-      }
-      
-      private function setLimitTypes(entity:Entity):void {
-          var type:String = null;
-          if ( entity is Node )
-              type = "point";
-          else if ( entity is Way )
-              type = Way(entity).isArea() ? "area" : "line";
-          else if ( entity is Relation )
-              type = "relation";
-          tw.setLimitTypes(type);
+
+      /** Set the icon, categorySelector and help text for the current entity. */
+      private function setCategorySelector(entity:Entity, feature:Feature):void {
+                       // Remove the "user has selected something" event listener from previous categorySelector,
+                       // and make it invisible because Flex is crap at updating click areas otherwise
+                       if (currentCategorySelector) { 
+                               currentCategorySelector.removeEventListener("selectedType", changeFeatureType);
+                               currentCategorySelector.visible=false;
+                       }
+                       
+                       // Have we cached the categorySelector for this limitType? If not, create one
+                       var lt:String=limitType(entity);
+                       if (!categorySelectors[lt]) {
+                               categorySelectors[lt]=new CategorySelector();
+                               categorySelectors[lt].setLimitTypes(lt);
+                       }
+                       currentCategorySelector=categorySelectors[lt];
+                       currentCategorySelector.addEventListener("selectedType", changeFeatureType, false, 0, true);
+
+                       // Update surrounding icon/text display
+                       if (feature) {
+                               iconImage.source = feature.image;
+                               iconText.htmlText = feature.htmlDetails(entity);
+                               popupChange.label = feature.name;
+                               helpLabel.visible = feature.hasHelpURL();
+                               currentCategorySelector.setSelectedFeature(feature);
+                       } else {
+                               iconImage.source = null;
+                               popupChange.label = "unknown";
+                               helpLabel.visible = false;
+                               if (entity==null) {
+                                       iconText.htmlText = "<i>Nothing selected</i>";
+                               } else if (entity.hasTags()) {
+                                       iconText.htmlText = "<b>Not recognised</b><br/><font size='10pt'>Try looking at the tags under the advanced properties</font>";
+                               } else {
+                                       iconText.htmlText = "<b>No tags set</b><br/><font size='10pt'>Please use the menu below to define what this "+entity.getType()+" is</font>";
+                               }
+                               currentCategorySelector.setSelectedFeature(null);
+                       }
+
+                       // Set it as the popup, and make sure it's visible
+                       popupChange.popUp=currentCategorySelector;
+                       currentCategorySelector.visible=true;
       }
 
-      private function blankFeatureIcon(entity:Entity):void {
-          iconImage.source = null;
-          popupChange.label = "unknown";
-          setLimitTypes(entity);
-                 if (entity == null) { 
-                       iconText.htmlText = "<i>Nothing selected</i>";
-            tw.setNoSelectedFeature();
-                 } else if (entity.hasTags()) {
-                       iconText.htmlText = "<b>Not recognised</b><br/>Try looking at the tags under the advanced properties";
-            tw.setSelectedFeature(null);
-                 } else {
-                       iconText.htmlText = "<b>No tags set</b><br/>Please use the menu below to define what this "+entity.getType()+" is";
-            tw.setSelectedFeature(null);
-          }
-          helpLabel.visible = false;
+         private function isMultipleEditable(entities:Array):Boolean {
+               for each(var entity:Entity in entities) {
+                       if(!(entity is Node || entity is Way))
+                               return false;
+               }
+               return true;
+         }
+
+      private function limitType(entity:Entity):String {
+          if      (entity is Node    ) return "point";
+          else if (entity is Way     ) return Way(entity).isArea() ? "area" : "line";
+          else if (entity is Relation) return "relation";
+          return null;
       }
 
       private var tabComponents:Object = {};
-      
+      private var subpanelComponents:Object = {};
+
       private function initialiseEditors():void {
-          editorStack.removeAllChildren();
-          if ( selectedEntity == null || feature == null )
-              return;
-          
-          var editorBox:VBox = createEditorBox();
-          editorBox.label = "Basic";
-          editorStack.addChild(editorBox);
-          
-          var tabs:Object = {};
-          tabComponents = {};
-          
-          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);
-              }
-          }
-      }
-      
-      private function createEditorBox():VBox {
-          var box:VBox = new VBox();
-          box.percentWidth = 100;
-          box.percentHeight = 100;
-          box.styleName = "dndEditorContainer";
-          return box;
-      }
+               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);      
+                               }
+                       }
+               }
 
-      private function ensureEditorsPopulated(tab:VBox):void {
-          var components:Array = tabComponents[tab];
-          if ( components == null || tab == null || tab.numChildren >= components.length )
-              return;
-          for each (var component:DisplayObject in components ) {
-              tab.addChild(component);
-          }
+               // Put the tabs on-screen in order
+               tabList.sort(sortCategories,16);
+               for each (tab in tabList) {
+                       editorStack.addChild(tab);
+                       tabComponents[tab] = [];
+               }
+
+               // Then add the individual editors to them
+               for each (factory in feature.editors) {
+
+                       // Add to basic editor box first
+                       if ( factory.presence.isEditorPresent(factory, selectedEntity, null) ) {
+                               var editor:DisplayObject = factory.createEditorInstance(selectedEntity);
+                               if (editor) Form(basicEditorBox.getChildByName("form")).addElement(UIComponent(editor));
+                       }
+
+                       // 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;
+                                       addConstrainedForm(subpanel);
+                                       tabComponents[tab].push(subpanel);
+                               }
+                               Form(subpanel.getChildByName("form")).addElement(UIComponent(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;
+               box.percentHeight = 100;
+               box.styleName = "dndEditorContainer";
+               addConstrainedForm(box);
+               return box;
+       }
+       
+       private function addConstrainedForm(parentObject:DisplayObjectContainer):void {
+               var form:Form = new Form();
+               form.name = "form";
+               form.percentWidth=100;
+               form.addEventListener(mx.events.ResizeEvent.RESIZE, formResizeHandler, false, 0, true);
+               parentObject.addChild(form);
+               if (parentObject.width>0) form.maxWidth=parentObject.width;
+       }
+       
+       private function formResizeHandler(e:Event):void {
+               var form:Form=Form(e.target);
+               if (form.parent.width>0) form.maxWidth=form.parent.width;
+       }
+
+       private function ensureEditorsPopulated(tab:VBox):void {
+               var components:Array = tabComponents[tab];
+               var form:Form=Form(tab.getChildByName("form"));
+               if ( components == null || tab == null || form.numElements >= components.length ) return;
+               for each (var component:DisplayObject in components ) {
+                       form.addElement(UIComponent(component));
+               }
+       }
+
        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);
        }
                editorStack.addEventListener("change",editorStackUIChange);
                editorStack.addEventListener("updateComplete",editorStackUIUpdate);
        }
-       
+
        private function editorStackUIChange(event:Event):void {
                ensureEditorsPopulated(IndexChangedEvent(event).relatedObject as VBox);
        }
 
        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);
                }
        }
 
+       public function selectAdvancedPanel():void {
+               checkAdvanced();
+               stack.selectedChild=advancedContainer;
+       }
+
       private function checkAdvanced():void {
           if ( selectedEntity != null )
              setupAdvanced(selectedEntity);
       }
 
-      /**
-      * When you enter a new tag and press enter, the focus moves to the add button
-      * Adding an event listener to the button and listening for + means that you
-      * can add two consecutive tags with the same keypress. This relies on focus
-      * moving to the "add" button, though, so it's not robust to rearranging the UI.
-      */
-      private function advancedAddButtonKeyboardEvent(event:KeyboardEvent):void {
-          switch (event.keyCode) {
-            case 187:   addNewTag(); break;                          // + - add tag
-          }
-      }
-
       private var listeningToRelations:Array = [];
-      
+
       private function setupAdvanced(entity:Entity):void {
+               if (!advancedTagGrid) advancedContainer.createComponentsFromDescriptors();      // if Flex hasn't created it, force it
                advancedTagGrid.init(entity);
-        advancedAddButton.addEventListener(KeyboardEvent.KEY_DOWN, advancedAddButtonKeyboardEvent);
 
                if ( entity == null ) {
                        advancedID.htmlText = "";
                        if      ( entity is Node     ) entityText = "Node";
                        else if ( entity is Way      ) entityText = "Way";
                        else if ( entity is Relation ) entityText = "Relation";
-                       advancedID.htmlText = entityText+": <b>"+entity.id+"</b>";
+                       advancedID.htmlText = entityText+": <b>"+entity.id+"</b> "+(entity.status ? entity.status : '');
                }
 
                removeRelationListeners();
-               if ( selectedEntity != null ) {
-                       selectedEntity.removeEventListener(Connection.ADDED_TO_RELATION, addedToRelation);
-                       selectedEntity.removeEventListener(Connection.REMOVED_FROM_RELATION, removedFromRelation);
-               }
 
                if ( entity == null ) {
                        relationsGrid.dataProvider = null;
                }
       }
 
+         private function setupMultiAdvanced(entity:Entity):void {
+               multiAdvancedTagGrid.init(entity);
+               resetRelationsGrid(entity);
+               entity.addEventListener(Connection.ADDED_TO_RELATION, addedToRelation, false, 0, true);
+               entity.addEventListener(Connection.REMOVED_FROM_RELATION, removedFromRelation, false, 0, true);
+      }
+
          public function addNewTag():void {
-               if (stack.selectedChild!=advancedContainer) { return; }
-               advancedTagGrid.addNewTag();
+               if (sidebar.selectedChild==multiplePanel) { multiAdvancedTagGrid.addNewTag(); }
+               else if (stack.selectedChild==advancedContainer) { advancedTagGrid.addNewTag(); }
          }
-      
+
       private function addedToRelation(event:RelationMemberEvent):void {
          resetRelationsGrid(selectedEntity);
       }
               rel.removeEventListener(Connection.RELATION_MEMBER_REMOVED, entityRelationMemberChanged);
           }
           listeningToRelations = [];
-          relationsGrid.removeEventListener(DataGridEvent.ITEM_EDIT_END, relationRoleChanged);
+          if (relationsGrid) relationsGrid.removeEventListener(DataGridEvent.ITEM_EDIT_END, relationRoleChanged);
+          if (multiRelationsGrid) multiRelationsGrid.removeEventListener(DataGridEvent.ITEM_EDIT_END, relationRoleChanged);
       }
-            
+
       private function resetRelationsGrid(entity:Entity):void {
           removeRelationListeners();
-          var relations:Array = [];
-          for each( var rel:Relation in entity.parentRelations ) {
-              for each( var memberIndex:int in rel.findEntityMemberIndexes(entity)) {
-                  var props:Object = {};
-                  props["relation"] = rel;
-                  props["id"] = rel.id;
-                  props["index"] = memberIndex;
-                  props["role"] = rel.getMember(memberIndex).role;
-                  props["description"] = rel.getDescription();
-                  props["id_idx"] = rel.id + "/"+memberIndex;
-
-                  relations.push(props);
-              }
-              
-              rel.addEventListener(Connection.TAG_CHANGED, relationTagChanged);
-              rel.addEventListener(Connection.RELATION_MEMBER_ADDED, entityRelationMemberChanged);
-              rel.addEventListener(Connection.RELATION_MEMBER_REMOVED, entityRelationMemberChanged);
-              listeningToRelations.push(rel);
+
+          var instance:DataGrid=relationsGrid;
+          if (entity is EntityCollection) instance=multiRelationsGrid;
+          var memberships:Array = entity.getRelationMemberships();
+          for each (var m:Object in memberships) {
+              m.relation.addEventListener(Connection.TAG_CHANGED, relationTagChanged);
+              m.relation.addEventListener(Connection.RELATION_MEMBER_ADDED, entityRelationMemberChanged);
+              m.relation.addEventListener(Connection.RELATION_MEMBER_REMOVED, entityRelationMemberChanged);
+              listeningToRelations.push(m.relation);
           }
-          relationsGrid.dataProvider = relations;
-          relationsGrid.addEventListener(DataGridEvent.ITEM_EDIT_END, relationRoleChanged, false, -100);
+          instance.dataProvider = memberships;
+          instance.addEventListener(DataGridEvent.ITEM_EDIT_END, relationRoleChanged, false, -100);
       }
-      
+
       private function relationRoleChanged(event:DataGridEvent):void {
                if (event.dataField != 'role') { return; }      // shouldn't really happen
 
                var props:Object=relations[event.rowIndex];
 
                var relation:Relation=props['relation'];
-               var index:uint=props['index'];
                var newRole:String=event.itemRenderer.data['role'];
 
-               relation.setMember(index, new RelationMember(selectedEntity,newRole));
+               if (selectedEntity is EntityCollection) {
+                       for each (var entity:Entity in EntityCollection(selectedEntity).entities) {
+                               var indexes:Array=relation.findEntityMemberIndexes(entity);
+                               for each (var index:int in indexes) {
+                                       relation.setMember(index, new RelationMember(entity,newRole), MainUndoStack.getGlobalStack().addAction);
+                               }
+                       }
+               } else {
+                       relation.setMember(props['index'], new RelationMember(selectedEntity,newRole), MainUndoStack.getGlobalStack().addAction);
+               }
       }
 
       private function relationTagChanged(event:TagEvent):void {
       private function entityRelationMemberChanged(event:RelationMemberEvent):void {
           resetRelationsGrid(selectedEntity);
       }
-      
+
       private function checkMembers():void {
           if (selectedEntity is Relation) {
             setupMembers(selectedEntity as Relation);
           }
       }
-      
+
       private function setupMembers(rel:Relation):void {
           var members:Array = [];
           for (var i:int=0 ; i<rel.length; i++) {
             props["id"] = member.entity.id;
             props["type"] = member.entity.getType();
             props["role"] = member.role;
-            
+
             members.push(props);
           }
           membersGrid.dataProvider = members;
-          membersGrid.dataProvider.addEventListener('collectionChange', membersChange); 
+          membersGrid.dataProvider.addEventListener('collectionChange', membersChange);
       }
-      
+
       private function membersChange(event:Event):void {
           // Dropping all the members and re-adding them isn't exactly optimal
           // but is at least robust for any kind of change.
           // Figuring out a better way is someone else's FIXME
-          
-          var conn:Connection = Connection.getConnectionInstance();
-          var rel:Relation = selectedEntity as Relation
-          
+
+          var rel:Relation = selectedEntity as Relation;
+          var action:CompositeUndoableAction = new CompositeUndoableAction("Rearrange relation members for "+rel);
+
           // drop members
           for (var i:int=rel.length-1 ; i>=0; i--) {
-            rel.removeMemberByIndex(i);
+            rel.removeMemberByIndex(i, action.push);
           }
-          
+
           // add members in new order
           for each(var memberObject:Object in membersGrid.dataProvider) {
             var e:Entity;
             var id:Number = memberObject.id;
-            if(memberObject.type == 'node') {
-              e = conn.getNode(id);
-            } else if (memberObject.type == 'way') {
-              e = conn.getWay(id);
-            } else if (memberObject.type == 'relation') {
-              e = conn.getRelation(id);
+                       switch (memberObject.type) {
+                               case 'node':            e = connection.getNode(id); break;
+               case 'way':                     e = connection.getWay(id); break;
+                               case 'relation':        e = connection.getRelation(id); break;
             }
-            rel.appendMember(new RelationMember(e, memberObject.role));
+            rel.appendMember(new RelationMember(e, memberObject.role), action.push);
           }
+          MainUndoStack.getGlobalStack().addAction(action);
       }
-      
+
       private function editRelation(id:Number):void {
           var panel:RelationEditorPanel = RelationEditorPanel(
-              PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
-          panel.setRelation(Connection.getConnectionInstance().getRelation(id));
+              PopUpManager.createPopUp(Application(FlexGlobals.topLevelApplication), RelationEditorPanel, true));
+          panel.setRelation(connection.getRelation(id));
           PopUpManager.centerPopUp(panel);
       }
-      
+
+       /** Create relation actions menu */
+
+       public function createRelationMenu(button:PopUpButton):void {
+               var menu:Menu = new Menu(); 
+               var dp:Object = [ {label: "Select all members"}, 
+                                                 {label: "Deselect all members"}, 
+                                                 {label: "Add selection to this relation", enabled: false},
+                                                 {label: "Delete relation"} ]; 
+               menu.dataProvider = dp; 
+               menu.addEventListener("itemClick", selectRelationMenu); 
+               button.popUp = menu;
+       }
+
+       /** Enable 'add selection to...' entry only if some of the selection isn't in the relation.
+           Called each time the menu is clicked. */
+       
+       public function updateRelationMenu(event:Event):void {
+               rowData=event.target.parent.data;       // this makes it accessible from selectRelationMenu
+               var menu:Menu = Menu(event.target.popUp);
+               var enable:Boolean = false;
+               if (selectedEntity != null && selectedEntity is EntityCollection) {
+                       // Enable only if some entities aren't a member of the relation
+                       enable=!rowData.universal;
+               }
+               if (enable==menu.dataProvider[2].enabled) return;
+               menu.dataProvider[2].enabled=enable;
+               menu.invalidateList();
+       }
+
+       /** Do the action selected in the relation actions menu */
+
+       public function selectRelationMenu(event:MenuEvent):void {
+               var rel:Relation=rowData.relation;
+               var entities:Array;
+               var controller:EditController=FlexGlobals.topLevelApplication.theController;
+               switch (event.index) {
+                       case 0: // Select all members
+                               entities=selectedEntity.entities.concat(rel.memberEntities);
+                               entities=entities.filter(function(e:*, i:int, arr:Array):Boolean { return arr.indexOf(e) == i } );      // remove duplicates
+                               // ** FIXME: This is a really horrible way of changing the controller state
+                               controller.setState(controller.findStateForSelection(entities));
+                               break;
+
+                       case 1: // Deselect all members
+                               entities=selectedEntity.entities;
+                               entities=entities.filter(function(e:*, i:int, arr:Array):Boolean { return !e.hasParent(rel) } );
+                               controller.setState(controller.findStateForSelection(entities));
+                               break;
+
+                       case 2: // Add selection to this relation
+                               var undo:CompositeUndoableAction=new CompositeUndoableAction("Remove selection from relations");
+                               for each (var entity:Entity in selectedEntity.entities) {
+                                       if (!entity.hasParent(rel)) {
+                                               rel.appendMember(new RelationMember(entity,''), undo.push);
+                                       }
+                               }
+                               MainUndoStack.getGlobalStack().addAction(undo);
+                               break;
+                       
+                       case 3: // Delete relation
+                               var warning:String="This relation has # members. Deleting it will affect all of them and erase this $. Are you really sure?";
+                               warning=warning.replace("#",rel.length).replace("$",rel.getRelationType());
+                               Alert.show(warning,"Are you sure?",Alert.YES | Alert.CANCEL,null,
+                                       function(event:CloseEvent):void { 
+                                               if (event.detail==Alert.CANCEL) return;
+                                               rel.remove(MainUndoStack.getGlobalStack().addAction);
+                                       } , null, Alert.CANCEL);
+                               break;
+               }
+       }
+
       private function tagChanged(event:TagEvent):void {
           refreshFeatureIcon();
-          // if the advancedTagGrid has already been set up, it needs to be refreshed.
-          // FIXME make this better, maybe advancedTagGrid should be event listening.
-          if(advancedContainer.initialized) {
-            checkAdvanced();
-          }
       }
 
       public function loadFeatures():void {
           stack.removeChild(membersVBox); // remove by default, will be added if relation
       }
 
+      /** Open up a new browser page, showing the help page as defined in Map Features XML file .*/
       public function openDescription():void {
           if ( feature != null && feature.hasHelpURL() )
               navigateToURL(new URLRequest(feature.helpURL), "potlatch_help");
       }
 
-      public function openEntityPage():void {
-          if (selectedEntity != null && selectedEntity.id >= 0) {
-              // This is slightly hard-coded, but not drastically. The ../s could be changed for string manipulation of the apiBase
-              var urlBase:String = Connection.getConnectionInstance().apiBase + '../../browse/'
-              navigateToURL(new URLRequest(urlBase+selectedEntity.getType()+'/'+selectedEntity.id), "potlatch_browse");
-          }
-      }
-
       public function addToRelation():void {
           new RelationSelectPanel().init(selectedEntity,new Object());
       }
-      
-      public function removeFromRelation(id:Number, index:int):void {
-          Connection.getConnectionInstance().getRelation(id).removeMemberByIndex(index);
-      }
-      
-      public function initFeatureBox():void {
-          tw = new CategorySelector();
-          tw.addEventListener("selectedType", changeFeatureType);
-          popupChange.popUp = tw;
+
+      private function removeFromRelation(id:Number, index:int=-1):void {
+               var rel:Relation=connection.getRelation(id);
+               if (index>-1) {
+                       rel.removeMemberByIndex(index, MainUndoStack.getGlobalStack().addAction);
+               } else if (selectedEntity is EntityCollection) {
+                       var undo:CompositeUndoableAction=new CompositeUndoableAction("Remove selection from relations");
+                       for each (var e:Entity in EntityCollection(selectedEntity).entities) rel.removeMember(e,undo.push);
+                       MainUndoStack.getGlobalStack().addAction(undo);
+               }
       }
-      
+
       public function changeFeatureType(event:Event):void {
           if ( selectedEntity == null )
               return;
 
           UIComponent.suspendBackgroundProcessing();
-          var newFeature:Feature = tw.selectedType;
+          var newFeature:Feature = currentCategorySelector.selectedType;
           var undoStack:Function = MainUndoStack.getGlobalStack().addAction;
           var action:CompositeUndoableAction = new CompositeUndoableAction(
                   "Set "+selectedEntity.getType()+" "+selectedEntity.id+" to "+newFeature.name);
                  selectedEntity.suspend();
+          
+          // build a list of tags that are editable in new feature
+          var editableTags:Array = new Array();
+          for each( var editor:EditorFactory in newFeature.editors ) {
+              if ( editor is SingleTagEditorFactory ) {
+                  var singleTagEditor:SingleTagEditorFactory = editor as SingleTagEditorFactory;
+                  editableTags.push(singleTagEditor.key);
+              }
+          }
 
           // remove tags from the current feature
           if ( feature != null ) {
               for each( var oldtag:Object in feature.tags ) {
-                  selectedEntity.setTag(oldtag["k"], null, action.push);
+                  if ( editableTags.indexOf(oldtag["k"]) < 0 ) {
+                      selectedEntity.setTag(oldtag["k"], null, action.push);
+                  }
               }
           }
-          
+
           // set tags for new feature
           if ( newFeature != null ) {
               for each( var newtag:Object in newFeature.tags ) {
                   selectedEntity.setTag(newtag["k"], newtag["v"], action.push);
               }
           }
-          
+
                  selectedEntity.resume();
           undoStack(action);
           popupChange.close();
           initialiseEditors();
           UIComponent.resumeBackgroundProcessing();
       }
-      
+
        private function resizePOIGrid(event:Event):void {
                var rows:Number=event.target.dataProvider.length/event.target.columnCount;
                if (rows!=Math.floor(rows)) { rows=Math.floor(rows+1); }
                event.target.height=rows*(event.target.rowHeight+1);
        }
-  ]]></mx:Script>
+
+  ]]></fx:Script>
 </mx:VBox>