changeset 526:96e60e0a4345

Added a service stub to update/modify the attribute of a collection (used in the theme control panel). flys-client/trunk@2005 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 25 May 2011 14:58:42 +0000
parents fc994da131f9
children 902609b5cc79
files flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionAttributeService.java flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionAttributeServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java flys-client/src/main/java/de/intevation/flys/client/server/CollectionAttributeServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 6 files changed, 186 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionAttributeService.java	Wed May 25 14:58:42 2011 +0000
@@ -0,0 +1,19 @@
+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.Collection;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+@RemoteServiceRelativePath("collection-attribute")
+public interface CollectionAttributeService extends RemoteService {
+
+    Collection update(Collection collection, String url, String locale)
+    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/CollectionAttributeServiceAsync.java	Wed May 25 14:58:42 2011 +0000
@@ -0,0 +1,19 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import de.intevation.flys.client.shared.model.Collection;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface CollectionAttributeServiceAsync {
+
+    void update(
+        Collection collection,
+        String     url,
+        String     locale,
+        AsyncCallback<Collection> 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/chart/ChartThemePanel.java	Wed May 25 14:50:37 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Wed May 25 14:58:42 2011 +0000
@@ -1,10 +1,10 @@
 package de.intevation.flys.client.client.ui.chart;
 
-import java.util.List;
-
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.grid.events.EditCompleteEvent;
 import com.smartgwt.client.widgets.grid.events.EditCompleteHandler;
@@ -14,13 +14,15 @@
 import com.smartgwt.client.widgets.layout.VLayout;
 
 import de.intevation.flys.client.shared.model.Collection;
-import de.intevation.flys.client.shared.model.Facet;
 import de.intevation.flys.client.shared.model.FacetRecord;
 import de.intevation.flys.client.shared.model.OutputMode;
 import de.intevation.flys.client.shared.model.Theme;
 import de.intevation.flys.client.shared.model.ThemeList;
 
+import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.client.services.CollectionAttributeService;
+import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync;
 
 
 /**
@@ -31,6 +33,12 @@
     /** The interface that provides i18n messages. */
     private FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
+
+    /** The service that is used to modify collection attributes.*/
+    protected CollectionAttributeServiceAsync updater =
+        GWT.create(CollectionAttributeService.class);
+
+
     public static final String GRID_FIELD_ACTIVE = "active";
     public static final String GRID_FIELD_NAME   = "name";
 
@@ -99,6 +107,19 @@
 
 
     /**
+     * Replace the current collection with a new one. <b>NOTE: this operation
+     * triggers updateGrid() which modifies the themes in the grid.</b>
+     *
+     * @param collection The new collection object.
+     */
+    protected void setCollection(Collection collection) {
+        this.collection = collection;
+
+        updateGrid();
+    }
+
+
+    /**
      * A method that removes all records from theme grid.
      */
     protected void clearGrid() {
@@ -119,6 +140,8 @@
      * data.
      */
     protected void updateGrid() {
+        GWT.log("ChartThemePanel.updateGrid");
+
         clearGrid();
 
         ThemeList themeList = collection.getThemeList(mode.getName());
@@ -153,7 +176,72 @@
         int         row = event.getRowNum();
         FacetRecord rec = (FacetRecord) list.getRecord(row);
 
-        // TODO Save modified facets
+        updateThemeList(rec.getTheme());
+    }
+
+
+    /**
+     * Update the theme list of the current collection with a modified theme. If
+     * a theme is really modified, the CollectionAttributeService is triggered
+     * to save the changes to the artifact server.
+     *
+     * @param theme The modified theme.
+     */
+    protected void updateThemeList(Theme theme) {
+        GWT.log("Update theme: " + theme.getFacet());
+
+        ThemeList themeList = collection.getThemeList(mode.getName());
+
+        String a = theme.getArtifact();
+        String f = theme.getFacet();
+
+        int num = themeList != null ? themeList.getThemeCount() : 0;
+
+        boolean updateRequired = false;
+
+        for (int i = 1; i <= num; i++) {
+            Theme old = themeList.getThemeAt(i);
+
+            if (f.equals(old.getFacet()) && a.equals(old.getArtifact())) {
+                themeList.removeTheme(old);
+                themeList.addTheme(theme);
+
+                updateRequired = true;
+
+                break;
+            }
+        }
+
+        if (updateRequired) {
+            updateCollection();
+        }
+    }
+
+
+    /**
+     * This method triggers the CollectionAttributeService. Based on the current
+     * collectin settings, the attribute of the collection is modified or not.
+     * But in every case, we will get a new collection object - which might be
+     * the same as the current one.
+     */
+    public void updateCollection() {
+        final Config config = Config.getInstance();
+        final String url    = config.getServerUrl();
+        final String loc    = config.getLocale();
+
+        GWT.log("ChartThemePanel.updateCollection via RPC now");
+
+        updater.update(collection, url, loc, new AsyncCallback<Collection>() {
+            public void onFailure(Throwable caught) {
+                GWT.log("Could not update collection attributes.");
+                SC.warn(MSG.getString(caught.getMessage()));
+            }
+
+
+            public void onSuccess(Collection collection) {
+                setCollection(collection);
+            }
+        });
     }
 }
 // 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/server/CollectionAttributeServiceImpl.java	Wed May 25 14:58:42 2011 +0000
@@ -0,0 +1,32 @@
+package de.intevation.flys.client.server;
+
+import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.shared.model.Collection;
+
+import de.intevation.flys.client.client.services.CollectionAttributeService;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class CollectionAttributeServiceImpl
+extends      DescribeCollectionServiceImpl
+implements   CollectionAttributeService
+{
+    public Collection update(Collection collection, String url, String locale)
+    throws ServerException
+    {
+        System.out.println("CollectionAttributeServiceImpl.update");
+
+        // TODO Implement the correct update process here!
+        try {
+            Thread.currentThread().sleep(5000);
+        }
+        catch (InterruptedException ie) {
+            // do nothing
+        }
+
+        return describe(collection.identifier(), url, locale);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java	Wed May 25 14:50:37 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java	Wed May 25 14:58:42 2011 +0000
@@ -49,5 +49,19 @@
 
         return null;
     }
+
+
+    public void removeTheme(Theme theme) {
+        if (theme != null) {
+            themes.remove(theme);
+        }
+    }
+
+
+    public void addTheme(Theme theme) {
+        if (theme != null) {
+            themes.add(theme);
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Wed May 25 14:50:37 2011 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Wed May 25 14:58:42 2011 +0000
@@ -167,6 +167,16 @@
     <url-pattern>/flys/export</url-pattern>
   </servlet-mapping>
 
+  <servlet>
+    <servlet-name>CollectionAttributeService</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.CollectionAttributeServiceImpl</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>CollectionAttributeService</servlet-name>
+    <url-pattern>/flys/collection-attribute</url-pattern>
+  </servlet-mapping>
+
   <!-- Default page to serve -->
   <welcome-file-list>
     <welcome-file>FLYS.html</welcome-file>

http://dive4elements.wald.intevation.org