Minor reworking of the merge button layout, which also allows the visibility to work...
[potlatch2.git] / net / systemeD / potlatch2 / panels / BackgroundMergePanel.mxml
index a5de13fa2dc38117a906fdba6dee9baa9fed6cfa..9833a5e963dd46935434185a3aa8cf24e3bc271b 100644 (file)
@@ -6,4 +6,89 @@
 
 <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" height="100%">
   <mx:Text id="backgroundMergePanelText" text="W00t!!!" width="100%" styleName="helpInfo" />
+  <mx:DataGrid editable="false" id="backgroundPanelDG" width="100%" height="50%">
+    <mx:columns>
+      <mx:DataGridColumn editable="false" dataField="k" headerText="Key" />
+      <mx:DataGridColumn editable="false" dataField="e" headerText="OSM value" />
+      <mx:DataGridColumn editable="false" headerText="Merge" width="50" textAlign="center">
+        <mx:itemRenderer>
+          <mx:Component>
+            <mx:HBox horizontalAlign="center" verticalAlign="middle">
+              <mx:Button label="&lt;&lt;" visible="{parentDocument.buttonVisible(data.b, data.e)}" click="parentDocument.mergeForKey(data.k);" />
+            </mx:HBox>
+          </mx:Component>
+        </mx:itemRenderer>
+      </mx:DataGridColumn>
+      <mx:DataGridColumn editable="false" itemRenderer="net.systemeD.potlatch2.panels.BackgroundMergeFieldComponent" dataField="b" headerText="Background value" />
+    </mx:columns>
+  </mx:DataGrid>
+  <mx:Script><![CDATA[
+
+      import net.systemeD.halcyon.connection.*;
+      import mx.collections.*;
+
+      private var editableEntity:Entity;
+      private var backgroundEntity:Entity;
+      private var tagDataProvider:ArrayCollection;
+
+      public function init(entities:Array):void {
+          if ( tagDataProvider == null ) {
+              tagDataProvider = new ArrayCollection();
+              backgroundPanelDG.dataProvider = tagDataProvider;
+          }
+
+          if (parentDocument.controller.map.getLayerForEntity(entities[0]).isBackground) {
+              backgroundEntity = entities[0];
+              editableEntity = entities[1];
+          } else {
+              backgroundEntity = entities[1];
+              editableEntity = entities[0];
+          }
+          updateTagDataProvider();
+      }
+
+      private function updateTagDataProvider():void {
+          var tag:Tag;
+          var keys:Array = [];
+
+          tagDataProvider.removeAll();
+
+          for each (tag in backgroundEntity.getTagArray() ) {
+              keys.push(tag.key);
+          }
+
+          for each (tag in editableEntity.getTagArray() ) {
+              keys.push(tag.key);
+          }
+
+          keys=keys.filter(function(k:*, i:int, arr:Array):Boolean { return arr.indexOf(k) == i } ); // remove duplicates
+          keys.sort();
+
+          for each (var key:String in keys) {
+              tagDataProvider.addItem({k:key, e:editableEntity.getTag(key), b:backgroundEntity.getTag(key)});
+          }
+      }
+
+      public function buttonVisible(b:String, e:String):Boolean {
+          if (b != null && b != e) {
+              return true;
+          }
+          return false;
+      }
+
+      public function mergeForKey(key:String):void {
+          trace("merge for " + key);
+      }
+
+      public function getColorFor(i:int):int {
+          if (tagDataProvider[i].e == tagDataProvider[i].b) {
+              return 0xDDFFDD; // matching, green
+           } else if (tagDataProvider[i].e == null) {
+              return 0xDDDDFF; // new value, blue
+           } else {
+              return 0xFFDDDD; // conflicting, red
+           }
+      }
+  ]]>
+  </mx:Script>
 </mx:VBox>
\ No newline at end of file