Mercurial > dive4elements > river
changeset 2468:6a65694bdcc2
Issue 506.
Gauge time range panel now accepts dates. The dates are stored as long values.
flys-client/trunk@4176 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 20 Mar 2012 14:53:42 +0000 |
parents | 070321cf17e1 |
children | 505e68d8d131 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTimeRangePanel.java flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java flys-client/src/main/java/de/intevation/flys/client/shared/model/LongRangeData.java |
diffstat | 8 files changed, 334 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Tue Mar 20 12:59:25 2012 +0000 +++ b/flys-client/ChangeLog Tue Mar 20 14:53:42 2012 +0000 @@ -1,3 +1,22 @@ +2012-03-20 Raimund Renkert <raimund.renkert@intevation.de> + + Issue 506. + + * src/main/java/de/intevation/flys/client/client/ui/GaugeTimeRangePanel.java: + The Panel now accepts dates and has a date chooser. + + * src/main/java/de/intevation/flys/client/shared/model/LongRangeData.java: + New. Datatype for long values. Used to store dates in ms. + + * src/main/java/de/intevation/flys/client/server/DataFactory.java: + Added method to create LongRangeData objects. + + * src/main/java/de/intevation/flys/client/client/FLYSConstants.java, + src/main/java/de/intevation/flys/client/client/FLYSConstants.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties: + Added i18n string for error message. + 2012-03-20 Ingo Weinzierl <ingo@intevation.de> flys/issue544 (Historische ATs: Eingabeunterstützung W/Q)
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Tue Mar 20 12:59:25 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Tue Mar 20 14:53:42 2012 +0000 @@ -449,6 +449,8 @@ String error_validate_range(); + String error_validate_date_range(); + String error_validate_lower_range(); String error_validate_upper_range();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Tue Mar 20 12:59:25 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Tue Mar 20 14:53:42 2012 +0000 @@ -228,6 +228,7 @@ unexpected_exception = There occured an unexpected exception error_read_minmax_values = Error while reading min/max values for the location input. error_validate_range = The value $1 needs to be smaller than $3 and bigger than $2. +error_validate_date_range = Start date needs to be before end date. error_validate_lower_range = The lower value $1 needs to be bigger than $2. error_validate_upper_range = The upper value $1 needs to be smaller than $2. error_empty_state = Required inputs are missing.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Tue Mar 20 12:59:25 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Tue Mar 20 14:53:42 2012 +0000 @@ -228,6 +228,7 @@ unexpected_exception = Ein unerwarteter Fehler ist aufgetreten error_read_minmax_values = Fehler beim Lesen der min/max Werte. Es kann keine Validierung der eingegebenen Strecke durchgef\u00fchrt werden. error_validate_range = Der Wert $1 muss kleiner als $3 und gr\u00f6\u00dfer als $2 sein. +error_validate_date_range = Anfangsdatum muss früher sein als Enddatum. error_validate_lower_range = Der untere Wert $1 muss gr\u00f6\u00dfer sein als $2. error_validate_upper_range = Der obere Wert $1 muss kleiner sein als $2. error_empty_state = Es wurden nicht alle ben\u00d6tigten Daten eingegeben.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Tue Mar 20 12:59:25 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Tue Mar 20 14:53:42 2012 +0000 @@ -226,6 +226,7 @@ unexpected_exception = There occured an unexpected exception error_read_minmax_values = Error while reading min/max values for the location input. error_validate_range = The value $1 needs to be smaller than $3 and bigger than $2. +error_validate_date_range = Start date needs to be before end date. error_validate_lower_range = The lower value $1 needs to be bigger than $2. error_validate_upper_range = The upper value $1 needs to be smaller than $2. error_empty_state = Required inputs are missing.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTimeRangePanel.java Tue Mar 20 12:59:25 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTimeRangePanel.java Tue Mar 20 14:53:42 2012 +0000 @@ -1,10 +1,21 @@ package de.intevation.flys.client.client.ui; +import java.util.List; +import java.util.ArrayList; +import java.util.Date; +import java.util.Calendar; +import java.text.ParseException; + import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; import com.smartgwt.client.types.ListGridFieldType; import com.smartgwt.client.data.Record; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.DateRangeItem; +import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.Canvas; @@ -22,19 +33,23 @@ import de.intevation.flys.client.shared.model.DataItem; import de.intevation.flys.client.shared.model.ArtifactDescription; import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.RangeData; +import de.intevation.flys.client.shared.model.LongRangeData; import de.intevation.flys.client.client.ui.range.DischargeInfoDataSource; /** * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class GaugeTimeRangePanel extends IntegerRangePanel { +public class GaugeTimeRangePanel extends RangePanel { /** The message class that provides i18n strings. */ protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); protected ListGrid yearTable; + protected DateRangeItem dateRange; + public GaugeTimeRangePanel() { GWT.log("Creating YearInputPanel"); yearTable = new ListGrid(); @@ -68,6 +83,127 @@ } + @Override + protected void initDefaults(DataList dataList) { + RangeData data = findRangeData(dataList); + + if(data != null) { + GWT.log("data: " + data); + } + } + + + @Override + public Canvas createOld(DataList dataList) { + GWT.log("create old date."); + Data data = dataList.get(0); + DataItem[] items = data.getItems(); +GWT.log(data.getClass().toString()); + HLayout layout = new HLayout(); + + Label label = new Label(dataList.getLabel()); + label.setWidth(200); + label.setHeight(20); + + Date dl = new Date((Long)((LongRangeData)data).getLower()); + Date du = new Date((Long)((LongRangeData)data).getUpper()); + DateTimeFormat dtf = DateTimeFormat.getMediumDateFormat(); + Label value = new Label(dtf.format(dl) + " - " + dtf.format(du)); + value.setHeight(20); + + layout.addMember(label); + layout.addMember(value); + layout.addMember(getBackButton(dataList.getState())); + + return layout; + } + + + @Override + protected Data[] getData() { + long lo = getLowerAsLong(); + long up = getUpperAsLong(); + + return new Data[] { new LongRangeData(getDataName(), null, lo, up) }; + } + + + @Override + protected Canvas createForm(DataList dataList) { + HLayout layout = new HLayout(); + DynamicForm form = new DynamicForm(); + dateRange = new DateRangeItem(); + dateRange.setToTitle(MESSAGES.to()); + dateRange.setFromTitle(MESSAGES.from()); + dateRange.setShowTitle(false); + form.setFields(dateRange); + + layout.addMember(form); + return layout; + + } + + + @Override + public Object getMaxLower() { + Date d = dateRange.getFromDate(); + return new Long(d.getTime()); + } + + + protected long getLowerAsLong() { + Date d = dateRange.getFromDate(); + return d.getTime(); + } + + + protected long getUpperAsLong() { + Date d = dateRange.getToDate(); + return d.getTime(); + } + + + @Override + public Object getMaxUpper() { + Date d = dateRange.getToDate(); + return new Long(d.getTime()); + } + + + @Override + public void setLower(String lower) { + try { + DateTimeFormat dtf = + DateTimeFormat.getFormat("yyyy"); + Date dy = dtf.parse(lower); + dy.setMonth(0); + dy.setDate(1); + dateRange.setFromDate(dy); + } + catch(IllegalArgumentException iae) { + GWT.log("could not parse lower date."); + //TODO: Messagebox with error. + } + } + + + @Override + public void setUpper(String upper) { + try { + DateTimeFormat dtf = + DateTimeFormat.getFormat("yyyy"); + Date dy = dtf.parse(upper); + dy.setMonth(0); + dy.setDate(1); + dateRange.setToDate(dy); + } + catch(IllegalArgumentException iae) { + GWT.log("could not parse upper date."); + //TODO: Messagebox with error. + } + } + + protected ListGrid initYearTable() { String baseUrl = GWT.getHostPageBaseURL(); @@ -174,4 +310,18 @@ return 0; } } + + + @Override + public List<String> validate() { + List<String> errors = new ArrayList<String>(); + if (dateRange.getFromDate() == null || + dateRange.getToDate() == null || + !dateRange.getFromDate().before(dateRange.getToDate())) + { + String msg = MSG.error_validate_date_range(); + errors.add(msg); + } + return errors; + } }
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java Tue Mar 20 12:59:25 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java Tue Mar 20 14:53:42 2012 +0000 @@ -20,6 +20,7 @@ import de.intevation.flys.client.shared.model.IntegerOptionsData; import de.intevation.flys.client.shared.model.IntegerRangeData; import de.intevation.flys.client.shared.model.StringData; +import de.intevation.flys.client.shared.model.LongRangeData; /** @@ -71,6 +72,9 @@ else if (type.equals(DoubleArrayData.TYPE)) { return createDoubleArrayData(element, name); } + else if (type.equals(LongRangeData.TYPE)) { + return createLongRangeData(element, name); + } else { return createDefaultData(element, name); } @@ -255,5 +259,29 @@ return items; } + + + /** + * This method creates a new instance of LongRangeData which has a type + * "longrange" set. + * + * @param ele The Data element. + * @param name The name of the Data instance. + * + * @return an instance of IntegerRangeData. + */ + protected static Data createLongRangeData(Element ele, String name) { + DataItem[] items = extractDataItems(ele); + String rawValue = items[0].getStringValue(); + + String[] minmax = rawValue.split(";"); + + return new LongRangeData( + name, + name, + Long.valueOf(minmax[0]), + Long.valueOf(minmax[1])); + } + } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/LongRangeData.java Tue Mar 20 14:53:42 2012 +0000 @@ -0,0 +1,131 @@ +package de.intevation.flys.client.shared.model; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class LongRangeData implements RangeData { + + public static final String TYPE = "longrange"; + + + protected String label; + protected String description; + + protected long lower; + protected long upper; + + protected Long defLower; + protected Long defUpper; + + + public LongRangeData() { + } + + + public LongRangeData(String label, String desc, long lower, long upper) { + this(label, desc, lower, upper, null, null); + } + + + /** + * @param label + * @param desc + * @param lower + * @param upper + * @param defLower + * @param defUpper + */ + public LongRangeData( + String label, + String desc, + long lower, + long upper, + Long defLower, + Long defUpper + ) { + this.label = label; + this.description = desc; + this.lower = lower; + this.upper = upper; + this.defLower = defLower; + this.defUpper = defUpper; + } + + + /** + * Returns the label of the item. + * + * @return the label. + */ + public String getLabel() { + return label; + } + + + /** + * Returns the description of the item. + * + * @return the description. + */ + public String getDescription() { + return description; + } + + + /** + * Returns the type of the item. + * + * @return the type. + */ + public String getType() { + return "longrange"; + } + + + /** + * Returns a DataItem which value is a string that consists of the min and + * max value separated by a ';'. + * + * @return the DataItem. + */ + public DataItem[] getItems() { + String theMin = String.valueOf(lower); + String theMax = String.valueOf(upper); + + String label = theMin + " - " + theMax; + String value = theMin + ";" + theMax; + + DataItem item = new DefaultDataItem(label, label, value); + + return new DataItem[] { item }; + } + + + /** + * @return always null. + */ + public DataItem getDefault() { + return null; + } + + + public Object getLower() { + return lower; + } + + + public Object getUpper() { + return upper; + } + + + public Object getDefaultLower() { + return defLower; + } + + + public Object getDefaultUpper() { + return defUpper; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :