Relation selection dialog
authorAndy Allan <gravitystorm@gmail.com>
Sat, 9 Jan 2010 18:14:10 +0000 (18:14 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Sat, 9 Jan 2010 18:14:10 +0000 (18:14 +0000)
net/systemeD/halcyon/connection/Relation.as
net/systemeD/potlatch2/RelationSelectPanel.mxml [new file with mode: 0644]
net/systemeD/potlatch2/TagViewer.mxml

index 22474adb7d7ab3da3a387483e3fa31a34c19ab9d..784d6f73275a7f0c64b0587074105b4451ec1003 100644 (file)
@@ -55,6 +55,21 @@ package net.systemeD.halcyon.connection {
                        removed[0].entity.removeParent(this);
         }
 
+        public function getDescription():String {
+            var desc:String = "";
+            var relTags:Object = getTagsHash();
+            if ( relTags["type"] ) {
+                desc = relTags["type"];
+                if ( relTags[desc] )
+                    desc += " " + relTags[desc];
+            }
+            if ( relTags["ref"] )
+                desc += " " + relTags["ref"];
+            if ( relTags["name"] )
+                desc += " " + relTags["name"];
+            return desc;
+        }
+
                public override function getType():String {
                        return 'relation';
                }
diff --git a/net/systemeD/potlatch2/RelationSelectPanel.mxml b/net/systemeD/potlatch2/RelationSelectPanel.mxml
new file mode 100644 (file)
index 0000000..5b2a8bd
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<mx:TitleWindow
+    xmlns:mx="http://www.adobe.com/2006/mxml"
+    xmlns:potlatch2="net.systemeD.potlatch2.*"
+    title="Select Relation" width="350" height="400"
+    showCloseButton="true" close="PopUpManager.removePopUp(this);">
+
+    <mx:Script><![CDATA[
+        import net.systemeD.halcyon.*;
+        import net.systemeD.halcyon.connection.*;
+        import net.systemeD.potlatch2.*;
+        import mx.managers.PopUpManager;
+        import mx.core.Application;
+
+        private var conn:Connection;
+        private var relationList:Array;
+        private var entity:Entity;
+
+        public function init(e:Entity):void {
+          entity = e;
+          PopUpManager.addPopUp(this, Application(Application.application), true);
+          PopUpManager.centerPopUp(this);
+    
+          var titles:Array = [];
+          conn = Connection.getConnectionInstance();
+          relationList = conn.getAllRelationIDs();
+          if (relationList.length == 0) {
+            warning.text = "No relations loaded";
+          } else {
+            warning.text = "These relations are available:";
+          }
+          //relationSelector.dataProvider = relationList;
+          for each (var id:Number in relationList) {
+            var relation:Relation = conn.getRelation(id);
+            titles.push({label:id + ": " + relation.getDescription(), relId:id});
+          }
+          relationSelector.dataProvider = titles;
+        }
+        
+        public function updateEntityAndClose():void {
+          var relation:Relation = conn.getRelation(relationSelector.selectedItem.relId);
+          relation.appendMember(new RelationMember(entity, ''));
+          PopUpManager.removePopUp(this);
+        }
+    ]]></mx:Script> 
+    <mx:Text id="warning" text="" />
+    <mx:List width="100%" height="100%" id="relationSelector" verticalScrollPolicy="on"> 
+    </mx:List>
+    <mx:ControlBar>
+      <mx:Button label="New Relation..." enabled="false"/>
+      <mx:Spacer width="100%"/>
+      <mx:Button label="Select" click="updateEntityAndClose();" enabled="{relationSelector.selectedItem != null? true : false}"/>
+    </mx:ControlBar>
+</mx:TitleWindow>
\ No newline at end of file
index d47478cb55a3fd0b0bbe7298269aa6106634d9f9..449c05f269b893d4bcd41808aa96dad6a3d99305 100644 (file)
                   props["id"] = rel.id;
                   var memberIndex:uint = rel.findEntityMemberIndex(entity);
                   props["role"] = rel.getMember(memberIndex).role;
-                  
-                  var desc:String = "";
-                  var relTags:Object = rel.getTagsHash();
-                  if ( relTags["type"] ) {
-                      desc = relTags["type"];
-                      if ( relTags[desc] )
-                          desc += " " + relTags[desc];
-                  }
-                  if ( relTags["ref"] )
-                      desc += " " + relTags["ref"];
-                  if ( relTags["name"] )
-                      desc += " " + relTags["name"];
-                  props["description"] = desc;
+                  props["description"] = rel.getDescription();
                   
                   relations.push(props);
               }
       }
       
       public function addToRelation():void {
+          new RelationSelectPanel().init(selectedEntity);        
       }
       
       public function removeFromRelation():void {