changeset 1503:3304608baf35

Issue 433. Allways load original chart settings when opening the dialog. flys-client/trunk@3632 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 09 Jan 2012 17:07:17 +0000
parents d1223d93dd68
children 02a9104c0451
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java flys-client/src/main/java/de/intevation/flys/client/shared/model/BooleanProperty.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleProperty.java flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerProperty.java flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Property.java flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java flys-client/src/main/java/de/intevation/flys/client/shared/model/StringProperty.java
diffstat 11 files changed, 241 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Jan 09 14:28:37 2012 +0000
+++ b/flys-client/ChangeLog	Mon Jan 09 17:07:17 2012 +0000
@@ -1,3 +1,24 @@
+2012-01-09  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Issue 433. Allways load original chart settings when opening the dialog.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java:
+	  Clone the settings object and set the original values while initializing
+	  the dialog.
+
+	* src/main/java/de/intevation/flys/client/shared/model/Property.java,
+	  src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java,
+	  src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java,
+	  src/main/java/de/intevation/flys/client/shared/model/BooleanProperty.java,
+	  src/main/java/de/intevation/flys/client/shared/model/DoubleProperty.java,
+	  src/main/java/de/intevation/flys/client/shared/model/IntegerProperty.java,
+	  src/main/java/de/intevation/flys/client/shared/model/StringProperty.java,
+	  src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java:
+	  Made the properties and settings classes cloneable.
+
+	* src/main/java/de/intevation/flys/client/shared/model/Collection.java:
+	  Added a method of DefaultCollection to the interface.
+
 2012-01-09  Raimund Renkert <raimund.renkert@intevation.de>
 
 	Issue 358. Validate dialog on accept.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java	Mon Jan 09 14:28:37 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java	Mon Jan 09 17:07:17 2012 +0000
@@ -37,6 +37,7 @@
 import de.intevation.flys.client.shared.model.DoubleProperty;
 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.client.utils.Validator;
@@ -66,9 +67,12 @@
     /** The collection */
     protected Collection collection;
 
-    /** The output settings */
+    /** The cloned output settings */
     protected OutputSettings settings;
 
+    /** The original output settings */
+    protected OutputSettings origSettings;
+
 
     /**
      * Setup editor dialog.
@@ -92,8 +96,9 @@
         Config config = Config.getInstance();
         collection = tab.getCollectionView().getCollection();
         String outputName = tab.getOutputName();
-        settings = (OutputSettings)collection.getSettings(outputName);
+        origSettings = (OutputSettings)collection.getSettings(outputName);
 
+        settings = (OutputSettings)origSettings.clone();
         if (settings == null) {
             return;
         }
@@ -102,17 +107,20 @@
         for (int i = 0; i < list.size(); i++) {
             Tab t = new Tab(MSG.getString(list.get(i)));
             List<Property> props = settings.getSettings(list.get(i));
+            List<Property> origProps = origSettings.getSettings(list.get(i));
             VLayout layout = new VLayout();
             for (int j = 0; j < props.size(); j++) {
                 if (props.get(j) instanceof PropertyGroup) {
-                    layout.addMember(generatePropertyGroup(props.get(j)));
+                    layout.addMember(generatePropertyGroup(props.get(j),
+                                                           origProps.get(j)));
                 }
                 else if (props.get(j) instanceof PropertySetting) {
                     PropertySetting p = (PropertySetting)props.get(j);
                     if (p.getAttribute("display").equals("false")) {
                         continue;
                     }
-                    layout.addMember(generatePropertySetting(props.get(j)));
+                    layout.addMember(generatePropertySetting(props.get(j),
+                                                             origProps.get(j)));
                 }
             }
             t.setPane(layout);
@@ -152,16 +160,16 @@
      * @param event The event.
      */
     public void onClick(ClickEvent event) {
-        this.hide();
+        this.destroy();
     }
 
 
     /**
      *
      */
-    protected Canvas generatePropertyGroup(Property group) {
+    protected Canvas generatePropertyGroup(Property group, Property orig) {
         PropertyGroup pg = (PropertyGroup)group;
-        List<Property> list = pg.getProperties();
+        PropertyGroup origPg = (PropertyGroup)orig;
 
         if (pg.getName().equals("axis")) {
             Label scale = new Label(MSG.scale() + " :");
@@ -175,12 +183,17 @@
             StringProperty label =
                 (StringProperty)pg.getPropertyByName("label");
             FormItem title = createStringProperty(label);
+            title.setValue(
+                ((StringProperty)origPg.getPropertyByName("label")).getValue());
 
             IntegerProperty fontsize =
                 (IntegerProperty)pg.getPropertyByName("font-size");
             FormItem fs = createIntegerProperty(fontsize);
             fs.setAttribute("internalType", "integer");
             fs.addChangedHandler(new Validator());
+            fs.setValue(
+                ((IntegerProperty)
+                    origPg.getPropertyByName("font-size")).getValue());
 
             DoubleProperty upper =
                 (DoubleProperty)pg.getPropertyByName("upper");
@@ -188,6 +201,8 @@
             range1.setAttribute("internalType", "double");
             range1.addChangedHandler(new Validator());
             range1.setWidth(70);
+            range1.setValue(
+                ((DoubleProperty)origPg.getPropertyByName("upper")).getValue());
 
             DoubleProperty lower =
                 (DoubleProperty)pg.getPropertyByName("lower");
@@ -195,10 +210,15 @@
             range2.setAttribute("internalType", "double");
             range2.addChangedHandler(new Validator());
             range2.setWidth(70);
+            range2.setValue(
+                ((DoubleProperty)origPg.getPropertyByName("lower")).getValue());
 
             BooleanProperty fixation =
                 (BooleanProperty)pg.getPropertyByName("fixation");
             FormItem fix = createBooleanProperty(fixation);
+            fix.setValue(
+                ((BooleanProperty)
+                    origPg.getPropertyByName("fixation")).getValue());
             fix.addChangedHandler(new ChangedHandler() {
                 public void onChanged(ChangedEvent e) {
                     if ((Boolean)e.getValue()) {
@@ -227,7 +247,7 @@
             scaleLayout.setHeight(30);
             scaleLayout.addMember(scale);
             scaleLayout.addMember(form2);
-            scaleLayout.addStyleName("property-dialog-axis");
+            scaleLayout.setStyleName("property-dialog-axis");
 
             VLayout root = new VLayout();
             root.addMember(form1);
@@ -243,25 +263,32 @@
     /**
      *
      */
-    protected DynamicForm generatePropertySetting(Property setting) {
+    protected DynamicForm generatePropertySetting(
+        Property setting,
+        Property orig)
+    {
         PropertySetting s = (PropertySetting)setting;
         DynamicForm form = new DynamicForm();
         FormItem item = new FormItem();
         if (setting instanceof BooleanProperty) {
             item = createBooleanProperty((BooleanProperty)setting);
+            item.setValue(((BooleanProperty)orig).getValue());
         }
         else if (setting instanceof DoubleProperty) {
             item = createDoubleProperty((DoubleProperty)setting);
             item.setAttribute("internalType", "double");
             item.addChangedHandler(new Validator());
+            item.setValue(((DoubleProperty)orig).getValue());
         }
         else if (setting instanceof IntegerProperty) {
             item = createIntegerProperty((IntegerProperty)setting);
             item.setAttribute("internalType", "integer");
             item.addChangedHandler(new Validator());
+            item.setValue(((IntegerProperty)orig).getValue());
         }
         else if (setting instanceof StringProperty) {
             item = createStringProperty((StringProperty)setting);
+            item.setValue(((StringProperty)orig).getValue());
         }
         form.setFields(item);
         return form;
@@ -279,7 +306,6 @@
         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;
@@ -309,12 +335,12 @@
         item.setLabelAsTitle(true);
         item.setTitleStyle("color:#000;");
         item.setTitleAlign(Alignment.LEFT);
-        if(bp.getValue().equals("true")) {
+/*        if(bp.getValue().equals("true")) {
             item.setValue(true);
         }
         else {
             item.setValue(false);
-        }
+        }*/
         item.addChangedHandler(new ChangedHandler() {
             public void onChanged(ChangedEvent e) {
                 String val;
@@ -343,7 +369,6 @@
         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;
@@ -372,7 +397,6 @@
         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;
@@ -395,6 +419,8 @@
 
         GWT.log("PropertiesEditor.updateCollection via RPC now");
 
+        Settings s = settings;
+        collection.addSettings(this.tab.getOutputName(), s);
         updater.update(collection, loc, new AsyncCallback<Collection>() {
             public void onFailure(Throwable caught) {
                 GWT.log("Could not update collection attributes.");
@@ -407,9 +433,9 @@
     }
 
     protected void updateChartTab() {
-        this.hide();
         this.tab.updateChartInfo();
         this.tab.updateChartPanel();
+        this.destroy();
     }
 
 
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/BooleanProperty.java	Mon Jan 09 14:28:37 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/BooleanProperty.java	Mon Jan 09 17:07:17 2012 +0000
@@ -1,8 +1,42 @@
 package de.intevation.flys.client.shared.model;
 
+import java.util.HashMap;
+
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class BooleanProperty extends PropertySetting {
 
+    /**
+     * Create a new BooleanProperty for settings.
+     */
+    public BooleanProperty() {
+        this.attributes = new HashMap<String, String>();
+    }
+
+
+    /**
+     * Create a new BooleanProperty.
+     * @param name The attribute name.
+     * @param value The current value.
+     */
+    public BooleanProperty(
+        String name,
+        String value)
+    {
+        this.name = name;
+        this.value = value;
+        this.attributes = new HashMap<String, String>();
+    }
+
+
+    public Object clone() {
+        BooleanProperty clone = new BooleanProperty(this.getName(),
+                                                    this.getValue());
+        for(String s: this.getAttributeList()) {
+            clone.setAttribute(s, this.getAttribute(s));
+        }
+        return clone;
+    }
+
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java	Mon Jan 09 14:28:37 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java	Mon Jan 09 17:07:17 2012 +0000
@@ -42,6 +42,8 @@
 
     public void setSettings(Map<String, Settings> settings);
 
+    public void addSettings(String name, Settings settings);
+
     /** Sets mapping outputname to ThemeList. */
     public void setThemeLists(Map<String, ThemeList> map);
 
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleProperty.java	Mon Jan 09 14:28:37 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleProperty.java	Mon Jan 09 17:07:17 2012 +0000
@@ -1,8 +1,42 @@
 package de.intevation.flys.client.shared.model;
 
+import java.util.HashMap;
+
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class DoubleProperty extends PropertySetting {
 
+    /**
+     * Create a new DoubleProperty for settings.
+     */
+    public DoubleProperty() {
+        this.attributes = new HashMap<String, String>();
+    }
+
+
+    /**
+     * Create a new DoubleProperty.
+     * @param name The attribute name.
+     * @param value The current value.
+     */
+    public DoubleProperty(
+        String name,
+        String value)
+    {
+        this.name = name;
+        this.value = value;
+        this.attributes = new HashMap<String, String>();
+    }
+
+
+    public Object clone() {
+        DoubleProperty clone = new DoubleProperty(this.getName(),
+                                                    this.getValue());
+        for(String s: this.getAttributeList()) {
+            clone.setAttribute(s, this.getAttribute(s));
+        }
+        return clone;
+    }
+
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerProperty.java	Mon Jan 09 14:28:37 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerProperty.java	Mon Jan 09 17:07:17 2012 +0000
@@ -1,8 +1,42 @@
 package de.intevation.flys.client.shared.model;
 
+import java.util.HashMap;
+
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class IntegerProperty extends PropertySetting {
 
+    /**
+     * Create a new IntegerProperty for settings.
+     */
+    public IntegerProperty() {
+        this.attributes = new HashMap<String, String>();
+    }
+
+
+    /**
+     * Create a new IntegerProperty.
+     * @param name The attribute name.
+     * @param value The current value.
+     */
+    public IntegerProperty(
+        String name,
+        String value)
+    {
+        this.name = name;
+        this.value = value;
+        this.attributes = new HashMap<String, String>();
+    }
+
+
+    public Object clone() {
+        IntegerProperty clone = new IntegerProperty(this.getName(),
+                                                    this.getValue());
+        for(String s: this.getAttributeList()) {
+            clone.setAttribute(s, this.getAttribute(s));
+        }
+        return clone;
+    }
+
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java	Mon Jan 09 14:28:37 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java	Mon Jan 09 17:07:17 2012 +0000
@@ -7,7 +7,7 @@
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
-public class OutputSettings implements Settings {
+public class OutputSettings implements Settings, Cloneable {
 
     /** The output name. */
     protected String name;
@@ -50,8 +50,21 @@
     }
 
 
-    public List getCategories() {
+    public List<String> getCategories() {
         ArrayList<String> list = new ArrayList<String>(categories.keySet());
         return list;
     }
+
+
+    public Object clone() {
+        OutputSettings clone = new OutputSettings(this.getName());
+        for (String s: this.getCategories()) {
+            ArrayList cloneList = new ArrayList<Property>();
+            for(Property p: this.getSettings(s)) {
+                cloneList.add((Property)p.clone());
+            }
+            clone.setSettings(s, cloneList);
+        }
+        return clone;
+    }
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Property.java	Mon Jan 09 14:28:37 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Property.java	Mon Jan 09 17:07:17 2012 +0000
@@ -12,4 +12,6 @@
     String getName();
 
     void setName(String name);
+
+    Object clone();
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java	Mon Jan 09 14:28:37 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java	Mon Jan 09 17:07:17 2012 +0000
@@ -1,11 +1,12 @@
 package de.intevation.flys.client.shared.model;
 
 import java.util.List;
+import java.util.ArrayList;
 
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
-public class PropertyGroup implements Property {
+public class PropertyGroup implements Property, Cloneable {
 
     /** The group name */
     protected String name;
@@ -49,4 +50,15 @@
         }
         return null;
     }
+
+
+    public Object clone() {
+        PropertyGroup clone = new PropertyGroup(this.getName());
+        List<Property> cloneList = new ArrayList<Property>();
+        for(Property p: properties) {
+            cloneList.add((Property)p.clone());
+        }
+        clone.setProperties(cloneList);
+        return clone;
+    }
 }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java	Mon Jan 09 14:28:37 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java	Mon Jan 09 17:07:17 2012 +0000
@@ -6,7 +6,7 @@
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
-public class PropertySetting implements Property {
+public class PropertySetting implements Property, Cloneable {
 
     /**The settings name.*/
     protected String name;
@@ -66,5 +66,15 @@
     public ArrayList<String> getAttributeList() {
         return new ArrayList<String>(attributes.keySet());
     }
+
+
+    public Object clone() {
+        PropertySetting clone = new PropertySetting(this.getName(),
+                                                    this.getValue());
+        for(String s: this.getAttributeList()) {
+            clone.setAttribute(s, this.getAttribute(s));
+        }
+        return clone;
+    }
 }
 // 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/StringProperty.java	Mon Jan 09 14:28:37 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/StringProperty.java	Mon Jan 09 17:07:17 2012 +0000
@@ -1,8 +1,42 @@
 package de.intevation.flys.client.shared.model;
 
+import java.util.HashMap;
+
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class StringProperty extends PropertySetting {
 
+    /**
+     * Create a new StringProperty for settings.
+     */
+    public StringProperty() {
+        this.attributes = new HashMap<String, String>();
+    }
+
+
+    /**
+     * Create a new StringProperty.
+     * @param name The attribute name.
+     * @param value The current value.
+     */
+    public StringProperty(
+        String name,
+        String value)
+    {
+        this.name = name;
+        this.value = value;
+        this.attributes = new HashMap<String, String>();
+    }
+
+
+    public Object clone() {
+        StringProperty clone = new StringProperty(this.getName(),
+                                                    this.getValue());
+        for(String s: this.getAttributeList()) {
+            clone.setAttribute(s, this.getAttribute(s));
+        }
+        return clone;
+    }
+
 }

http://dive4elements.wald.intevation.org