changeset 1304:18b0414bde44

Allow reparameterization of W-Diffs. flys-client/trunk@2938 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 11 Oct 2011 11:59:57 +0000
parents 84c50f1d939b
children 014fc183c640
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/RecommendationPairRecord.java
diffstat 3 files changed, 76 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Oct 11 11:50:58 2011 +0000
+++ b/flys-client/ChangeLog	Tue Oct 11 11:59:57 2011 +0000
@@ -1,3 +1,15 @@
+2011-10-11  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Enable reparameterization of WINFO-Artifacts in WDiff-branch. Do not
+	reclone in parameterization.
+
+	* src/main/java/de/intevation/flys/client/client/ui/RecommendationPairRecord.java:
+	  Add flag to remember whether already cloned.
+
+	* src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java:
+	  Recreate already cloned pairs of Ws from datastring, do not reclone
+	  these.
+
 2011-10-11  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java: Added
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java	Tue Oct 11 11:50:58 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java	Tue Oct 11 11:59:57 2011 +0000
@@ -130,6 +130,9 @@
             Recommendation subtrahend = createRecommendationFromString(recs[i+1]);
             RecommendationPairRecord pr = new RecommendationPairRecord(
                "A", minuend, "B", subtrahend);
+            // This Recommendation Pair comes from the data string and was thus
+            // already cloned.
+            pr.setIsAlreadyLoaded(true);
             this.differencesList.addData(pr);
         }
     }
@@ -227,18 +230,29 @@
         Config config = Config.getInstance();
         ListGridRecord[] records = differencesList.getRecords();
 
-        Set<Recommendation> ar = new HashSet<Recommendation>();
+        Set<Recommendation> ar  = new HashSet<Recommendation>();
+        Set<Recommendation> all = new HashSet<Recommendation>();
         for (ListGridRecord record : records) {
             RecommendationPairRecord r =
                 (RecommendationPairRecord) record;
-            ar.add(r.getFirst());
-            ar.add(r.getSecond());
+            // Do not add "old" recommendations.
+            if (!r.isAlreadyLoaded()) {
+                GWT.log("One not yet loaded.");
+                ar.add(r.getFirst());
+                ar.add(r.getSecond());
+            }
+            else {
+                GWT.log("One already loaded.");
+                all.add(r.getFirst());
+                all.add(r.getSecond());
+            }
         }
 
-        final Recommendation[] rs = ar.toArray(new Recommendation[ar.size()]);
+        final Recommendation[] toClone = ar.toArray(new Recommendation[ar.size()]);
+        final Recommendation[] toUse   = all.toArray(new Recommendation[all.size()]);
         loadArtifactService.loadMany(
               this.collection,
-              rs,
+              toClone,
               "waterlevel",
               config.getServerUrl(),
               config.getLocale(),
@@ -247,20 +261,24 @@
                     GWT.log("Failure of cloning with waterlevelfactory!");
                 }
                 public void onSuccess(Artifact[] artifacts) {
-                    GWT.log("Success in cloning with watelevelfactory!");
+                    GWT.log("Success in cloning ("+toClone.length+") with watelevelfactory!");
 
                     fireStepForwardEvent(new StepForwardEvent(
-                        getData(rs, artifacts)));
+                        getData(toClone, artifacts, toUse)));
                 }
               } );
     }
 
 
-    protected Data[] getData(Recommendation[] rs, Artifact[] newArtifacts) {
+    protected Data[] getData(
+            Recommendation[] newRecommendations,
+            Artifact[] newArtifacts,
+            Recommendation[] oldRecommendations)
+    {
         // Construct string with info about selections.
         String dataItemString = "";
-        for (int i = 0; i < rs.length; i++) {
-            Recommendation r = rs[i];
+        for (int i = 0; i < newRecommendations.length; i++) {
+            Recommendation r = newRecommendations[i];
             Artifact newArtifact = newArtifacts[i];
             String uuid = newArtifact.getUuid();
             r.setMasterArtifact(uuid);
@@ -268,6 +286,15 @@
     
             dataItemString += createDataString(uuid, r.getFilter());
         }
+
+        for (int i = 0; i < oldRecommendations.length; i++) {
+            Recommendation r = oldRecommendations[i];
+            String uuid = r.getIDs();
+            if (dataItemString.length() > 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}) };
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/RecommendationPairRecord.java	Tue Oct 11 11:50:58 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/RecommendationPairRecord.java	Tue Oct 11 11:59:57 2011 +0000
@@ -28,6 +28,12 @@
     /** Human-readable short information about the "second" recommendation. */
     String secondName;
 
+    /**
+     * Whether the RecommendationPairRecord was restored from data and thus
+     * already loaded (usually cloned) in an ArtifactCollection or not.
+     */
+    boolean alreadyLoaded;
+
 
     public RecommendationPairRecord() {
     }
@@ -49,6 +55,7 @@
     {
         setFirst(first, firstName);
         setSecond(second, secondName);
+        alreadyLoaded = false;
     }
 
 
@@ -106,4 +113,24 @@
     public String getSecondName() {
         return secondName;
     }
+
+
+    /**
+     * Sets whether or not the Recommendation is already loaded (in contrast
+     * to not yet loaded).
+     * @param isAlreadyLoaded new value.
+     */
+    public void setIsAlreadyLoaded(boolean isAlreadyLoaded) {
+        this.alreadyLoaded = isAlreadyLoaded;
+    }
+
+
+    /**
+     * Whether or not this pair of recommendations is already laoded (usually
+     * cloned) in an ArtifactCollection.
+     * @return whether pair of recommendations is already loaded.
+     */
+    public boolean isAlreadyLoaded() {
+        return this.alreadyLoaded;
+    }
 }

http://dive4elements.wald.intevation.org