[PATCH 2 of 4] issue1542: Only show year of date for mainvalues validity, refactoring
Wald Commits
scm-commit at wald.intevation.org
Wed Nov 20 11:05:51 CET 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1384941806 -3600
# Node ID 1f2f64d244fc57420e48b3f0ce6c1f4b6d39ff06
# Parent 1244db8cd1d906c605b1b7bb27a9a8fd55fe90ef
issue1542: Only show year of date for mainvalues validity, refactoring.
diff -r 1244db8cd1d9 -r 1f2f64d244fc gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/WTable.java
--- 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.
More information about the Dive4elements-commits
mailing list