Figure out which entity is which, and populate the tag grid
[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" dataField="b" headerText="Background value" />
14     </mx:columns>
15   </mx:DataGrid>
16   <mx:Script><![CDATA[
17
18       import net.systemeD.halcyon.connection.*;
19       import mx.collections.*;
20
21       private var editableEntity:Entity;
22       private var backgroundEntity:Entity;
23       private var tagDataProvider:ArrayCollection;
24
25       public function init(entities:Array):void {
26           if ( tagDataProvider == null ) {
27               tagDataProvider = new ArrayCollection();
28               backgroundPanelDG.dataProvider = tagDataProvider;
29           }
30
31           if (parentDocument.controller.map.getLayerForEntity(entities[0]).isBackground) {
32               backgroundEntity = entities[0];
33               editableEntity = entities[1];
34           } else {
35               backgroundEntity = entities[1];
36               editableEntity = entities[0];
37           }
38           updateTagDataProvider();
39       }
40
41       private function updateTagDataProvider():void {
42           var tag:Tag;
43           var keys:Array = [];
44
45           tagDataProvider.removeAll();
46
47           for each (tag in backgroundEntity.getTagArray() ) {
48               keys.push(tag.key);
49           }
50
51           for each (tag in editableEntity.getTagArray() ) {
52               keys.push(tag.key);
53           }
54
55           keys=keys.filter(function(k:*, i:int, arr:Array):Boolean { return arr.indexOf(k) == i } ); // remove duplicates
56           keys.sort();
57
58           for each (var key:String in keys) {
59               tagDataProvider.addItem({k:key, e:editableEntity.getTag(key), b:backgroundEntity.getTag(key)});
60           }
61       }
62   ]]>
63   </mx:Script>
64 </mx:VBox>