changeset 914:39a39e9be5af

Made DatacageTwinPanel somewhat usable. flys-client/trunk@2775 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 16 Sep 2011 11:21:38 +0000
parents 9976d99aea34
children 89a47098bcbd
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePairWidget.java flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java
diffstat 3 files changed, 192 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Sep 16 11:09:39 2011 +0000
+++ b/flys-client/ChangeLog	Fri Sep 16 11:21:38 2011 +0000
@@ -1,3 +1,14 @@
+2011-09-16	Felix Wolfsteller	<felix.wolfsteller@intevation.de> 
+
+  Updated implementation to a working (but limited and buggy)
+    DatacageTwinPanel.
+
+	* src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java,
+	  src/main/java/de/intevation/flys/client/client/ui/DatacagePairWidget.java:
+	  Eat recommendations and add them to list, on "proceed"-click, clone
+	  selected artifacts and add them to selection, collapse list entries
+	  to string and add that string as data.
+
 2011-09-16	Felix Wolfsteller	<felix.wolfsteller@intevation.de> 
 
   Added a loadMany-Function to LoadArtifactService.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePairWidget.java	Fri Sep 16 11:09:39 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePairWidget.java	Fri Sep 16 11:21:38 2011 +0000
@@ -41,11 +41,16 @@
 import de.intevation.flys.client.shared.model.DataCageTree;
 import de.intevation.flys.client.shared.model.DataCageNode;
 import de.intevation.flys.client.shared.model.AttrList;
+import de.intevation.flys.client.shared.model.Recommendation;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Stack;
 
+/**
+ * Widget showing two Datacages and a plus-button.
+ * Insert a record into a listgrid when plus-button clicked.
+ */
 public class DatacagePairWidget
 extends      VLayout
 {
@@ -71,24 +76,32 @@
     /**
      * Two strings to be displayed in a GridList.
      */
-    protected class StringPairRecord extends ListGridRecord {
-        public StringPairRecord() {
+    protected class RecommendationPairRecord extends ListGridRecord {
+        Recommendation first;
+        Recommendation second;
+
+        public RecommendationPairRecord() {
         }
 
-        public StringPairRecord(String first, String second) {
+        public RecommendationPairRecord(Recommendation first, Recommendation second) {
             setFirst(first);
             setSecond(second);
         }
 
 
-        public void setFirst(String first) {
-            setAttribute(ATTRIBUTE_FIRST, first);
+        public void setFirst(Recommendation first) {
+            this.first = first;
+            setAttribute(ATTRIBUTE_FIRST, first.getFactory() + first.getIDs());
         }
 
 
-        public void setSecond(String second) {
-            setAttribute(ATTRIBUTE_SECOND, second);
+        public void setSecond(Recommendation second) {
+            this.second = second;
+            setAttribute(ATTRIBUTE_SECOND, second.getFactory() + second.getIDs());
         }
+
+        public Recommendation getFirst() {return first;}
+        public Recommendation getSecond() {return second;}
     }
 
 
@@ -132,11 +145,14 @@
         ToLoad toLoad1 = firstDatacageWidget.getSelection();
         ToLoad toLoad2 = secondDatacageWidget.getSelection();
 
+        // TODO further sanitize (toRecommendations.length)
         if (toLoad1 == null || toLoad2 == null) {
             return;
         }
 
-        //grid.addData(new StringPairRecord((String)toLoad1.getKeys().toArray()[0], (String)toLoad2.getKeys().toArray()[0]));
+        grid.addData(new RecommendationPairRecord(
+            toLoad1.toRecommendations().get(0),
+            toLoad2.toRecommendations().get(0)));
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java	Fri Sep 16 11:09:39 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java	Fri Sep 16 11:21:38 2011 +0000
@@ -1,12 +1,23 @@
 package de.intevation.flys.client.client.ui;
 
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+import java.util.Set;
+
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
+import com.smartgwt.client.widgets.grid.ListGrid;
+import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.widgets.events.ClickEvent;
 
+import de.intevation.flys.client.shared.model.Artifact;
 import de.intevation.flys.client.shared.model.Data;
 import de.intevation.flys.client.shared.model.DataItem;
 import de.intevation.flys.client.shared.model.DefaultData;
@@ -15,9 +26,25 @@
 import de.intevation.flys.client.shared.model.User;
 
 import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.client.event.DatacageHandler;
+import de.intevation.flys.client.client.event.StepForwardEvent;
+import de.intevation.flys.client.shared.model.Recommendation;
+import de.intevation.flys.client.shared.model.ToLoad;
+import de.intevation.flys.client.shared.model.Recommendation.Facet;
+import de.intevation.flys.client.shared.model.Recommendation.Filter;
+
+import de.intevation.flys.client.client.services.LoadArtifactService;
+import de.intevation.flys.client.client.services.LoadArtifactServiceAsync;
+import de.intevation.flys.client.client.Config;
 
 // TODO Probably better to branch off AbstractUIProvider.
-public class DatacageTwinPanel extends TextProvider {
+// TODO Merge with other datacage-widget impls.
+/**
+ * Panel containing a Grid and a "next" button. The Grid is fed by a
+ * DatacagePairWidget which is put in the input-helper area.
+ */
+public class DatacageTwinPanel
+extends      TextProvider {
 
     protected static FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
@@ -25,6 +52,15 @@
 
     protected User user;
 
+    protected ToLoad toLoad1;
+
+    protected ToLoad toLoad2;
+
+    protected ListGrid differencesList;
+
+    LoadArtifactServiceAsync loadArtifactService = GWT.create(
+            de.intevation.flys.client.client.services.LoadArtifactService.class);
+
 
     public DatacageTwinPanel(User user) {
         super();
@@ -43,48 +79,139 @@
         Canvas submit = getNextButton();
 
         VLayout layout = new VLayout();
+        HLayout helperLayout = new HLayout();
         label.setHeight(50);
-        DatacageWidget baseDataCage = new DatacageWidget(this.artifact, user);
-        DatacageWidget modDataCage = new DatacageWidget(this.artifact, user);
-        baseDataCage.setHeight(250);
-        modDataCage.setHeight(250);
-        layout.addMember(baseDataCage);
-        layout.addMember(modDataCage);
+        helperLayout.addMember(new DatacagePairWidget(this.artifact,
+            user, "longitudinal_section", differencesList));
 
         /*layout.addMember(label);*/
         layout.addMember(widget);
         layout.addMember(submit);
         layout.setMembersMargin(10);
-        this.helperContainer.addMember(layout);
-
-//        return layout;
-        return new VLayout();
-    }
-
-
-    public Canvas createWidget() {
-        HLayout layout = new HLayout();
-        layout.setMembersMargin(10);
-
-        layout.addMember(createForm());
-        layout.addMember(new DatacageWidget());
-        // TODO: fetch current user!
-        // TODO: fetch collection view!
-        /*layout.addMember(
-            new DatacageButton(
-                MSG.databasket(), artifact, null, null));
-                */
+        this.helperContainer.addMember(helperLayout);
 
         return layout;
     }
 
 
     @Override
+    public List<String> validate() {
+        List<String> errors = new ArrayList<String>();
+        if (differencesList.getRecords().length == 0) {
+            // TODO i18n of error message. (MSG.no_waterlevel_pair_selected())
+            errors.add("No pair of waterlevel items selected");
+        }
+
+        return errors;
+    }
+
+
+    public Canvas createWidget() {
+        VLayout layout = new VLayout();
+
+        differencesList = new ListGrid();  
+        differencesList.setHeight(150);  
+        differencesList.setShowAllRecords(true);  
+        differencesList.setCanEdit(false);  
+
+        ListGridField nameField = new ListGridField("first", "Minuend");  
+        ListGridField capitalField = new ListGridField("second", "Subtrahend");  
+        differencesList.setFields(new ListGridField[] {nameField, capitalField});  
+
+        layout.addMember(differencesList);
+
+        return layout;
+    }
+
+
+    @Override
+    public void onClick(ClickEvent e) {
+        /*
+        TODO: Validation/Error
+        List<String> errors = validate();
+        if (errors == null || errors.isEmpty()) {
+        ...
+        else {showErrors(errors);}
+
+         * */
+        GWT.log("DatacageTwinPanel.onClick");
+        Config config = Config.getInstance();
+        ListGridRecord[] records = differencesList.getRecords();
+        ArrayList<Recommendation> ar = new ArrayList<Recommendation>();
+        for (ListGridRecord record : records) {
+            DatacagePairWidget.RecommendationPairRecord r =
+                (DatacagePairWidget.RecommendationPairRecord) record;
+            ar.add(r.getFirst());
+            ar.add(r.getSecond());
+        }
+        final Recommendation[] rs = ar.toArray(new Recommendation[ar.size()]);
+        loadArtifactService.loadMany(
+              this.collection,
+              rs,
+              "winfo",
+              config.getServerUrl(),
+              config.getLocale(),
+              new AsyncCallback<Artifact[]>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("No success in cloning Thing!");
+                }
+                public void onSuccess(Artifact[] artifacts) {
+                    GWT.log("Success of cloning thing!");
+                        fireStepForwardEvent(new StepForwardEvent(
+                            getData(rs, artifacts)));
+                } }
+                );
+    }
+
+
+    protected Data[] getData(Recommendation[] rs, Artifact[] newArtifacts) {
+        // Construct string with info about selections.
+        String dataItemString = "";
+        for (int i = 0; i < rs.length; i++) {
+            Recommendation r = rs[i];
+            Artifact newArtifact = newArtifacts[i];
+            String uuid = newArtifact.getUuid();
+            r.setMasterArtifact(uuid);
+            if (i>0) dataItemString += "#";
+    
+            dataItemString += createDataString(uuid, r.getFilter());
+        }
+        DataItem item = new DefaultDataItem(dataName, dataName, dataItemString);
+        return new Data[] { new DefaultData(
+            dataName, null, null, new DataItem[] {item}) };
+    }
+
+
+    protected String createDataString(String artifact, Filter filter) {
+        Facet f = null;
+
+        Map<String, List<Facet>>               outs = filter.getOuts();
+        Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet();
+
+        for (Map.Entry<String, List<Facet>> entry: entries) {
+            List<Facet> fs = entry.getValue();
+
+            f = fs.get(0);
+            if (f != null) {
+                break;
+            }
+        }
+
+        return "[" + artifact + ";" + f.getName() + ";" + f.getIndex() + "]";
+    }
+
+    /*@Override
     protected Data[] getData() {
-        String value  = "TODO:FIND VALUE";
-        DataItem item = new DefaultDataItem(dataName, dataName, value);
+        // TODO ToLoadRecord ! 
+        String value = "TODO:FIND VALUE";
+        if (toLoad1 != null) {
+            List<Recommendation> recommendations = toLoad1.toRecommendations();
+            value = recommendations.get(0).getIDs();
+        }
+        DataItem item1 = new DefaultDataItem(dataName, dataName, value);
+        DataItem item2 = new DefaultDataItem(dataName, dataName, value);
         return new Data[] { new DefaultData(
-            dataName, null, null, new DataItem[] { item }) };
-    }
+            dataName, null, null, new DataItem[] { item1, item2}) };
+    }*/
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org