First stab at merge button, albeit the visibility stuff doesn't work
[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">
14         <mx:itemRenderer>
15           <mx:Component>
16             <mx:Button label="++" visible="{data.b == null}" click="trace('b is '+data.b);parentDocument.mergeForKey(data.k);" />
17           </mx:Component>
18         </mx:itemRenderer>
19       </mx:DataGridColumn>
20       <mx:DataGridColumn editable="false" dataField="b" headerText="Background value" />
21     </mx:columns>
22   </mx:DataGrid>
23   <mx:Script><![CDATA[
24
25       import net.systemeD.halcyon.connection.*;
26       import mx.collections.*;
27
28       private var editableEntity:Entity;
29       private var backgroundEntity:Entity;
30       private var tagDataProvider:ArrayCollection;
31
32       public function init(entities:Array):void {
33           if ( tagDataProvider == null ) {
34               tagDataProvider = new ArrayCollection();
35               backgroundPanelDG.dataProvider = tagDataProvider;
36           }
37
38           if (parentDocument.controller.map.getLayerForEntity(entities[0]).isBackground) {
39               backgroundEntity = entities[0];
40               editableEntity = entities[1];
41           } else {
42               backgroundEntity = entities[1];
43               editableEntity = entities[0];
44           }
45           updateTagDataProvider();
46       }
47
48       private function updateTagDataProvider():void {
49           var tag:Tag;
50           var keys:Array = [];
51
52           tagDataProvider.removeAll();
53
54           for each (tag in backgroundEntity.getTagArray() ) {
55               keys.push(tag.key);
56           }
57
58           for each (tag in editableEntity.getTagArray() ) {
59               keys.push(tag.key);
60           }
61
62           keys=keys.filter(function(k:*, i:int, arr:Array):Boolean { return arr.indexOf(k) == i } ); // remove duplicates
63           keys.sort();
64
65           for each (var key:String in keys) {
66               tagDataProvider.addItem({k:key, e:editableEntity.getTag(key), b:backgroundEntity.getTag(key)});
67           }
68       }
69
70       public function mergeForKey(key:String):void {
71           trace("merge for " + key);
72       }
73   ]]>
74   </mx:Script>
75 </mx:VBox>