comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/WTable.java @ 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 a52b820c9006
comparison
equal deleted inserted replaced
7587:1244db8cd1d9 7588:1f2f64d244fc
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.client.client.ui.wq; 9 package org.dive4elements.river.client.client.ui.wq;
10 10
11 import java.util.Date;
12
11 import com.google.gwt.core.client.GWT; 13 import com.google.gwt.core.client.GWT;
14 import com.google.gwt.i18n.client.DateTimeFormat;
12 import com.google.gwt.i18n.client.NumberFormat; 15 import com.google.gwt.i18n.client.NumberFormat;
13 16
14 import com.smartgwt.client.types.ListGridFieldType; 17 import com.smartgwt.client.types.ListGridFieldType;
15 import com.smartgwt.client.types.SelectionStyle; 18 import com.smartgwt.client.types.SelectionStyle;
16 import com.smartgwt.client.widgets.grid.CellFormatter; 19 import com.smartgwt.client.widgets.grid.CellFormatter;
49 52
50 ListGridField type = new ListGridField("type", MESSAGE.type()); 53 ListGridField type = new ListGridField("type", MESSAGE.type());
51 type.setType(ListGridFieldType.TEXT); 54 type.setType(ListGridFieldType.TEXT);
52 type.setWidth("50"); 55 type.setWidth("50");
53 56
54 ListGridField startTime = new ListGridField("starttime", MESSAGE.starttime()); 57 ListGridField startTime = createYearListGridField("starttime", MESSAGE.starttime());
55 startTime.setType(ListGridFieldType.DATE);
56 startTime.setWidth("60");
57 58
58 ListGridField stopTime = new ListGridField("stoptime", MESSAGE.stoptime()); 59 ListGridField stopTime = createYearListGridField("stoptime", MESSAGE.stoptime());
59 stopTime.setType(ListGridFieldType.DATE);
60 stopTime.setWidth("60");
61 60
62 final NumberFormat nf = NumberFormat.getDecimalFormat(); 61 final NumberFormat nf = NumberFormat.getDecimalFormat();
63 62
64 ListGridField value = new ListGridField("value", MESSAGE.wq_value_w()); 63 ListGridField value = new ListGridField("value", MESSAGE.wq_value_w());
65 value.setType(ListGridFieldType.FLOAT); 64 value.setType(ListGridFieldType.FLOAT);
91 90
92 public void showSelect() { 91 public void showSelect() {
93 showField("select"); 92 showField("select");
94 } 93 }
95 94
95 public static ListGridField createYearListGridField(
96 final String propertyName, String displayName) {
97 ListGridField listGridField = new ListGridField(propertyName, displayName);
98 listGridField.setType(ListGridFieldType.DATE);
99 listGridField.setWidth("60");
100 listGridField.setCellFormatter(createYearDateFormatter(propertyName));
101 return listGridField;
102 }
103
104 /** Create CellFormatter that prints just the year of a date stored in attributeName. */
105 private static CellFormatter createYearDateFormatter(final String attributeName) {
106 return new CellFormatter() {
107 @Override
108 public String format(Object arg0, ListGridRecord record, int arg2, int arg3) {
109 Date date = record.getAttributeAsDate(attributeName);
110 if (date == null) {
111 return "";
112 }
113 DateTimeFormat fmt = DateTimeFormat.getFormat("yyyy");
114 return fmt.format(date);
115 }
116 };
117 }
118
96 119
97 /** 120 /**
98 * Search all records for one with attribute name equals to given name. 121 * Search all records for one with attribute name equals to given name.
99 * @return null if none found. 122 * @return null if none found.
100 * */ 123 * */

http://dive4elements.wald.intevation.org