Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTimeRangePanel.java @ 2894:fe0dc03f3158
Added i18n stubs for fix analyses to continue working with the GUI.
flys-client/trunk@4617 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 07 Jun 2012 07:27:57 +0000 |
parents | 8d27d2d33d70 |
children | 0cc2c3d89a9d |
line wrap: on
line source
package de.intevation.flys.client.client.ui; import java.util.List; import java.util.ArrayList; import java.util.Date; 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; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.CellFormatter; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.grid.events.RecordClickHandler; import com.smartgwt.client.widgets.grid.events.RecordClickEvent; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.shared.model.DataList; 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 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(); yearTable.setAutoFetchData(true); yearTable.setShowHeaderContextMenu(false); } public Canvas create(DataList data) { setDataName(data); VLayout root = new VLayout(); root.addMember(createLabel(data)); root.addMember(createForm(data)); root.addMember(getNextButton()); initDefaults(data); initYearTable(); long gauge = getGaugeNumber(); Config config = Config.getInstance(); String url = config.getServerUrl(); yearTable.setDataSource(new DischargeInfoDataSource(url, gauge)); helperContainer.addMember(yearTable); return root; } @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(); yearTable.setWidth100(); yearTable.setHeight100(); yearTable.setShowRecordComponents(true); yearTable.setShowRecordComponentsByCell(true); yearTable.setEmptyMessage(MESSAGES.empty_filter()); yearTable.setCanReorderFields(false); CellFormatter cf = new CellFormatter() { public String format( Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) return null; if (value.toString().equals("-1")) { return ""; } return value.toString(); } }; ListGridField addstart = new ListGridField ("", ""); addstart.setType (ListGridFieldType.ICON); addstart.setWidth (20); addstart.setCellIcon(baseUrl + MESSAGES.markerGreen()); addstart.addRecordClickHandler(new RecordClickHandler() { public void onRecordClick(RecordClickEvent e) { Record r = e.getRecord(); if (r.getAttribute("start").equals("-1")) { return; } else { setLower(r.getAttribute("start")); } } }); ListGridField addend = new ListGridField ("", ""); addend.setType (ListGridFieldType.ICON); addend.setWidth (20); addend.setCellIcon(baseUrl + MESSAGES.markerRed()); addend.addRecordClickHandler(new RecordClickHandler() { public void onRecordClick(RecordClickEvent e) { Record r = e.getRecord(); if (r.getAttribute("end").equals("-1")) { return; } else { setUpper(r.getAttribute("end")); } } }); ListGridField desc = new ListGridField("description", MESSAGES.description()); desc.setType(ListGridFieldType.TEXT); desc.setWidth("*"); ListGridField start = new ListGridField("start", MESSAGES.start_year()); start.setType(ListGridFieldType.INTEGER); start.setWidth(50); start.setCellFormatter(cf); ListGridField end = new ListGridField("end", MESSAGES.end_year()); end.setType(ListGridFieldType.INTEGER); end.setWidth(50); end.setCellFormatter(cf); yearTable.setFields(addstart, addend, desc, start, end); return yearTable; } protected long getGaugeNumber() { ArtifactDescription adescr = artifact.getArtifactDescription(); DataList[] data = adescr.getOldData(); String gauge = ""; if (data != null && data.length > 0) { for (int i = 0; i < data.length; i++) { DataList dl = data[i]; if (dl.getState().equals("state.winfo.historicalq.reference_gauge")) { for (int j = 0; j < dl.size(); j++) { Data d = dl.get(j); DataItem[] di = d.getItems(); if (di != null && di.length == 1) { gauge = d.getItems()[0].getStringValue(); } } } } } try { return Long.parseLong(gauge); } catch (NumberFormatException nfe) { GWT.log("Error parsing gauge."); 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; } }