Set blank tags as black, and use that to debug some flawed logic
[potlatch2.git] / net / systemeD / potlatch2 / panels / BackgroundMergePanel.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2
3 <!--
4     Background Merge Panel
5 -->
6
7 <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" height="100%">
8   <mx:Text id="backgroundMergePanelText" text="W00t!!!" width="100%" styleName="helpInfo" />
9   <mx:DataGrid editable="false" id="backgroundPanelDG" width="100%" height="50%">
10     <mx:columns>
11       <mx:DataGridColumn editable="false" dataField="k" headerText="Key" />
12       <mx:DataGridColumn editable="false" dataField="e" headerText="OSM value" />
13       <mx:DataGridColumn editable="false" headerText="Merge" width="50" textAlign="center">
14         <mx:itemRenderer>
15           <mx:Component>
16             <mx:HBox horizontalAlign="center" verticalAlign="middle">
17               <mx:Button label="&lt;&lt;" visible="{parentDocument.buttonVisible(data.b, data.e)}" click="parentDocument.mergeForKey(data.k);" />
18             </mx:HBox>
19           </mx:Component>
20         </mx:itemRenderer>
21       </mx:DataGridColumn>
22       <mx:DataGridColumn editable="false" itemRenderer="net.systemeD.potlatch2.panels.BackgroundMergeFieldComponent" dataField="b" headerText="Background value" />
23     </mx:columns>
24   </mx:DataGrid>
25   <mx:Script><![CDATA[
26
27       import net.systemeD.halcyon.connection.*;
28       import mx.collections.*;
29
30       private var editableEntity:Entity;
31       private var backgroundEntity:Entity;
32       private var tagDataProvider:ArrayCollection;
33
34       public function init(entities:Array):void {
35           if ( tagDataProvider == null ) {
36               tagDataProvider = new ArrayCollection();
37               backgroundPanelDG.dataProvider = tagDataProvider;
38           }
39
40           if (parentDocument.controller.map.getLayerForEntity(entities[0]).isBackground) {
41               backgroundEntity = entities[0];
42               editableEntity = entities[1];
43           } else {
44               backgroundEntity = entities[1];
45               editableEntity = entities[0];
46           }
47           editableEntity.addEventListener(Connection.TAG_CHANGED, tagChanged, false, 0, true);
48           updateTagDataProvider();
49       }
50
51       private function updateTagDataProvider():void {
52           var tag:Tag;
53           var keys:Array = [];
54
55           tagDataProvider.removeAll();
56
57           for each (tag in backgroundEntity.getTagArray() ) {
58               keys.push(tag.key);
59           }
60
61           for each (tag in editableEntity.getTagArray() ) {
62               keys.push(tag.key);
63           }
64
65           keys=keys.filter(function(k:*, i:int, arr:Array):Boolean { return arr.indexOf(k) == i } ); // remove duplicates
66           keys.sort();
67
68           for each (var key:String in keys) {
69               tagDataProvider.addItem({k:key, e:editableEntity.getTag(key), b:backgroundEntity.getTag(key)});
70           }
71           backgroundPanelDG.invalidateList();
72       }
73
74       private function tagChanged(e:Event):void {
75           updateTagDataProvider();
76       }
77
78       public function buttonVisible(b:String, e:String):Boolean {
79           if (b != null && b != e) {
80               return true;
81           }
82           return false;
83       }
84
85       public function mergeForKey(key:String):void {
86           editableEntity.setTag(key, backgroundEntity.getTag(key), MainUndoStack.getGlobalStack().addAction);
87       }
88
89       // Don't call this for things you don't want coloured in. Like for empty tags.
90       public function getColorFor(i:int):int {
91           if (tagDataProvider[i].e == tagDataProvider[i].b) {
92               return 0xDDFFDD; // matching, green
93            } else if (tagDataProvider[i].e == null) {
94               return 0xDDDDFF; // new value, blue
95            } else if (tagDataProvider[i].b) {
96               return 0xFFDDDD; // conflicting, red
97            }
98            return NaN; // which is interpretted as black
99       }
100   ]]>
101   </mx:Script>
102 </mx:VBox>