changeset 8454:7003cf5c19ed

(issue1764) Handle date ranges in chart properties editor
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 29 Oct 2014 19:49:18 +0100
parents 1326fc65638c
children 6dfc3a1fc70d
files gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ChartPropertiesEditor.java
diffstat 5 files changed, 126 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java	Wed Oct 29 16:02:37 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java	Wed Oct 29 19:49:18 2014 +0100
@@ -1409,5 +1409,9 @@
     String station();
 
     String station_name();
+
+    String lower_time();
+
+    String upper_time();
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties	Wed Oct 29 16:02:37 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties	Wed Oct 29 19:49:18 2014 +0100
@@ -748,3 +748,6 @@
 ld_locations=Station(s)
 
 potentiel = Potential
+
+lower_time = From
+upper_time = Until
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Wed Oct 29 16:02:37 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Wed Oct 29 19:49:18 2014 +0100
@@ -741,3 +741,6 @@
 potentiel = Potentiell
 bandwidthcolot = Bandbreitenfarbe
 
+lower_time = Von
+upper_time = Bis
+
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties	Wed Oct 29 16:02:37 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties	Wed Oct 29 19:49:18 2014 +0100
@@ -778,3 +778,5 @@
 
 DESCRIPTION = Description
 
+lower_time = From
+upper_time = Until
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ChartPropertiesEditor.java	Wed Oct 29 16:02:37 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/ChartPropertiesEditor.java	Wed Oct 29 19:49:18 2014 +0100
@@ -21,6 +21,7 @@
 import com.smartgwt.client.widgets.events.ClickHandler;
 import com.smartgwt.client.widgets.form.DynamicForm;
 import com.smartgwt.client.widgets.form.fields.CheckboxItem;
+import com.smartgwt.client.widgets.form.fields.DateItem;
 import com.smartgwt.client.widgets.form.fields.FormItem;
 import com.smartgwt.client.widgets.form.fields.SelectItem;
 import com.smartgwt.client.widgets.form.fields.TextItem;
@@ -30,6 +31,7 @@
 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
 import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
+import com.smartgwt.client.widgets.layout.Layout;
 import com.smartgwt.client.widgets.tab.Tab;
 import com.smartgwt.client.widgets.tab.TabSet;
 
@@ -53,6 +55,7 @@
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Date;
 
 /**
  * Dialog for the Chart-Properties, constructed from respective xml document.
@@ -204,8 +207,6 @@
             scale.setMargin(2);
 
             DynamicForm form1 = new DynamicForm();
-            DynamicForm form2 = new DynamicForm();
-            form2.setNumCols(6);
 
             StringProperty label =
                 (StringProperty)pg.getPropertyByName("label");
@@ -232,67 +233,104 @@
                 ((IntegerProperty)
                     origPg.getPropertyByName("font-size")).getValue());
 
-            DoubleProperty upper =
-                (DoubleProperty)pg.getPropertyByName("upper");
-            final FormItem range1 = createDoubleProperty(upper);
-            range1.setName("rangeupper");
-            range1.setWidth(70);
-            range1.setValue(
-                ((DoubleProperty)
-                    origPg.getPropertyByName("upper")).toUIString());
-
-            DoubleProperty lower =
-                (DoubleProperty)pg.getPropertyByName("lower");
-            final FormItem range2 = createDoubleProperty(lower);
-            range2.setName("rangelower");
-            range2.setWidth(70);
-            range2.setValue(
-                ((DoubleProperty)
-                    origPg.getPropertyByName("lower")).toUIString());
-
-            BooleanProperty fixation =
-                (BooleanProperty)pg.getPropertyByName("fixation");
-            FormItem fix = createBooleanProperty(fixation);
-            fix.setValue(((BooleanProperty)
-                origPg.getPropertyByName("fixation")).getValue().booleanValue());
-            fix.setWidth(30);
-
-            fix.addChangedHandler(new ChangedHandler() {
-                @Override
-                public void onChanged(ChangedEvent e) {
-                    if ((Boolean)e.getValue()) {
-                        range1.enable();
-                        range2.enable();
-                    }
-                    else {
-                        range1.disable();
-                        range2.disable();
-                    }
-                }
-            });
-            if (fix.getValue().toString().equals("true")) {
-                range1.enable();
-                range2.enable();
-            }
-            else {
-                range1.disable();
-                range2.disable();
-            }
-
             form1.setFields(title, fs);
-            form2.setFields(fix, range2, range1);
-
-            HLayout scaleLayout = new HLayout();
-            scaleLayout.setHeight(30);
-            scaleLayout.addMember(scale);
-            scaleLayout.addMember(form2);
-            scaleLayout.setStyleName("property-dialog-axis");
 
             VLayout root = new VLayout();
             root.addMember(form1);
-            root.addMember(scaleLayout);
             root.setHeight(90);
 
+
+            DoubleProperty upper =
+                (DoubleProperty)pg.getPropertyByName("upper");
+            DoubleProperty lower =
+                (DoubleProperty)pg.getPropertyByName("lower");
+
+            FormItem range1candidate = null;
+            FormItem range2candidate = null;
+            Layout scaleLayout;
+            DynamicForm form2 = new DynamicForm();
+
+            if (upper != null && lower != null) {
+                // Normal axis with double values
+                scaleLayout = new HLayout();
+                form2.setNumCols(6);
+                range1candidate = createDoubleProperty(upper);
+                range1candidate.setName("rangeupper");
+                range1candidate.setWidth(70);
+                range1candidate.setValue(
+                    ((DoubleProperty)
+                        origPg.getPropertyByName("upper")).toUIString());
+
+                range2candidate = createDoubleProperty(lower);
+                range2candidate.setName("rangelower");
+                range2candidate.setWidth(70);
+                range2candidate.setValue(
+                    ((DoubleProperty)
+                        origPg.getPropertyByName("lower")).toUIString());
+            } else {
+                // Time range axis
+                scaleLayout = new VLayout();
+                StringProperty dateUpper = (StringProperty)pg.getPropertyByName("upper-time");
+                StringProperty dateLower = (StringProperty)pg.getPropertyByName("lower-time");
+                if (dateUpper != null && dateLower != null) {
+                    DateItem lowerDI = createDateProperty(dateLower);
+                    DateItem upperDI = createDateProperty(dateUpper);
+                    StringProperty origUp = (StringProperty)origPg.getPropertyByName("upper-time");
+                    StringProperty origLow = (StringProperty)origPg.getPropertyByName("lower-time");
+                    try {
+                        lowerDI.setStartDate(new Date(-2208988800000L));
+                        lowerDI.setValue(new Date(Long.valueOf(origLow.getValue())));
+                        upperDI.setValue(new Date(Long.valueOf(origUp.getValue())));
+                    } catch (NumberFormatException e) {
+                        // Just leave it at default then.
+                    }
+                    range1candidate = upperDI;
+                    range2candidate = lowerDI;
+                }
+            }
+
+            if (range1candidate != null && range2candidate != null) {
+                final FormItem range1 = range1candidate;
+                final FormItem range2 = range2candidate;
+
+                BooleanProperty fixation =
+                    (BooleanProperty)pg.getPropertyByName("fixation");
+                FormItem fix = createBooleanProperty(fixation);
+                fix.setValue(((BooleanProperty)
+                    origPg.getPropertyByName("fixation")).getValue().booleanValue());
+                fix.setWidth(30);
+
+                fix.addChangedHandler(new ChangedHandler() {
+                    @Override
+                    public void onChanged(ChangedEvent e) {
+                        if ((Boolean)e.getValue()) {
+                            range1.enable();
+                            range2.enable();
+                        }
+                        else {
+                            range1.disable();
+                            range2.disable();
+                        }
+                    }
+                });
+                if (fix.getValue().toString().equals("true")) {
+                    range1.enable();
+                    range2.enable();
+                }
+                else {
+                    range1.disable();
+                    range2.disable();
+                }
+                form2.setFields(fix, range2, range1);
+                scaleLayout.setHeight(30);
+                scaleLayout.addMember(scale);
+                scaleLayout.addMember(form2);
+                scaleLayout.setStyleName("property-dialog-axis");
+                root.addMember(scaleLayout);
+            } else {
+                GWT.log("Invalid settings document. Without upper/lower.");
+            }
+
             return root;
         }
         return null;
@@ -458,6 +496,25 @@
         return item;
     }
 
+    protected DateItem createDateProperty(final StringProperty sp) {
+        String name = sp.getName();
+        if (name.contains("-")) {
+            name = name.replace("-", "_");
+        }
+
+        DateItem item = new DateItem(name, MSG.getString(name));
+        item.setTitleAlign(Alignment.LEFT);
+        item.setTitleStyle("color:#000;");
+
+        item.addBlurHandler(new BlurHandler() {
+            @Override
+            public void onBlur(BlurEvent e) {
+                DateItem di = (DateItem)e.getItem();
+                sp.setValue(Long.toString(di.getValueAsDate().getTime()));
+            }
+        });
+        return item;
+    }
 
     /**
      *

http://dive4elements.wald.intevation.org