how do I hate thee, Flex? let me count the ways
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / Presence.as
1 package net.systemeD.potlatch2.mapfeatures {
2
3     import net.systemeD.halcyon.connection.*;
4
5
6         public class Presence {
7             private static var ALWAYS:Presence;
8             private static var ON_TAG_MATCH:Presence;
9             private static var WITH_CATEGORY:Presence;
10         
11         public static function getPresence(presence:String):Presence {
12             if ( ALWAYS == null ) {
13                 ALWAYS = new Presence();
14                 ON_TAG_MATCH = new OnTagMatch();
15             }
16             if ( presence == "always" )
17                 return ALWAYS;
18             if ( presence == "onTagMatch" )
19                 return ON_TAG_MATCH;
20             if ( presence == "withCategory" )
21                 return WITH_CATEGORY;
22             return ON_TAG_MATCH;
23         }
24
25         public function isEditorPresent(editor:EditorFactory, forEntity:Entity, forCategory:String):Boolean {
26             return forCategory == null || forCategory == editor.category;
27         }
28
29     }
30
31 }
32
33     import net.systemeD.halcyon.connection.*;
34     import net.systemeD.potlatch2.mapfeatures.*;
35
36     class OnTagMatch extends Presence {
37         public function OnTagMatch() {}
38         
39         override public function isEditorPresent(editor:EditorFactory, forEntity:Entity, forCategory:String):Boolean {
40             return (forCategory == null || forCategory == editor.category) &&
41                       editor.areTagsMatching(forEntity);
42         }
43     }
44
45     class WithCategory extends Presence {
46         public function WithCategory() {}
47         
48         override public function isEditorPresent(editor:EditorFactory, forEntity:Entity, forCategory:String):Boolean {
49             return forCategory == editor.category &&
50                       editor.areTagsMatching(forEntity);
51         }
52     }
53