changeset 1292:bdc270ea6195

Edited item attributes are saved and send to the server on accept. flys-client/trunk@2898 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 05 Oct 2011 16:29:14 +0000
parents 1d04f35b2cc0
children e88cd17b3420
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeService.java flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionItemAttribute.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Style.java
diffstat 8 files changed, 227 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Oct 05 09:26:13 2011 +0000
+++ b/flys-client/ChangeLog	Wed Oct 05 16:29:14 2011 +0000
@@ -1,3 +1,25 @@
+2011-10-05  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Edited item attributes are saved and send to the server on accept.
+
+	* src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java,
+	  src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeService.java,
+	  src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeServiceAsync.java:
+	  Added service method to save new item attributes.
+
+	* src/main/java/de/intevation/flys/client/shared/model/Style.java:
+	  Added facet to style attributes.
+
+	* src/main/java/de/intevation/flys/client/shared/model/CollectionItemAttribute.java:
+	  Added artifact uuid to collection item attributes.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java:
+	  Added item changed handler to save new values and update the
+	  serverside values.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java:
+	  Set the selected facet record to the editor window.
+
 2011-10-05  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeService.java	Wed Oct 05 09:26:13 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeService.java	Wed Oct 05 16:29:14 2011 +0000
@@ -24,5 +24,13 @@
         String locale)
     throws ServerException;
 
+    void setCollectionItemAttribute(
+        Collection collection,
+        String artifact,
+        String url,
+        String locale,
+        CollectionItemAttribute attribute)
+    throws ServerException;
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeServiceAsync.java	Wed Oct 05 09:26:13 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/CollectionItemAttributeServiceAsync.java	Wed Oct 05 16:29:14 2011 +0000
@@ -19,5 +19,14 @@
         String                  serverUrl,
         String                  locale,
         AsyncCallback<CollectionItemAttribute> callback);
+
+    public void setCollectionItemAttribute(
+        Collection              collection,
+        String                  artifact,
+        String                  serverUrl,
+        String                  locale,
+        CollectionItemAttribute attributes,
+        AsyncCallback<Void> 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 Oct 05 09:26:13 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Wed Oct 05 16:29:14 2011 +0000
@@ -147,7 +147,7 @@
     }
 
 
-    protected void getItemAttributes(FacetRecord record) {
+    protected void getItemAttributes(final FacetRecord record) {
         Config config = Config.getInstance();
         String url = config.getServerUrl();
         String locale = config.getLocale();
@@ -167,7 +167,8 @@
                     GWT.log("Successfully loaded collectionitem attributes.");
                     StyleEditorWindow win = new StyleEditorWindow(
                         collection,
-                        cia);
+                        cia,
+                        record);
                     win.setCollectionView(view);
                     win.show();
                 }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java	Wed Oct 05 09:26:13 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java	Wed Oct 05 16:29:14 2011 +0000
@@ -1,6 +1,7 @@
 package de.intevation.flys.client.client.ui.chart;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.widgets.Window;
 import com.smartgwt.client.widgets.layout.VLayout;
@@ -12,18 +13,26 @@
 import com.smartgwt.client.widgets.form.fields.SpinnerItem;
 import com.smartgwt.client.widgets.form.fields.ColorPickerItem;
 import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
+import com.smartgwt.client.widgets.form.fields.TextItem;
 
 import com.smartgwt.client.widgets.events.ClickEvent;
 import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.form.events.ItemChangedEvent;
+import com.smartgwt.client.widgets.form.events.ItemChangedHandler;
 import com.smartgwt.client.types.Alignment;
 
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.shared.model.CollectionItemAttribute;
 import de.intevation.flys.client.shared.model.Style;
 import de.intevation.flys.client.shared.model.StyleSetting;
+import de.intevation.flys.client.shared.model.FacetRecord;
+
+import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync;
+import de.intevation.flys.client.client.services.CollectionItemAttributeService;
 import de.intevation.flys.client.client.ui.CollectionView;
 
 import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.client.Config;
 
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
@@ -44,16 +53,24 @@
     /** The attributes */
     protected CollectionItemAttribute attributes;
 
+    /** The selected facet. */
+    protected FacetRecord facet;
+
     /** Main layout */
     protected VLayout layout;
 
+    /** The service used to set collection item attributes. */
+    protected CollectionItemAttributeServiceAsync itemAttributeService =
+        GWT.create(CollectionItemAttributeService.class);
 
     public StyleEditorWindow (
         Collection collection,
-        CollectionItemAttribute attributes)
+        CollectionItemAttribute attributes,
+        FacetRecord facet)
     {
         this.collection = collection;
         this.attributes = attributes;
+        this.facet = facet;
         this.layout = new VLayout();
 
         init();
@@ -82,7 +99,7 @@
         cancel.addClickHandler(this);
         accept.addClickHandler(new ClickHandler() {
             public void onClick(ClickEvent e) {
-
+                saveStyle();
             }
         });
 
@@ -90,7 +107,7 @@
         buttons.addMember(cancel);
         buttons.setAlign(Alignment.RIGHT);
 
-        layout.addMember(createPropertyGrid("LongitudinalSectionW"));;
+        layout.addMember(createPropertyGrid());;
         layout.addMember(buttons);
         addItem(layout);
     }
@@ -107,14 +124,20 @@
     }
 
 
-    protected VLayout createPropertyGrid(String stylename) {
-        //TODO use the style-(theme-)name from response to get the correct
-        //attribute set.
-
+    protected VLayout createPropertyGrid() {
         VLayout properties = new VLayout();
 
-        // get the correct style using the name.
-        Style s = attributes.getStyle(0);
+        Style s = attributes.getStyle(facet.getTheme().getFacet());
+
+        TextItem name = new TextItem("name", "Name");
+        name.setValue(facet.getName());
+        name.setTitleStyle("color:#000; width:120px");
+        name.setTitleAlign(Alignment.LEFT);
+        name.setDisabled(true);
+        name.setShowDisabled(false);
+        DynamicForm f = new DynamicForm();
+        f.setFields(name);
+        properties.addMember(f);
 
         for (int i = 0; i < s.getNumSettings(); i ++) {
             final StyleSetting set = s.getSetting(i);
@@ -170,6 +193,14 @@
         f.setTitleStyle("color:#000; width:120px");
         f.setTitleAlign(Alignment.LEFT);
         df.setFields(f);
+        df.addItemChangedHandler(new ItemChangedHandler() {
+            public void onItemChanged(ItemChangedEvent e) {
+                String name = e.getItem().getName();
+                String newValue = e.getNewValue().toString();
+                GWT.log("changed: " + name);
+                setNewValue(name, newValue);
+            }
+        });
 
         return df;
     }
@@ -188,7 +219,10 @@
         }
         String hex = "#";
         for (int i = 0; i < values.length; i++) {
-            hex += Integer.toHexString(values[i]);
+           if (values[i] < 16) {
+                hex += "0";
+           }
+           hex += Integer.toHexString(values[i]);
         }
         return hex;
     }
@@ -198,7 +232,6 @@
             return "0, 0, 0";
         }
 
-        GWT.log("sub: " + html.substring(1, 3));
         int r = Integer.valueOf(html.substring(1, 3), 16);
         int g = Integer.valueOf(html.substring(3, 5), 16);
         int b = Integer.valueOf(html.substring(5, 7), 16);
@@ -206,5 +239,38 @@
         return r + ", " + g + ", " + b;
     }
 
+    protected void saveStyle () {
+        GWT.log("StyleEditorWindow.saveStyle()");
+        Config config = Config.getInstance();
+        String url = config.getServerUrl();
+        String locale = config.getLocale();
+
+        itemAttributeService.setCollectionItemAttribute(
+            this.collection,
+            attributes.getArtifact(),
+            url,
+            locale,
+            attributes,
+            new AsyncCallback<Void>() {
+                public void onFailure (Throwable caught) {
+                    GWT.log("Could not set Collection item attributes.");
+                }
+                public void onSuccess(Void v) {
+                    GWT.log("Successfully saved collection item attributes.");
+                }
+            });
+
+
+        this.hide();
+    }
+
+    protected final void setNewValue(String name, String value) {
+        Style s = attributes.getStyle(facet.getTheme().getFacet());
+        StyleSetting set = s.getSetting(name);
+        if(name.equals("linecolor")) {
+            value = htmlToRgb(value);
+        }
+        set.setDefaultValue(value);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java	Wed Oct 05 09:26:13 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java	Wed Oct 05 16:29:14 2011 +0000
@@ -45,7 +45,7 @@
     throws ServerException
     {
         System.out.println(
-            "GetCollectionItemAttributeServiceImpl.getCollectionItemAttribute");
+            "CollectionItemAttributeServiceImpl.getCollectionItemAttribute");
 
         Document requestDoc = XMLUtils.newDocument();
 
@@ -72,8 +72,7 @@
                 requestDoc,
                 collection.identifier(),
                 new DocumentResponseHandler());
-
-            return readXML (res);
+            return readXML (res, artifact);
         }
         catch (ConnectionException ce) {
             System.err.println(ce.getLocalizedMessage());
@@ -81,8 +80,38 @@
         throw new ServerException("");
     }
 
-    protected CollectionItemAttribute readXML (Document doc) {
+
+    public void setCollectionItemAttribute(
+        Collection collection,
+        String artifact,
+        String url,
+        String locale,
+        CollectionItemAttribute attributes)
+    throws ServerException
+    {
+        System.out.println(
+            "CollectionItemAttributeServiceImpl.setCollectionItemAttribute");
+
+        Document doc = writeXML(attributes, artifact);
+
+        try {
+            HttpClient client = new HttpClientImpl(url, locale);
+            Document res = (Document) client.doCollectionAction(
+                doc,
+                collection.identifier(),
+                new DocumentResponseHandler());
+
+            return;
+        }
+        catch (ConnectionException ce) {
+            System.err.println(ce.getLocalizedMessage());
+        }
+        throw new ServerException("");
+    }
+
+    protected CollectionItemAttribute readXML (Document doc, String artifact) {
         CollectionItemAttribute cia = new CollectionItemAttribute();
+        cia.setArtifact(artifact);
 
         Element root = doc.getDocumentElement();
         NodeList themes = root.getElementsByTagName("art:themes");
@@ -102,6 +131,56 @@
     }
 
 
+    protected Document writeXML (
+        CollectionItemAttribute attributes,
+        String artifact)
+    {
+        Document styles = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+                styles,
+                ArtifactNamespaceContext.NAMESPACE_URI,
+                ArtifactNamespaceContext.NAMESPACE_PREFIX);
+        Element action = ec.create("action");
+        Element type = ec.create("type");
+        type.setAttribute("name", "setitemattribute");
+        Element art = ec.create("artifact");
+        art.setAttribute("uuid", artifact);
+        Element attr = ec.create("attribute");
+        Element themes = ec.create("themes");
+        action.appendChild(type);
+        type.appendChild(art);
+        art.appendChild(attr);
+        attr.appendChild(themes);
+
+        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
+                styles,
+                "",
+                "");
+
+        for (int i = 0; i < attributes.getNumStyles(); i++) {
+            Style s = attributes.getStyle(i);
+            Element theme = creator.create("theme");
+            theme.setAttribute("name", s.getName());
+            theme.setAttribute("facet", s.getFacet());
+            theme.setAttribute("index", String.valueOf(i));
+            for (int j = 0; j < s.getNumSettings(); j++) {
+                StyleSetting set = s.getSetting(j);
+                Element field = creator.create("field");
+                field.setAttribute("name", set.getName());
+                field.setAttribute("display", set.getDisplayName());
+                field.setAttribute("default", set.getDefaultValue());
+                field.setAttribute("hints", set.getHints());
+                field.setAttribute("type", set.getType());
+                theme.appendChild(field);
+            }
+            themes.appendChild(theme);
+        }
+        styles.appendChild(action);
+        return styles;
+    }
+
+
     protected Style getStyle (Element element) {
 
         if (!element.getTagName().equals("theme")) {
@@ -110,7 +189,9 @@
 
         NodeList list = element.getElementsByTagName("field");
         Style style = new Style();
+
         style.setName (element.getAttribute("name"));
+        style.setFacet (element.getAttribute("facet"));
         for(int i = 0; i < list.getLength(); i++) {
             Element e = (Element) list.item(i);
             StyleSetting set = new StyleSetting (
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionItemAttribute.java	Wed Oct 05 09:26:13 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionItemAttribute.java	Wed Oct 05 16:29:14 2011 +0000
@@ -13,6 +13,8 @@
 
     protected List<Style> styles;
 
+    protected String artifact;
+
     public CollectionItemAttribute() {
         styles = new ArrayList<Style>();
     }
@@ -29,9 +31,9 @@
         }
     }
 
-    public Style getStyle(String name) {
+    public Style getStyle(String facet) {
         for (int i = 0; i < styles.size(); i++) {
-            if (styles.get(i).getName().equals(name)) {
+            if (styles.get(i).getFacet().equals(facet)) {
                 return styles.get(i);
             }
         }
@@ -45,4 +47,12 @@
     public int getNumStyles() {
         return styles.size();
     }
+
+    public void setArtifact(String artifact) {
+        this.artifact = artifact;
+    }
+
+    public String getArtifact () {
+        return this.artifact;
+    }
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Style.java	Wed Oct 05 09:26:13 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Style.java	Wed Oct 05 16:29:14 2011 +0000
@@ -14,6 +14,9 @@
 public class Style implements Serializable {
 
     protected String name;
+
+    protected String facet;
+
     protected List<StyleSetting> settings;
 
     public Style() {
@@ -28,10 +31,18 @@
         this.name = name;
     }
 
+    public void setFacet(String facet) {
+        this.facet = facet;
+    }
+
     public String getName() {
         return this.name;
     }
 
+    public String getFacet() {
+        return this.facet;
+    }
+
     public StyleSetting getSetting(String name) {
         for (int i = 0; i < settings.size (); i++) {
             if (settings.get(i).getName().equals(name)) {

http://dive4elements.wald.intevation.org