[PATCH 2 of 3] Changed twin dc panel in bed height deifferences to single dc and use the new differences dc macro

Wald Commits scm-commit at wald.intevation.org
Thu Jun 26 15:00:33 CEST 2014


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1403787568 -7200
# Node ID 93da474506e7d9636f175ac448dfb7a0b01be63c
# Parent  d66ea32d98bc9e0c103d436d068d1324aae51d91
Changed twin dc panel in bed height deifferences to single dc and use the new differences dc macro.

diff -r d66ea32d98bc -r 93da474506e7 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageWidget.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageWidget.java	Thu Jun 26 14:54:04 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageWidget.java	Thu Jun 26 14:59:28 2014 +0200
@@ -292,6 +292,20 @@
     }
 
 
+    public List<TreeNode> getPlainSelection() {
+        ListGridRecord [] selection = treeGrid.getSelectedRecords();
+        List<TreeNode> nodes = new ArrayList<TreeNode>();
+        if (selection != null) {
+            for (ListGridRecord record: selection) {
+                if (record instanceof TreeNode) {
+                    nodes.add((TreeNode)record);
+                }
+            }
+        }
+        return nodes;
+    }
+
+
     /**
      * Returns the titles of selected items (if any).
      */
diff -r d66ea32d98bc -r 93da474506e7 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/BedHeightsDatacagePanel.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/BedHeightsDatacagePanel.java	Thu Jun 26 14:54:04 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/BedHeightsDatacagePanel.java	Thu Jun 26 14:59:28 2014 +0200
@@ -14,14 +14,17 @@
 
 import com.smartgwt.client.data.Record;
 
+import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.Button;
 import com.smartgwt.client.widgets.Canvas;
 
 import com.smartgwt.client.widgets.events.ClickEvent;
-
+import com.smartgwt.client.widgets.events.ClickHandler;
 import com.smartgwt.client.widgets.grid.ListGridRecord;
 
 import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
+import com.smartgwt.client.widgets.tree.TreeNode;
 
 import org.dive4elements.river.client.client.Config;
 import org.dive4elements.river.client.client.FLYSConstants;
@@ -35,6 +38,7 @@
 
 import org.dive4elements.river.client.client.ui.DatacagePairWidget;
 import org.dive4elements.river.client.client.ui.DatacageTwinPanel;
+import org.dive4elements.river.client.client.ui.DatacageWidget;
 import org.dive4elements.river.client.client.ui.RecommendationPairRecord;
 
 import org.dive4elements.river.client.shared.model.Artifact;
@@ -42,6 +46,7 @@
 import org.dive4elements.river.client.shared.model.Data;
 import org.dive4elements.river.client.shared.model.DataItem;
 import org.dive4elements.river.client.shared.model.DataList;
+import org.dive4elements.river.client.shared.model.ToLoad;
 
 import org.dive4elements.river.client.shared.model.Recommendation.Facet;
 import org.dive4elements.river.client.shared.model.Recommendation.Filter;
@@ -80,6 +85,7 @@
     RemoveArtifactServiceAsync removeArtifactService = GWT.create(
             org.dive4elements.river.client.client.services.RemoveArtifactService.class);
 
+    protected DatacageWidget datacage;
 
     public BedHeightsDatacagePanel(User user) {
         super(user);
@@ -120,14 +126,25 @@
     public Canvas create(DataList dataList) {
         GWT.log("createData()");
 
-        String filter = "minfo-heights";
+        String filter = "minfo-heights-diff";
         Canvas widget = createWidget();
         Canvas submit = getNextButton();
+        datacage = new DatacageWidget(
+            this.artifact, user, filter, "load-system:true", false);
+
+        Button plusBtn = new Button(MSG.datacage_add_pair());
+        plusBtn.setAutoFit(true);
+        plusBtn.addClickHandler(new ClickHandler() {
+            @Override
+            public void onClick(ClickEvent event) {
+                plusClicked();
+            }
+        });
 
         VLayout layout       = new VLayout();
-        HLayout helperLayout = new HLayout();
-        helperLayout.addMember(new DatacagePairWidget(this.artifact,
-            user, filter, differencesList));
+        VLayout helperLayout = new VLayout();
+        helperLayout.addMember(datacage);
+        helperLayout.addMember(plusBtn);
 
         layout.addMember(widget);
         layout.addMember(submit);
@@ -306,5 +323,53 @@
                 + recommendation.getDisplayName() + "]";
         }
     }
+
+    /**
+     * Callback for add-button.
+     * Fires to load for every selected element and handler.
+     */
+    public void plusClicked() {
+        List<TreeNode> selection = datacage.getPlainSelection();
+
+        if (selection == null || selection.isEmpty()) {
+            SC.say(MSG.warning());
+            return;
+        }
+
+        for (TreeNode node : selection) {
+            ToLoad toLoad1 = new ToLoad();
+            ToLoad toLoad2 = new ToLoad();
+
+            String factory = node.getAttribute("factory");
+            if (factory != null) { // we need at least a factory
+                String artifact    = node.getAttribute("artifact-id");
+                String out         = node.getAttribute("out");
+                String name        = node.getAttribute("facet");
+                String ids         = node.getAttribute("ids");
+                String info        = node.getAttribute("info");
+                String targetOut   = node.getAttribute("target_out");
+
+                String[] splitIds = ids.split("#");
+                String[] splitInfo = info.split("#");
+                toLoad1.add(artifact,
+                     factory,
+                     out,
+                     name,
+                     splitIds[0],
+                     splitInfo[0],
+                     targetOut);
+                toLoad2.add(artifact,
+                     factory,
+                     out,
+                     name,
+                     splitIds[1],
+                     splitInfo[1],
+                     targetOut);
+            }
+            differencesList.addData(new RecommendationPairRecord(
+                toLoad1.toRecommendations().get(0),
+                toLoad2.toRecommendations().get(0)));
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4Elements-commits mailing list