Merge branch 'master' into history
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / RelationMemberEditorFactory.as
1 package net.systemeD.potlatch2.mapfeatures.editors {
2
3     import flash.display.*;
4     
5     import net.systemeD.halcyon.connection.*;
6     import net.systemeD.potlatch2.mapfeatures.*;
7
8         public class RelationMemberEditorFactory extends EditorFactory {
9             /** Contains "route"=["hiking","foot"] key/values. The <match> map_features tag is parsed here from
10             * "hiking|foot" pipe-separated values. */
11             private var _relationTagPatterns:Object;
12                 private var _role:String;
13         
14         /** Constructs the editing panel for a relation(###), given its <relation> in map_features.xml */
15         public function RelationMemberEditorFactory(inputXML:XML) {
16             super(inputXML);
17             _relationTagPatterns = {};
18             for each(var match:XML in inputXML.match) {
19                 _relationTagPatterns[match.@k] = match.@v.split('|');
20             }
21                         for each(var role:XML in inputXML.role) {
22                                 _role=role.@role;
23                         }
24         }
25         
26         public function get relationTagPatterns():Object {
27             return _relationTagPatterns;
28         }
29         
30         public function get role():String {
31             return _role;
32         }
33         
34         override public function areTagsMatching(entity:Entity):Boolean {
35             var parentRelations:Array = entity.parentRelations;
36             if ( parentRelations.length == 0 )
37                 return false;
38
39             // get relations for the entity
40             for each(var relation:Relation in parentRelations) {
41                                 var match:Boolean=true;
42                 for ( var k:String in _relationTagPatterns ) {
43                     var relVal:String = relation.getTag(k);
44                     if (k.indexOf(relVal) < 0) { match=false; break; }
45                                         if ( _role && !relation.hasMemberInRole(entity,_role) ) { match=false; break; }
46                 }
47                                 if (match) { return true; }
48             }
49                         return false;
50         }
51         
52         override public function createEditorInstance(entity:Entity):DisplayObject {
53             var editor:RelationMemberEditor = createRelationMemberEditor();
54             editor.factory = this;
55             editor.entity = entity;
56             return editor;
57         }
58         
59         protected function createRelationMemberEditor():RelationMemberEditor {
60             return null;
61         }
62     }
63
64 }
65
66