start of turn restriction editor
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / RelationMemberEditorFactory.as
1 package net.systemeD.potlatch2.mapfeatures.editors {
2
3     import net.systemeD.halcyon.connection.*;
4     import net.systemeD.potlatch2.mapfeatures.*;
5     import flash.display.*;
6
7         public class RelationMemberEditorFactory extends EditorFactory {
8             private var _relationTags:Object;
9                 private var _role:String;
10         
11         public function RelationMemberEditorFactory(inputXML:XML) {
12             super(inputXML);
13             _relationTags = {};
14             for each(var match:XML in inputXML.match) {
15                 _relationTags[match.@k] = match.@v;
16             }
17                         for each(var role:XML in inputXML.role) {
18                                 _role=role.@role;
19                         }
20         }
21         
22         public function get relationTags():Object {
23             return _relationTags;
24         }
25         
26         public function get role():String {
27             return _role;
28         }
29         
30         override public function areTagsMatching(entity:Entity):Boolean {
31             var parentRelations:Array = entity.parentRelations;
32             if ( parentRelations.length == 0 )
33                 return false;
34
35             // get relations for the entity
36             for each(var relation:Relation in parentRelations) {
37                                 var match:Boolean=true;
38                 for ( var k:String in _relationTags ) {
39                     var relVal:String = relation.getTag(k);
40                     if ( relVal != _relationTags[k] ) { match=false; break; }
41                                         if ( _role && !relation.hasMemberInRole(entity,_role) ) { match=false; break; }
42                 }
43                                 if (match) { return true; }
44             }
45                         return false;
46         }
47         
48         override public function createEditorInstance(entity:Entity):DisplayObject {
49             var editor:RelationMemberEditor = createRelationMemberEditor();
50             editor.factory = this;
51             editor.entity = entity;
52             return editor;
53         }
54         
55         protected function createRelationMemberEditor():RelationMemberEditor {
56             return null;
57         }
58     }
59
60 }
61
62