changeset 7570:f4c13fbde072

issue1020: Let WspDatacagePanel also handle non-winfo (prev. calc) rec.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 14 Nov 2013 11:54:02 +0100
parents 3cbf8bab1a0f
children f89ad512f426
files gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WspDatacagePanel.java
diffstat 1 files changed, 27 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WspDatacagePanel.java	Thu Nov 14 06:44:11 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WspDatacagePanel.java	Thu Nov 14 11:54:02 2013 +0100
@@ -87,7 +87,7 @@
     public void onClick(ClickEvent e) {
         List<String> errors = validate();
         if (errors == null || errors.isEmpty()) {
-            // 1) Fetch selected recommendation
+            // 1) Fetch selected recommendation.
             Config config           = Config.getInstance();
             final  String locale    = config.getLocale();
             final  Collection c     = this.collection;
@@ -99,9 +99,10 @@
                 return;
             }
 
-            // 2) Create, load Artifact and fire event
+            // TODO: This could eventually be handled server-side.
+            // 2) Create, load Artifact and fire event.
             loadService.load(
-                c, r, "winfo", locale,
+                c, r, r.getFactory(), locale,
                 new AsyncCallback<Artifact>() {
                     @Override
                     public void onFailure(Throwable caught) {
@@ -110,9 +111,10 @@
                     }
 
                     @Override
-                    public void onSuccess(Artifact artifact) {
+                    public void onSuccess(Artifact newArtifact) {
+                        GWT.log("Created new artifact.");
                         fireStepForwardEvent(new StepForwardEvent(
-                            getData(r, artifact)));
+                            getData(r, newArtifact)));
                     }
                 }
             );
@@ -149,7 +151,7 @@
         String uuid = newArtifact.getUuid();
         r.setMasterArtifact(uuid);
 
-        String value = createDataString(uuid, r.getFilter());
+        String value = createDataString(uuid, r);
 
         DataItem item = new DefaultDataItem(dataName, dataName, value);
         return new Data[] { new DefaultData(
@@ -157,22 +159,30 @@
     }
 
 
-    protected String createDataString(String artifact, Filter filter) {
+    protected String createDataString(String artifact, Recommendation recommendation) {
         Facet f = null;
-
-        Map<String, List<Facet>>               outs = filter.getOuts();
-        Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet();
+        
+        // The filter will only be available or previous calculation artifacts.
+        Filter filter = recommendation.getFilter();
 
-        for (Map.Entry<String, List<Facet>> entry: entries) {
-            List<Facet> fs = entry.getValue();
+        if (filter != null) {
+            Map<String, List<Facet>>               outs = filter.getOuts();
+            Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet();
 
-            f = fs.get(0);
-            if (f != null) {
-                break;
+            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() + "]";
         }
-
-        return "[" + artifact + ";" + f.getName() + ";" + f.getIndex() + "]";
+        else {
+            return "[" + artifact + ";" + recommendation.getFactory() + ";" + 0 + "]";
+        }
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org