changeset 910:7f72239e56c8

#259 Use the LoadArtifactService to clone Artifacts and add them to the current Collection. flys-client/trunk@2767 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 15 Sep 2011 16:27:07 +0000
parents 794d1af42987
children 4668357b255e
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java
diffstat 2 files changed, 58 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Sep 15 16:02:23 2011 +0000
+++ b/flys-client/ChangeLog	Thu Sep 15 16:27:07 2011 +0000
@@ -1,3 +1,12 @@
+2011-09-15  Ingo Weinzierl <ingo@intevation.de>
+
+	flys/issue259 (Daten aus Datenkorb in Diagramm einladen)
+
+	* src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java:
+	  Don't abuse the mechanism to load recommendations any longer. Selected
+	  Facets/Artifacts in this Window are cloned and loaded into the current
+	  Collection using the LoadArtifactService.
+
 2011-09-15  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/UIProvider.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Thu Sep 15 16:02:23 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Thu Sep 15 16:27:07 2011 +0000
@@ -1,15 +1,22 @@
 package de.intevation.flys.client.client.ui;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 
+import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Window;
 
+import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYSConstants;
 
 import de.intevation.flys.client.client.event.DatacageHandler;
 
+import de.intevation.flys.client.client.services.LoadArtifactService;
+import de.intevation.flys.client.client.services.LoadArtifactServiceAsync;
+
 import de.intevation.flys.client.shared.model.Artifact;
 import de.intevation.flys.client.shared.model.ArtifactDescription;
+import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.shared.model.Data;
 import de.intevation.flys.client.shared.model.DataItem;
 import de.intevation.flys.client.shared.model.DataList;
@@ -27,6 +34,9 @@
     protected FLYSConstants messages =
         GWT.create(FLYSConstants.class);
 
+    protected LoadArtifactServiceAsync loadService =
+        GWT.create(LoadArtifactService.class);
+
     protected CollectionView view;
 
     public DatacageWindow(
@@ -60,8 +70,7 @@
     public void toLoad(ToLoad toLoad) {
         destroy();
         List<Recommendation> recs = toLoad.toRecommendations();
-        view.loadRecommendedArtifacts(
-            recs.toArray(new Recommendation[recs.size()]));
+        loadArtifacts(recs.toArray(new Recommendation[recs.size()]));
     }
 
 
@@ -86,5 +95,43 @@
 
         return "";
     }
+
+
+    protected void loadArtifacts(Recommendation[] recommendations) {
+        Config cfg = Config.getInstance();
+
+        final Collection collection     = view.getCollection();
+        final Artifact   masterArtifact = view.getArtifact();
+        final String     serverUrl      = cfg.getServerUrl();
+        final String     locale         = cfg.getLocale();
+
+        for (final Recommendation recommendation: recommendations) {
+            // XXX: UGLY! If no reference artifact given use uuid of
+            //      current artifact as reference.
+            if (recommendation.getMasterArtifact() == null) {
+                recommendation.setMasterArtifact(masterArtifact.getUuid());
+            }
+
+            final String factory = recommendation.getFactory();
+
+            GWT.log("Load new artifact with factory: " + factory);
+
+            loadService.load(
+                collection,
+                recommendation,
+                factory,
+                serverUrl,
+                locale,
+                new AsyncCallback<Artifact>() {
+                    public void onFailure(Throwable caught) {
+                        SC.warn(caught.getMessage());
+                    }
+
+                    public void onSuccess(Artifact artifact) {
+                        GWT.log("Created new artifact: " + artifact.getUuid());
+                    }
+            });
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org