diff flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java @ 911:4668357b255e

#259 Refresh charts after loading new Themes / Artifacts from Datacage. flys-client/trunk@2768 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 15 Sep 2011 17:01:12 +0000
parents 7f72239e56c8
children 07aa1f504491
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Thu Sep 15 16:27:07 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java	Thu Sep 15 17:01:12 2011 +0000
@@ -1,5 +1,8 @@
 package de.intevation.flys.client.client.ui;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
@@ -10,6 +13,10 @@
 import de.intevation.flys.client.client.FLYSConstants;
 
 import de.intevation.flys.client.client.event.DatacageHandler;
+import de.intevation.flys.client.client.event.HasRedrawRequestHandlers;
+import de.intevation.flys.client.client.event.RedrawRequestHandler;
+import de.intevation.flys.client.client.event.RedrawRequestEvent;
+import de.intevation.flys.client.client.event.RedrawRequestEvent.Type;
 
 import de.intevation.flys.client.client.services.LoadArtifactService;
 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync;
@@ -24,12 +31,10 @@
 import de.intevation.flys.client.shared.model.User;
 import de.intevation.flys.client.shared.model.Recommendation;
 
-import java.util.List;
-
 
 public class DatacageWindow
 extends      Window
-implements   DatacageHandler
+implements   DatacageHandler, HasRedrawRequestHandlers
 {
     protected FLYSConstants messages =
         GWT.create(FLYSConstants.class);
@@ -39,13 +44,21 @@
 
     protected CollectionView view;
 
+    protected List<RedrawRequestHandler> handlers;
+
+    protected int inProgress;
+
+
     public DatacageWindow(
         Artifact       artifact, 
         User           user,
         String         outs,
         CollectionView view
     ) {
-        this.view = view;
+        this.view       = view;
+        this.handlers   = new ArrayList<RedrawRequestHandler>();
+        this.inProgress = 0;
+
         setWidth(400);
         setHeight(500);
 
@@ -74,6 +87,14 @@
     }
 
 
+    @Override
+    public void addRedrawRequestHandler(RedrawRequestHandler handler) {
+        if (handler != null) {
+            handlers.add(handler);
+        }
+    }
+
+
     protected String findRiver(Artifact artifact) {
         ArtifactDescription adescr = artifact.getArtifactDescription();
         DataList [] data = adescr.getOldData();
@@ -97,6 +118,26 @@
     }
 
 
+    protected void decreateInProgress() {
+        if (this.inProgress > 0) {
+            this.inProgress--;
+        }
+
+        if (this.inProgress == 0) {
+            fireRedrawRequest();
+        }
+    }
+
+
+    protected void fireRedrawRequest() {
+        RedrawRequestEvent evt = new RedrawRequestEvent(Type.DEFAULT);
+
+        for (RedrawRequestHandler handler: handlers) {
+            handler.onRedrawRequest(evt);
+        }
+    }
+
+
     protected void loadArtifacts(Recommendation[] recommendations) {
         Config cfg = Config.getInstance();
 
@@ -105,6 +146,8 @@
         final String     serverUrl      = cfg.getServerUrl();
         final String     locale         = cfg.getLocale();
 
+        this.inProgress = recommendations.length;
+
         for (final Recommendation recommendation: recommendations) {
             // XXX: UGLY! If no reference artifact given use uuid of
             //      current artifact as reference.
@@ -124,10 +167,12 @@
                 locale,
                 new AsyncCallback<Artifact>() {
                     public void onFailure(Throwable caught) {
+                        decreateInProgress();
                         SC.warn(caught.getMessage());
                     }
 
                     public void onSuccess(Artifact artifact) {
+                        decreateInProgress();
                         GWT.log("Created new artifact: " + artifact.getUuid());
                     }
             });

http://dive4elements.wald.intevation.org