Relation selection dialog
[potlatch2.git] / net / systemeD / halcyon / connection / Relation.as
index 475a95ef00303cd7e33aa294dfad9287966055ab..784d6f73275a7f0c64b0587074105b4451ec1003 100644 (file)
@@ -4,16 +4,32 @@ package net.systemeD.halcyon.connection {
         private var members:Array;
                public static var entity_type:String = 'relation';
 
-        public function Relation(id:Number, version:uint, tags:Object, members:Array) {
-            super(id, version, tags);
+        public function Relation(id:Number, version:uint, tags:Object, loaded:Boolean, members:Array) {
+            super(id, version, tags, loaded);
             this.members = members;
                        for each (var member:RelationMember in members) { member.entity.addParent(this); }
         }
 
+        public function update(version:uint, tags:Object, loaded:Boolean, members:Array):void {
+                       var member:RelationMember;
+                       for each (member in this.members) { member.entity.removeParent(this); }
+                       updateEntityProperties(version,tags,loaded); this.members=members;
+                       for each (member in members) { member.entity.addParent(this); }
+               }
+               
         public function get length():uint {
             return members.length;
         }
 
+        public function findEntityMemberIndex(entity:Entity):int {
+            for (var index:uint = 0; index < members.length; index++) {
+                var member:RelationMember = members[index];
+                if ( member.entity == entity )
+                    return index;
+            }
+            return -1;
+        }
+        
         public function getMember(index:uint):RelationMember {
             return members[index];
         }
@@ -39,9 +55,29 @@ 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';
                }
+               
+               public override function toString():String {
+            return "Relation("+id+"@"+version+"): "+members.length+" members "+getTagList();
+        }
+
     }
 
 }