Add more guidance.
[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
8     xmlns:fx="http://ns.adobe.com/mxml/2009"
9     xmlns:mx="library://ns.adobe.com/flex/mx"
10     xmlns:s="library://ns.adobe.com/flex/spark"
11     height="100%">
12   <s:RichText id="backgroundMergePanelText" width="100%">Review and Merge tags from the Background layer</s:RichText>
13   <mx:DataGrid editable="false" id="backgroundPanelDG" width="100%" height="50%">
14     <mx:columns>
15       <mx:DataGridColumn editable="false" dataField="k" headerText="Key" />
16       <mx:DataGridColumn editable="false" dataField="e" headerText="OSM value" />
17       <mx:DataGridColumn editable="false" headerText="Merge" width="150" textAlign="center">
18         <mx:itemRenderer>
19           <fx:Component>
20             <mx:HBox horizontalAlign="center" verticalAlign="middle" width="100%">
21               <s:Button width="50" label="&lt;&lt;" visible="{parentDocument.buttonVisible(data.b, data.e)}" click="parentDocument.mergeForKey(data.k);" />
22             </mx:HBox>
23           </fx:Component>
24         </mx:itemRenderer>
25       </mx:DataGridColumn>
26       <mx:DataGridColumn editable="false" itemRenderer="net.systemeD.potlatch2.panels.BackgroundMergeFieldComponent" dataField="b" headerText="Background value" />
27     </mx:columns>
28   </mx:DataGrid>
29   <mx:ViewStack id="statusStack" resizeToContent="true" width="100%">
30     <mx:VBox id="empty" />
31     <mx:VBox id="not_complete">
32       <s:VGroup width="100%">
33         <s:RichText width="100%">If all the information from this feature is accounted for in the main layer, you can mark this feature as 'complete'.</s:RichText>
34         <s:RichText width="100%">This lets other contributors see what still needs reconciling.</s:RichText>
35         <s:Button label="Mark feature as Complete" click="markComplete()"/>
36       </s:VGroup>
37     </mx:VBox>
38     <mx:VBox id="complete" width="100%">
39       <s:VGroup width="100%">
40         <s:RichText width="100%">This feature has been marked as 'complete'. If this is incorrect, and there is still reconciling required, you can mark this feature as 'not complete'.</s:RichText>
41         <s:Button label="Mark feature as Not complete" click="markNotComplete()"/>
42       </s:VGroup>
43     </mx:VBox>
44   </mx:ViewStack>
45   <fx:Script><![CDATA[
46
47       import net.systemeD.halcyon.connection.*;
48       import net.systemeD.halcyon.MapPaint;
49       import net.systemeD.potlatch2.utils.SnapshotConnection;
50
51       import mx.collections.*;
52
53       private var editableEntity:Entity;
54       private var backgroundEntity:Entity;
55       private var tagDataProvider:ArrayCollection;
56
57       public function init(entities:Array):void {
58           if ( tagDataProvider == null ) {
59               tagDataProvider = new ArrayCollection();
60               backgroundPanelDG.dataProvider = tagDataProvider;
61           }
62
63           if (parentDocument.controller.map.getLayerForEntity(entities[0]).isBackground) {
64               backgroundEntity = entities[0];
65               editableEntity = entities[1];
66           } else {
67               backgroundEntity = entities[1];
68               editableEntity = entities[0];
69           }
70           backgroundEntity.addEventListener(Connection.STATUS_CHANGED, statusEvent, false, 0, true);
71           setStatusStack();
72           editableEntity.addEventListener(Connection.TAG_CHANGED, tagChanged, false, 0, true);
73           updateTagDataProvider();
74       }
75
76       private function updateTagDataProvider():void {
77           var tag:Tag;
78           var keys:Array = [];
79
80           tagDataProvider.removeAll();
81
82           for each (tag in backgroundEntity.getTagArray() ) {
83               keys.push(tag.key);
84           }
85
86           for each (tag in editableEntity.getTagArray() ) {
87               keys.push(tag.key);
88           }
89
90           keys=keys.filter(function(k:*, i:int, arr:Array):Boolean { return arr.indexOf(k) == i } ); // remove duplicates
91           keys.sort();
92
93           for each (var key:String in keys) {
94               tagDataProvider.addItem({k:key, e:editableEntity.getTag(key), b:backgroundEntity.getTag(key)});
95           }
96           backgroundPanelDG.invalidateList();
97       }
98
99       private function tagChanged(e:Event):void {
100           updateTagDataProvider();
101       }
102
103       public function buttonVisible(b:String, e:String):Boolean {
104           if (b != null && b != e) {
105               return true;
106           }
107           return false;
108       }
109
110       public function mergeForKey(key:String):void {
111           editableEntity.setTag(key, backgroundEntity.getTag(key), MainUndoStack.getGlobalStack().addAction);
112       }
113
114       // Don't call this for things you don't want coloured in. Like for empty tags.
115       public function getColorFor(i:int):int {
116           if (tagDataProvider[i].e == tagDataProvider[i].b) {
117               return 0xDDFFDD; // matching, green
118            } else if (tagDataProvider[i].e == null) {
119               return 0xDDDDFF; // new value, blue
120            } else if (tagDataProvider[i].b) {
121               return 0xFFDDDD; // conflicting, red
122            }
123            return NaN; // which is interpretted as black
124       }
125
126       private function statusEvent(e:Event):void {
127             setStatusStack();
128       }
129
130       private function setStatusStack():void {
131           switch (backgroundEntity.status) {
132               case 'incomplete':
133                   statusStack.selectedChild = not_complete;
134                   break;
135               case 'complete':
136                   statusStack.selectedChild = complete;
137                   break;
138               default:
139                   statusStack.selectedChild = empty;
140           }
141       }
142
143       private function markComplete():void {
144           if (backgroundEntity.connection is SnapshotConnection) {
145               SnapshotConnection(backgroundEntity.connection).markComplete(backgroundEntity);
146           }
147       }
148
149       private function markNotComplete():void {
150           if (backgroundEntity.connection is SnapshotConnection) {
151               SnapshotConnection(backgroundEntity.connection).markNotComplete(backgroundEntity);
152           }
153       }
154   ]]>
155   </fx:Script>
156 </mx:VBox>