Merge branch 'master' into history
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / SingleTagEditor.as
1 package net.systemeD.potlatch2.mapfeatures.editors {
2
3     import net.systemeD.halcyon.connection.*;
4     import net.systemeD.potlatch2.mapfeatures.*;
5     import spark.components.FormItem;
6     import flash.events.*;
7
8     public class SingleTagEditor extends FormItem {
9
10       protected var _factory:SingleTagEditorFactory;
11       protected var _entity:Entity;
12       
13       [Bindable(event="factory_set")]
14       public function get fieldName():String {
15           return _factory == null ? "" : _factory.name;
16       }
17       
18       [Bindable(event="factory_set")]
19       public function get fieldDescription():String {
20           return _factory == null ? "" : _factory.description;
21       }
22
23       [Bindable(event="factory_set")]
24       public function get fieldDirection():String {
25           return _factory == null ? "" : _factory.direction;
26       }
27       
28       [Bindable(event="tag_changed")]
29       public function get value():String {
30           return _entity == null ? null : _entity.getTag(_factory.key);
31       }
32       
33       public function set value(val:String):void {
34           if ( _entity != null )
35               _entity.setTag(_factory.key, val, MainUndoStack.getGlobalStack().addAction);
36       }
37
38       public function set factory(factory:SingleTagEditorFactory):void {
39           _factory = factory;
40           dispatchEvent(new Event("factory_set"));
41       }
42       
43       public function set entity(entity:Entity):void {
44           _entity = entity;
45           entity.addEventListener(Connection.TAG_CHANGED, tagChanged, false, 0, true);
46           dispatchEvent(new Event("tag_changed"));
47       }
48       
49       private function tagChanged(event:TagEvent):void {
50           var tagVal:String = _entity.getTag(_factory.key);
51           dispatchEvent(new Event("tag_changed"));
52       }
53
54     }
55
56 }
57
58