Relation selection dialog
[potlatch2.git] / net / systemeD / potlatch2 / TagViewer.mxml
index 064cd2505dd67f75bbe7be48b711dd2a0b94d636..449c05f269b893d4bcd41808aa96dad6a3d99305 100644 (file)
@@ -1,8 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <mx:VBox
 <?xml version="1.0" encoding="utf-8"?>
 <mx:VBox
-       xmlns:mx="http://www.adobe.com/2006/mxml" 
+       xmlns:mx="http://www.adobe.com/2006/mxml"
+       xmlns:flexlib="flexlib.containers.*"
     backgroundColor="white"
     backgroundColor="white"
-    creationComplete="loadFeatures()">
+    initialize="loadFeatures()">
 
   <mx:ViewStack id="stack" width="100%" height="100%">
   <mx:VBox width="100%" height="100%" label="Simple">
 
   <mx:ViewStack id="stack" width="100%" height="100%">
   <mx:VBox width="100%" height="100%" label="Simple">
@@ -14,7 +15,9 @@
         </mx:VBox>
         <mx:LinkButton label="?" click="openDescription()" id="helpLabel"/>
     </mx:HBox>
         </mx:VBox>
         <mx:LinkButton label="?" click="openDescription()" id="helpLabel"/>
     </mx:HBox>
-    <mx:VBox width="100%" id="editorBox" paddingLeft="2" paddingRight="2"/>
+    <flexlib:SuperTabNavigator id="editorStack" width="100%" height="100%" paddingLeft="2" paddingRight="2"
+        allowTabSqueezing="false" minTabWidth="10" closePolicy="close_never"
+        scrollSpeed="20"/>
   </mx:VBox>
 
   <mx:VBox width="100%" height="100%" label="Advanced" initialize="checkAdvanced()" verticalGap="1">
   </mx:VBox>
 
   <mx:VBox width="100%" height="100%" label="Advanced" initialize="checkAdvanced()" verticalGap="1">
@@ -22,7 +25,7 @@
       <mx:htmlText><![CDATA[<i>No Selection</i>]]></mx:htmlText>
     </mx:Label>
 
       <mx:htmlText><![CDATA[<i>No Selection</i>]]></mx:htmlText>
     </mx:Label>
 
-    <mx:DataGrid editable="true" width="100%" height="100%" id="advancedTagGrid">
+    <mx:DataGrid editable="true" width="100%" height="75%" id="advancedTagGrid">
             <mx:columns>
                 <mx:DataGridColumn editable="true" dataField="key" headerText="Key"/>
                 <mx:DataGridColumn editable="true" dataField="value" headerText="Value"/>
             <mx:columns>
                 <mx:DataGridColumn editable="true" dataField="key" headerText="Key"/>
                 <mx:DataGridColumn editable="true" dataField="value" headerText="Value"/>
       <mx:LinkButton label="Delete" click="removeTag()"/>
       <mx:LinkButton label="Add" click="addNewTag()"/>
     </mx:HBox>
       <mx:LinkButton label="Delete" click="removeTag()"/>
       <mx:LinkButton label="Add" click="addNewTag()"/>
     </mx:HBox>
+    
+    <mx:DataGrid editable="true" width="100%" height="25%" id="relationsGrid"
+        doubleClickEnabled="true"
+        itemDoubleClick="editRelation(ListEvent(event).rowIndex)">
+        <mx:columns>
+            <mx:DataGridColumn editable="false" dataField="description" headerText="Relation"/>
+            <mx:DataGridColumn editable="false" dataField="id" headerText="ID"/>
+            <mx:DataGridColumn editable="true" dataField="role" headerText="Role"/>
+        </mx:columns>
+    </mx:DataGrid>
+
+    <mx:HBox horizontalAlign="right" width="100%">
+      <mx:LinkButton label="Remove from" click="removeFromRelation()"/>
+      <mx:LinkButton label="Add to" click="addToRelation()"/>
+    </mx:HBox>
+
   </mx:VBox>
 
   </mx:ViewStack>
   </mx:VBox>
 
   </mx:ViewStack>
       import mx.core.*;
       import mx.managers.PopUpManager;
       import flash.geom.Point;
       import mx.core.*;
       import mx.managers.PopUpManager;
       import flash.geom.Point;
+      import flash.net.*;
       
       private var mapFeatures:MapFeatures;
       private var selectedEntity:Entity;
       
       private var mapFeatures:MapFeatures;
       private var selectedEntity:Entity;
-      private var collection:ArrayCollection;
+      private var tagDataProvider:ArrayCollection;
       private var tw:CategorySelector = null;
       private var feature:Feature = null;
 
       private var tw:CategorySelector = null;
       private var feature:Feature = null;
 
           var txt:String = feature.htmlDetails(entity);
           iconText.htmlText = txt;
           popupChange.label = feature.name;
           var txt:String = feature.htmlDetails(entity);
           iconText.htmlText = txt;
           popupChange.label = feature.name;
+          setLimitTypes(entity);
           tw.setSelectedFeature(feature);
           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);
       }
 
       private function blankFeatureIcon(entity:Entity):void {
       }
 
       private function blankFeatureIcon(entity:Entity):void {
                "<i>Nothing selected</i>" :
                "<b>Not recognised</b><br/>Try looking at the tags under the advanced properties";
           popupChange.label = "unknown";
                "<i>Nothing selected</i>" :
                "<b>Not recognised</b><br/>Try looking at the tags under the advanced properties";
           popupChange.label = "unknown";
+          setLimitTypes(entity);
           tw.setSelectedFeature(null);
           tw.setSelectedFeature(null);
+          helpLabel.visible = false;
       }
 
       private function initialiseEditors():void {
       }
 
       private function initialiseEditors():void {
-          editorBox.removeAllChildren();
+          editorStack.removeAllChildren();
           if ( selectedEntity == null || feature == null )
               return;
           if ( selectedEntity == null || feature == null )
               return;
-              
+          
+          var editorBox:VBox = createEditorBox();
+          editorBox.label = "Basic";
+          editorStack.addChild(editorBox);
+          
+          var tabs:Object = {};
+          
           for each (var factory:EditorFactory in feature.editors) {
           for each (var factory:EditorFactory in feature.editors) {
-              var editor:DisplayObject = factory.createEditorInstance(selectedEntity);
-              if ( editor != null )
-                 editorBox.addChild(editor);
+              if ( factory.presence.isEditorPresent(factory, selectedEntity, null) ) {
+                  var editor:DisplayObject = factory.createEditorInstance(selectedEntity);
+                  if ( editor != null )
+                      editorBox.addChild(editor);
+              }
+              var category:String = factory.category;
+              var tab:VBox = tabs[category];
+              if ( tab == null ) {
+                  tab = createEditorBox();
+                  tab.label = category;
+                  editorStack.addChild(tab);
+                  tabs[category] = tab;
+              }
+              var catEditor:DisplayObject = factory.createEditorInstance(selectedEntity);
+              if ( catEditor != null )
+                  tab.addChild(catEditor);
           }
       }
       
           }
       }
       
+      private function createEditorBox():VBox {
+          var box:VBox = new VBox();
+          box.percentWidth = 100;
+          box.percentHeight = 100;
+          return box;
+      }
+
       private function checkAdvanced():void {
           if ( selectedEntity != null )
              setupAdvanced(selectedEntity);
       }
 
       private function setupAdvanced(entity:Entity):void {
       private function checkAdvanced():void {
           if ( selectedEntity != null )
              setupAdvanced(selectedEntity);
       }
 
       private function setupAdvanced(entity:Entity):void {
-          if ( collection == null ) {
-              collection = new ArrayCollection();
-              advancedTagGrid.dataProvider = collection;
+          if ( tagDataProvider == null ) {
+              tagDataProvider = new ArrayCollection();
+              advancedTagGrid.dataProvider = tagDataProvider;
           }
 
           }
 
-          collection.removeAll();
+          tagDataProvider.removeAll();
           
           if ( entity == null ) {
               advancedID.htmlText = "";
           
           if ( entity == null ) {
               advancedID.htmlText = "";
               var tags:Array = entity.getTagArray();
               tags.sortOn("key");
               for each(var tag:Tag in tags)
               var tags:Array = entity.getTagArray();
               tags.sortOn("key");
               for each(var tag:Tag in tags)
-                  collection.addItem(tag);
+                  tagDataProvider.addItem(tag);
+          }
+          
+          if ( entity == null ) {
+              relationsGrid.dataProvider = null;
+          } else {
+              var relations:Array = [];
+              for each( var rel:Relation in entity.parentRelations ) {
+                  var props:Object = {};
+                  props["relation"] = rel;
+                  props["id"] = rel.id;
+                  var memberIndex:uint = rel.findEntityMemberIndex(entity);
+                  props["role"] = rel.getMember(memberIndex).role;
+                  props["description"] = rel.getDescription();
+                  
+                  relations.push(props);
+              }
+              relationsGrid.dataProvider = relations;
           }
       }
 
           }
       }
 
+      private function editRelation(index:uint):void {
+          trace("edit relation "+index+" "+selectedEntity.parentRelations[index]);
+          var panel:RelationEditorPanel = RelationEditorPanel(
+              PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
+          panel.setRelation(selectedEntity.parentRelations[index]);
+          PopUpManager.centerPopUp(panel);
+      }
+      
       private function tagChanged(event:TagEvent):void {
           refreshFeatureIcon();
           
       private function tagChanged(event:TagEvent):void {
           refreshFeatureIcon();
           
-          if ( collection != null ) {
+          if ( tagDataProvider != null ) {
               // check to see if the key is already in our list
               var exists:Boolean = false;
               var tag:Tag = null;
               var i:uint;
               // check to see if the key is already in our list
               var exists:Boolean = false;
               var tag:Tag = null;
               var i:uint;
-              for ( i = 0; i < collection.length && !exists; i++ ) {
-                  tag = Tag(collection.getItemAt(i));
+              for ( i = 0; i < tagDataProvider.length && !exists; i++ ) {
+                  tag = Tag(tagDataProvider.getItemAt(i));
                   exists = tag.key == event.key;
               }
               if ( !exists ) {
                   tag = new Tag(selectedEntity, event.key, event.newValue);
                   exists = tag.key == event.key;
               }
               if ( !exists ) {
                   tag = new Tag(selectedEntity, event.key, event.newValue);
-                  collection.addItem(tag);
-                  collection.refresh();
+                  tagDataProvider.addItem(tag);
+                  tagDataProvider.refresh();
               } else {
                   if ( event.newValue == null ) {
               } else {
                   if ( event.newValue == null ) {
-                      collection.removeItemAt(i-1);
-                      collection.refresh();
+                      tagDataProvider.removeItemAt(i-1);
+                      tagDataProvider.refresh();
                   } else {
                   } else {
-                      collection.itemUpdated(tag, "value");
+                      tagDataProvider.itemUpdated(tag, "value");
                   }
               }
           }
                   }
               }
           }
 
       public function openDescription():void {
           trace("open description here");
 
       public function openDescription():void {
           trace("open description here");
+          if ( feature != null && feature.hasHelpURL() )
+              navigateToURL(new URLRequest(feature.helpURL), "potlatch_help");
       }
 
       public function addNewTag():void {
           var newKey:String = "(new tag)";
           var newTag:Tag = new Tag(selectedEntity, newKey, "(new value)");
       }
 
       public function addNewTag():void {
           var newKey:String = "(new tag)";
           var newTag:Tag = new Tag(selectedEntity, newKey, "(new value)");
-          collection.addItem(newTag);
-          advancedTagGrid.editedItemPosition = {rowIndex: collection.getItemIndex(newTag), columnIndex: 0};
+          tagDataProvider.addItem(newTag);
+          advancedTagGrid.editedItemPosition = {rowIndex: tagDataProvider.getItemIndex(newTag), columnIndex: 0};
       }
 
       public function removeTag():void {
       }
 
       public function removeTag():void {
           selectedEntity.setTag(k, null);
       }
       
           selectedEntity.setTag(k, null);
       }
       
+      public function addToRelation():void {
+          new RelationSelectPanel().init(selectedEntity);        
+      }
+      
+      public function removeFromRelation():void {
+      }
+      
       public function initFeatureBox():void {
           tw = new CategorySelector();
           tw.addEventListener("selectedType", changeFeatureType);
       public function initFeatureBox():void {
           tw = new CategorySelector();
           tw.addEventListener("selectedType", changeFeatureType);