Relation selection dialog
[potlatch2.git] / net / systemeD / halcyon / connection / Relation.as
1 package net.systemeD.halcyon.connection {
2
3     public class Relation extends Entity {
4         private var members:Array;
5                 public static var entity_type:String = 'relation';
6
7         public function Relation(id:Number, version:uint, tags:Object, loaded:Boolean, members:Array) {
8             super(id, version, tags, loaded);
9             this.members = members;
10                         for each (var member:RelationMember in members) { member.entity.addParent(this); }
11         }
12
13         public function update(version:uint, tags:Object, loaded:Boolean, members:Array):void {
14                         var member:RelationMember;
15                         for each (member in this.members) { member.entity.removeParent(this); }
16                         updateEntityProperties(version,tags,loaded); this.members=members;
17                         for each (member in members) { member.entity.addParent(this); }
18                 }
19                 
20         public function get length():uint {
21             return members.length;
22         }
23
24         public function findEntityMemberIndex(entity:Entity):int {
25             for (var index:uint = 0; index < members.length; index++) {
26                 var member:RelationMember = members[index];
27                 if ( member.entity == entity )
28                     return index;
29             }
30             return -1;
31         }
32         
33         public function getMember(index:uint):RelationMember {
34             return members[index];
35         }
36
37         public function setMember(index:uint, member:RelationMember):void {
38                         member.entity.addParent(this);
39                         members.splice(index, 1, member);
40         }
41
42         public function insertMember(index:uint, member:RelationMember):void {
43                         member.entity.addParent(this);
44             members.splice(index, 0, member);
45         }
46
47         public function appendMember(member:RelationMember):uint {
48                         member.entity.addParent(this);
49             members.push(member);
50             return members.length;
51         }
52
53         public function removeMember(index:uint):void {
54             var removed:Array=members.splice(index, 1);
55                         removed[0].entity.removeParent(this);
56         }
57
58         public function getDescription():String {
59             var desc:String = "";
60             var relTags:Object = getTagsHash();
61             if ( relTags["type"] ) {
62                 desc = relTags["type"];
63                 if ( relTags[desc] )
64                     desc += " " + relTags[desc];
65             }
66             if ( relTags["ref"] )
67                 desc += " " + relTags["ref"];
68             if ( relTags["name"] )
69                 desc += " " + relTags["name"];
70             return desc;
71         }
72
73                 public override function getType():String {
74                         return 'relation';
75                 }
76                 
77                 public override function toString():String {
78             return "Relation("+id+"@"+version+"): "+members.length+" members "+getTagList();
79         }
80
81     }
82
83 }