changeset 865:43f520f923a8

Remove the loading panel when its Artifact's background process is finished. flys-client/trunk@2672 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 08 Sep 2011 07:44:05 +0000
parents c0e13cf826d7
children 593e6c49c6ee
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/services/DescribeArtifactService.java flys-client/src/main/java/de/intevation/flys/client/client/services/DescribeArtifactServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/LoadingPanel.java flys-client/src/main/java/de/intevation/flys/client/server/DescribeArtifactServiceImpl.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 6 files changed, 182 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Sep 08 06:56:17 2011 +0000
+++ b/flys-client/ChangeLog	Thu Sep 08 07:44:05 2011 +0000
@@ -1,3 +1,18 @@
+2011-09-08  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/services/DescribeArtifactServiceAsync.java,
+	  src/main/java/de/intevation/flys/client/client/services/DescribeArtifactService.java,
+	  src/main/java/de/intevation/flys/client/server/DescribeArtifactServiceImpl.java:
+	  New. The task of this service is to fetch the current DESCRIBE document
+	  of a specific Artifact (currently used in the LoadingPanel to determine
+	  the background processing's state).
+
+	* src/main/java/de/intevation/flys/client/client/ui/LoadingPanel.java: The
+	  loading panel is finished when its Artifact has no longer a processing
+	  background task.
+
+	* src/main/webapp/WEB-INF/web.xml: Registered the DescribeArtifactService.
+
 2011-09-08	Felix Wolfsteller	<felix.wolfsteller@intevation.de> 
 
 	Cosmetics.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/DescribeArtifactService.java	Thu Sep 08 07:44:05 2011 +0000
@@ -0,0 +1,32 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.RemoteService;
+import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+
+import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.shared.model.Artifact;
+
+/**
+ * This interface provides artifact specific operation DESCRIBE.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+@RemoteServiceRelativePath("describe")
+public interface DescribeArtifactService extends RemoteService {
+
+    /**
+     * This method inserts new data into the an existing artifact.
+     *
+     * @param url The url of the artifact server.
+     * @param locale The locale used for the request.
+     * @param artifact The artifact.
+     *
+     * @return the artifact which description might have been changed.
+     */
+    public Artifact describe(
+        String   url,
+        String   locale,
+        Artifact artifact)
+    throws ServerException;
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/DescribeArtifactServiceAsync.java	Thu Sep 08 07:44:05 2011 +0000
@@ -0,0 +1,21 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import de.intevation.flys.client.shared.model.Artifact;
+
+
+/**
+ * This interface provides artifact specific operation DESCRIBE.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface DescribeArtifactServiceAsync {
+
+    public void describe(
+        String                  url,
+        String                  locale,
+        Artifact                artifact,
+        AsyncCallback<Artifact> callback);
+}
+// 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/LoadingPanel.java	Thu Sep 08 06:56:17 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LoadingPanel.java	Thu Sep 08 07:44:05 2011 +0000
@@ -2,21 +2,27 @@
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.Timer;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.types.Alignment;
 import com.smartgwt.client.types.Positioning;
-import com.smartgwt.client.types.VerticalAlignment;
 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 de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.client.services.DescribeArtifactService;
+import de.intevation.flys.client.client.services.DescribeArtifactServiceAsync;
 import de.intevation.flys.client.shared.model.Artifact;
 
 
 public class LoadingPanel extends Canvas {
 
-    public static final int UPDATE_INTERVAL = 1000 * 5;
+    public static final int UPDATE_INTERVAL = 1000 * 10;
+
+    public static final DescribeArtifactServiceAsync describe =
+        GWT.create(DescribeArtifactService.class);
+
 
     protected CollectionView parent;
     protected Artifact       artifact;
@@ -56,6 +62,11 @@
     }
 
 
+    public void setArtifact(Artifact artifact) {
+        this.artifact = artifact;
+    }
+
+
     protected HLayout createDialog() {
         msg.setStyleName("loading-message");
         msg.setWidth(200);
@@ -85,17 +96,33 @@
     }
 
 
-    private void update() {
+    protected void update() {
         msg.setContents("This is update -> " + String.valueOf(i++));
 
-        // TODO FETCH ARTIFACT's DESCRIBE DOCUMENT AND REMOVE THIS LOADING PANEL
-        // IF IT IS NO LONGER IN BACKGROUND MODE!
+        final Config config = Config.getInstance();
+        final String url    = config.getServerUrl();
+        final String locale = config.getLocale();
 
-        if (i == 5) {
-            finish();
-        }
+        describe.describe(url, locale, artifact, new AsyncCallback<Artifact>() {
+            public void onFailure(Throwable t) {
+                GWT.log("Error while DESCRIBE artifact: " + t.getMessage());
+                // SC.warn()...
+                startTimer();
+            }
 
-        startTimer();
+            public void onSuccess(Artifact artifact) {
+                GWT.log("Successfully DESCRIBE artifact.");
+
+                setArtifact(artifact);
+
+                if (artifact.isInBackground()) {
+                    startTimer();
+                }
+                else {
+                    finish();
+                }
+            }
+        });
     }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DescribeArtifactServiceImpl.java	Thu Sep 08 07:44:05 2011 +0000
@@ -0,0 +1,67 @@
+package de.intevation.flys.client.server;
+
+import org.w3c.dom.Document;
+
+import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+
+import de.intevation.artifacts.common.utils.ClientProtocolUtils;
+
+import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
+import de.intevation.artifacts.httpclient.http.HttpClient;
+import de.intevation.artifacts.httpclient.http.HttpClientImpl;
+import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
+
+import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.shared.model.Artifact;
+import de.intevation.flys.client.client.services.DescribeArtifactService;
+
+
+/**
+ * This interface provides artifact specific operation DESCRIBE.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class DescribeArtifactServiceImpl
+extends      RemoteServiceServlet
+implements   DescribeArtifactService
+{
+    public static final String ERROR_DESCRIBE_ARTIFACT =
+        "error_describe_artifact";
+
+
+    public Artifact describe(String url, String locale, Artifact artifact)
+    throws ServerException
+    {
+        System.out.println("DescribeArtifactServiceImpl.describe");
+
+        Document describe = ClientProtocolUtils.newDescribeDocument(
+            artifact.getUuid(),
+            artifact.getHash(),
+            true);
+
+        HttpClient client = new HttpClientImpl(url, locale);
+
+        try {
+            System.out.println("Start Http request now.");
+
+            Document description = (Document) client.describe(
+                new de.intevation.artifacts.httpclient.objects.Artifact(
+                    artifact.getUuid(),
+                    artifact.getHash()),
+                describe,
+                new DocumentResponseHandler());
+
+            if (description != null) {
+                System.out.println("Finished Http request sucessfully!");
+
+                return (Artifact) new FLYSArtifactCreator().create(description);
+            }
+        }
+        catch (ConnectionException ce) {
+            ce.printStackTrace();
+        }
+
+        throw new ServerException(ERROR_DESCRIBE_ARTIFACT);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Thu Sep 08 06:56:17 2011 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Thu Sep 08 07:44:05 2011 +0000
@@ -257,6 +257,16 @@
     <url-pattern>/flys/map-info</url-pattern>
   </servlet-mapping>
 
+  <servlet>
+    <servlet-name>DescribeArtifactService</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.DescribeArtifactServiceImpl</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>DescribeArtifactService</servlet-name>
+    <url-pattern>/flys/describe</url-pattern>
+  </servlet-mapping>
+
   <!-- Default page to serve -->
   <welcome-file-list>
     <welcome-file>FLYS.html</welcome-file>

http://dive4elements.wald.intevation.org