diff flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java @ 1478:237e7450ae2e

Save output settings in chart properties dialog. flys-client/trunk@3524 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 22 Dec 2011 12:46:23 +0000
parents d0bcf5ba7adf
children cd8a146d29cd
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java	Thu Dec 22 09:28:22 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java	Thu Dec 22 12:46:23 2011 +0000
@@ -3,7 +3,9 @@
 import java.util.List;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 
+import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Window;
 import com.smartgwt.client.widgets.tab.TabSet;
 import com.smartgwt.client.widgets.tab.Tab;
@@ -24,6 +26,7 @@
 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
 import com.smartgwt.client.types.Alignment;
 
+import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.ui.OutputTab;
 import de.intevation.flys.client.shared.model.Property;
@@ -34,8 +37,12 @@
 import de.intevation.flys.client.shared.model.IntegerProperty;
 import de.intevation.flys.client.shared.model.StringProperty;
 import de.intevation.flys.client.shared.model.Settings;
+import de.intevation.flys.client.shared.model.OutputSettings;
+import de.intevation.flys.client.shared.model.Collection;
 
-import de.intevation.flys.client.shared.model.Collection;
+import de.intevation.flys.client.client.services.CollectionAttributeService;
+import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync;
+
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
@@ -46,12 +53,22 @@
     /** The interface that provides i18n messages. */
     protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
+    protected CollectionAttributeServiceAsync updater =
+        GWT.create(CollectionAttributeService.class);
+
     /** The tab called the editor window. */
     protected OutputTab tab;
 
     /** The tabset for chart properties */
     protected TabSet tabs;
 
+    /** The collection */
+    protected Collection collection;
+
+    /** The output settings */
+    protected OutputSettings settings;
+
+
     /**
      * Setup editor dialog.
      * @param callerTab      The tab called the editor window.
@@ -72,9 +89,9 @@
         setCanDragResize(true);
 
 
-        Collection c = tab.getCollectionView().getCollection();
+        collection = tab.getCollectionView().getCollection();
         String outputName = tab.getOutputName();
-        Settings settings = c.getSettings(outputName);
+        settings = (OutputSettings)collection.getSettings(outputName);
 
         if (settings == null) {
             return;
@@ -91,7 +108,6 @@
                 }
                 else if (props.get(j) instanceof PropertySetting) {
                     PropertySetting p = (PropertySetting)props.get(j);
-
                     if (p.getAttribute("display").equals("false")) {
                         continue;
                     }
@@ -107,7 +123,7 @@
         cancel.addClickHandler(this);
         accept.addClickHandler(new ClickHandler() {
             public void onClick(ClickEvent e) {
-
+                updateCollection();
             }
         });
 
@@ -152,23 +168,19 @@
             StringProperty label =
                 (StringProperty)pg.getPropertyByName("label");
             FormItem title = createStringProperty(label);
-            title.setValue(label.getValue());
 
             IntegerProperty fontsize =
                 (IntegerProperty)pg.getPropertyByName("font-size");
             FormItem fs = createIntegerProperty(fontsize);
-            fs.setValue(fontsize.getValue());
 
             DoubleProperty upper =
                 (DoubleProperty)pg.getPropertyByName("upper");
             final FormItem range1 = createDoubleProperty(upper);
-            range1.setValue(upper.getValue());
             range1.setWidth(50);
 
             DoubleProperty lower =
                 (DoubleProperty)pg.getPropertyByName("lower");
             final FormItem range2 = createDoubleProperty(lower);
-            range2.setValue(lower.getValue());
             range2.setWidth(50);
 
             BooleanProperty fixation =
@@ -187,12 +199,10 @@
                 }
             });
             if (fixation.getValue().equals("true")) {
-                fix.setValue(true);
                 range1.enable();
                 range2.enable();
             }
             else {
-                fix.setValue(false);
                 range1.disable();
                 range2.disable();
             }
@@ -221,19 +231,22 @@
      *
      */
     protected DynamicForm generatePropertySetting(Property setting) {
+        final PropertySetting s = (PropertySetting)setting;
         DynamicForm form = new DynamicForm();
+        FormItem item = new FormItem();
         if (setting instanceof BooleanProperty) {
-            form.setFields(createBooleanProperty((BooleanProperty)setting));
+            item = createBooleanProperty((BooleanProperty)setting);
         }
         else if (setting instanceof DoubleProperty) {
-            form.setFields(createDoubleProperty((DoubleProperty)setting));
+            item = createDoubleProperty((DoubleProperty)setting);
         }
         else if (setting instanceof IntegerProperty) {
-            form.setFields(createIntegerProperty((IntegerProperty)setting));
+            item = createIntegerProperty((IntegerProperty)setting);
         }
         else if (setting instanceof StringProperty) {
-            form.setFields(createStringProperty((StringProperty)setting));
+            item = createStringProperty((StringProperty)setting);
         }
+        form.setFields(item);
         return form;
     }
 
@@ -241,7 +254,7 @@
     /**
      *
      */
-    protected FormItem createStringProperty(StringProperty sp) {
+    protected FormItem createStringProperty(final StringProperty sp) {
         String name = sp.getName();
         if (name.contains("-")) {
             name = name.replace("-", "_");
@@ -249,6 +262,19 @@
         TextItem item = new TextItem();
         item.setTitle(MSG.getString(name));
         item.setTitleAlign(Alignment.LEFT);
+        item.setValue(sp.getValue());
+        item.addChangedHandler(new ChangedHandler() {
+            public void onChanged(ChangedEvent e) {
+                String val;
+                if (e.getValue() == null) {
+                    val = "";
+                }
+                else {
+                    val = e.getValue().toString();
+                }
+                sp.setValue(val);
+            }
+        });
         return item;
     }
 
@@ -256,7 +282,7 @@
     /**
      *
      */
-    protected FormItem createBooleanProperty(BooleanProperty bp) {
+    protected FormItem createBooleanProperty(final BooleanProperty bp) {
         String name = bp.getName();
         if (name.contains("-")) {
             name = name.replace("-", "_");
@@ -266,6 +292,24 @@
         item.setLabelAsTitle(true);
         item.setTitleStyle("color:#000;");
         item.setTitleAlign(Alignment.LEFT);
+        if(bp.getValue().equals("true")) {
+            item.setValue(true);
+        }
+        else {
+            item.setValue(false);
+        }
+        item.addChangedHandler(new ChangedHandler() {
+            public void onChanged(ChangedEvent e) {
+                String val;
+                if (e.getValue() == null) {
+                    val = "";
+                }
+                else {
+                    val = e.getValue().toString();
+                }
+                bp.setValue(val);
+            }
+        });
         return item;
     }
 
@@ -273,7 +317,7 @@
     /**
      *
      */
-    protected FormItem createDoubleProperty(DoubleProperty dp) {
+    protected FormItem createDoubleProperty(final DoubleProperty dp) {
         String name = dp.getName();
         if (name.contains("-")) {
             name = name.replace("-", "_");
@@ -282,6 +326,19 @@
         TextItem item = new TextItem();
         item.setTitle(MSG.getString(name));
         item.setTitleAlign(Alignment.LEFT);
+        item.setValue(dp.getValue());
+        item.addChangedHandler(new ChangedHandler() {
+            public void onChanged(ChangedEvent e) {
+                String val;
+                if (e.getValue() == null) {
+                    val = "";
+                }
+                else {
+                    val = e.getValue().toString();
+                }
+                dp.setValue(val);
+            }
+        });
         return item;
     }
 
@@ -289,7 +346,7 @@
     /**
      *
      */
-    protected FormItem createIntegerProperty(IntegerProperty ip) {
+    protected FormItem createIntegerProperty(final IntegerProperty ip) {
         String name = ip.getName();
         if (name.contains("-")) {
             name = name.replace("-", "_");
@@ -298,6 +355,42 @@
         TextItem item = new TextItem();
         item.setTitle(MSG.getString(name));
         item.setTitleAlign(Alignment.LEFT);
+        item.setValue(ip.getValue());
+        item.addChangedHandler(new ChangedHandler() {
+            public void onChanged(ChangedEvent e) {
+                String val;
+                if (e.getValue() == null) {
+                    val = "";
+                }
+                else {
+                    val = e.getValue().toString();
+                }
+                ip.setValue(val);
+            }
+        });
         return item;
     }
+
+
+    protected void updateCollection() {
+        final Config config = Config.getInstance();
+        final String loc    = config.getLocale();
+
+        GWT.log("PropertiesEditor.updateCollection via RPC now");
+        this.hide();
+
+        updater.update(collection, 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) {
+            }
+        });
+
+    }
+
+
 }

http://dive4elements.wald.intevation.org