changeset 7588:1f2f64d244fc

issue1542: Only show year of date for mainvalues validity, refactoring.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 20 Nov 2013 11:03:26 +0100
parents 1244db8cd1d9
children a64ed9f067c6
files gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/WTable.java
diffstat 1 files changed, 29 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/WTable.java	Wed Nov 20 11:02:55 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/WTable.java	Wed Nov 20 11:03:26 2013 +0100
@@ -8,7 +8,10 @@
 
 package org.dive4elements.river.client.client.ui.wq;
 
+import java.util.Date;
+
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.DateTimeFormat;
 import com.google.gwt.i18n.client.NumberFormat;
 
 import com.smartgwt.client.types.ListGridFieldType;
@@ -51,13 +54,9 @@
         type.setType(ListGridFieldType.TEXT);
         type.setWidth("50");
 
-        ListGridField startTime = new ListGridField("starttime", MESSAGE.starttime());
-        startTime.setType(ListGridFieldType.DATE);
-        startTime.setWidth("60");
+        ListGridField startTime = createYearListGridField("starttime", MESSAGE.starttime());
 
-        ListGridField stopTime = new ListGridField("stoptime", MESSAGE.stoptime());
-        stopTime.setType(ListGridFieldType.DATE);
-        stopTime.setWidth("60");
+        ListGridField stopTime = createYearListGridField("stoptime", MESSAGE.stoptime());
 
         final NumberFormat nf = NumberFormat.getDecimalFormat();
 
@@ -93,6 +92,30 @@
         showField("select");
     }
 
+    public static ListGridField createYearListGridField(
+        final String propertyName, String displayName) {
+        ListGridField listGridField = new ListGridField(propertyName, displayName);
+        listGridField.setType(ListGridFieldType.DATE);
+        listGridField.setWidth("60");
+        listGridField.setCellFormatter(createYearDateFormatter(propertyName));
+        return listGridField;
+    }
+
+    /** Create CellFormatter that prints just the year of a date stored in attributeName. */
+    private static CellFormatter createYearDateFormatter(final String attributeName) {
+        return new CellFormatter() {
+            @Override
+            public String format(Object arg0, ListGridRecord record, int arg2, int arg3) {
+                Date date = record.getAttributeAsDate(attributeName);
+                if (date == null) {
+                    return "";
+                }
+                DateTimeFormat fmt = DateTimeFormat.getFormat("yyyy");
+                return fmt.format(date);
+            }
+        };
+    }
+
 
     /**
      * Search all records for one with attribute name equals to given name.

http://dive4elements.wald.intevation.org