Minor reworking of the merge button layout, which also allows the visibility to 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" 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           updateTagDataProvider();
48       }
49
50       private function updateTagDataProvider():void {
51           var tag:Tag;
52           var keys:Array = [];
53
54           tagDataProvider.removeAll();
55
56           for each (tag in backgroundEntity.getTagArray() ) {
57               keys.push(tag.key);
58           }
59
60           for each (tag in editableEntity.getTagArray() ) {
61               keys.push(tag.key);
62           }
63
64           keys=keys.filter(function(k:*, i:int, arr:Array):Boolean { return arr.indexOf(k) == i } ); // remove duplicates
65           keys.sort();
66
67           for each (var key:String in keys) {
68               tagDataProvider.addItem({k:key, e:editableEntity.getTag(key), b:backgroundEntity.getTag(key)});
69           }
70       }
71
72       public function buttonVisible(b:String, e:String):Boolean {
73           if (b != null && b != e) {
74               return true;
75           }
76           return false;
77       }
78
79       public function mergeForKey(key:String):void {
80           trace("merge for " + key);
81       }
82
83       public function getColorFor(i:int):int {
84           if (tagDataProvider[i].e == tagDataProvider[i].b) {
85               return 0xDDFFDD; // matching, green
86            } else if (tagDataProvider[i].e == null) {
87               return 0xDDDDFF; // new value, blue
88            } else {
89               return 0xFFDDDD; // conflicting, red
90            }
91       }
92   ]]>
93   </mx:Script>
94 </mx:VBox>