Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSingleYearPanel.java @ 9066:b5d7a9d79837
uinfo.inundation_duration ui
author | gernotbelger |
---|---|
date | Fri, 11 May 2018 17:04:35 +0200 |
parents | b6919e3c2d86 |
children | 2b13de1b0897 |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSingleYearPanel.java Wed May 09 16:36:55 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSingleYearPanel.java Fri May 11 17:04:35 2018 +0200 @@ -11,24 +11,6 @@ import java.util.ArrayList; import java.util.List; -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.smartgwt.client.data.Record; -import com.smartgwt.client.types.ListGridFieldType; -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; -import com.smartgwt.client.widgets.form.fields.TextItem; -import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridField; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.grid.events.RecordClickHandler; -import com.smartgwt.client.widgets.grid.events.RecordClickEvent; - import org.dive4elements.river.client.client.Config; import org.dive4elements.river.client.client.FLYSConstants; import org.dive4elements.river.client.client.services.SedimentLoadInfoService; @@ -43,40 +25,55 @@ import org.dive4elements.river.client.shared.model.SedimentLoadInfoObject; import org.dive4elements.river.client.shared.model.SedimentLoadInfoRecord; +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.IntegerItem; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; -public class LoadSingleYearPanel -extends AbstractUIProvider -{ - protected SedimentLoadInfoServiceAsync sedLoadInfoService = - GWT.create(SedimentLoadInfoService.class); +public class LoadSingleYearPanel extends AbstractUIProvider { + protected SedimentLoadInfoServiceAsync sedLoadInfoService = GWT.create(SedimentLoadInfoService.class); // TODO: find right datasource + private static final String datakey = "singleyear"; protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - private TextItem yearsItem; + private TextItem inputItem; private ListGrid sedLoadTable; - protected List<String> validYears; + protected List<String> validInputs; - public LoadSingleYearPanel () { + public LoadSingleYearPanel() { } @Override - public Canvas createOld(DataList dataList) { - List<Data> items = dataList.getAll(); - Data years = getData(items, "years"); - DataItem[] yearsItems = years.getItems(); + public Canvas createOld(final DataList dataList) { + final List<Data> items = dataList.getAll(); + final Data item = getData(items, datakey); + final DataItem[] alreadySetItems = item.getItems(); - String v1 = yearsItems[0].getStringValue().replace(" ", ", "); + final String v1 = alreadySetItems[0].getStringValue().replace(" ", ", "); - Label old = new Label(v1); - HLayout layout = new HLayout(); + final Label old = new Label(v1); + final HLayout layout = new HLayout(); layout.setWidth("400px"); - Label label = new Label(dataList.getLabel()); + final Label label = new Label(dataList.getLabel()); label.setWidth("200px"); - Canvas back = getBackButton(dataList.getState()); + final Canvas back = getBackButton(dataList.getState()); layout.addMember(label); layout.addMember(old); @@ -91,14 +88,14 @@ } @Override - public Canvas create(DataList data) { - VLayout layout = new VLayout(); + public Canvas create(final DataList data) { + final VLayout layout = new VLayout(); - Canvas helper = createHelper(); + final Canvas helper = createHelper(); this.helperContainer.addMember(helper); - Canvas submit = getNextButton(); - Canvas widget = createWidget(data); + final Canvas submit = getNextButton(); + final Canvas widget = createWidget(data); layout.addMember(widget); layout.addMember(submit); @@ -109,54 +106,52 @@ } private Canvas createHelper() { - sedLoadTable = new ListGrid(); - sedLoadTable.setShowHeaderContextMenu(false); - sedLoadTable.setWidth100(); - sedLoadTable.setShowRecordComponents(true); - sedLoadTable.setShowRecordComponentsByCell(true); - sedLoadTable.setHeight100(); - sedLoadTable.setEmptyMessage(MSG.empty_table()); - sedLoadTable.setCanReorderFields(false); + this.sedLoadTable = new ListGrid(); + this.sedLoadTable.setShowHeaderContextMenu(false); + this.sedLoadTable.setWidth100(); + this.sedLoadTable.setShowRecordComponents(true); + this.sedLoadTable.setShowRecordComponentsByCell(true); + this.sedLoadTable.setHeight100(); + this.sedLoadTable.setEmptyMessage(this.MSG.empty_table()); + this.sedLoadTable.setCanReorderFields(false); - ListGridField date = new ListGridField("date", MSG.year()); + final ListGridField date = new ListGridField("date", this.MSG.year()); date.setType(ListGridFieldType.TEXT); date.setWidth(100); - ListGridField descr = - new ListGridField("description", MSG.description()); + final ListGridField descr = new ListGridField("description", this.MSG.description()); descr.setType(ListGridFieldType.TEXT); descr.setWidth("*"); - String baseUrl = GWT.getHostPageBaseURL(); - ListGridField pinFrom = new ListGridField( - "fromIcon", MESSAGES.selection()); - pinFrom.setWidth (60); - pinFrom.setType (ListGridFieldType.ICON); - pinFrom.setCellIcon(baseUrl + MESSAGES.markerGreen()); + final String baseUrl = GWT.getHostPageBaseURL(); + final ListGridField pinFrom = new ListGridField("fromIcon", this.MESSAGES.selection()); + pinFrom.setWidth(60); + pinFrom.setType(ListGridFieldType.ICON); + pinFrom.setCellIcon(baseUrl + this.MESSAGES.markerGreen()); - pinFrom.addRecordClickHandler (new RecordClickHandler () { + pinFrom.addRecordClickHandler(new RecordClickHandler() { @Override - public void onRecordClick (RecordClickEvent e) { - Record r = e.getRecord(); - appendYear(r.getAttribute("date")); + public void onRecordClick(final RecordClickEvent e) { + final Record r = e.getRecord(); + appendValue(r.getAttribute("date")); } }); - sedLoadTable.setFields(pinFrom, date, descr); - return sedLoadTable; + this.sedLoadTable.setFields(pinFrom, date, descr); + return this.sedLoadTable; } - public Canvas createWidget(DataList data) { - VLayout layout = new VLayout(); + public Canvas createWidget(final DataList data) { + final VLayout layout = new VLayout(); - Label title = new Label(data.get(0).getDescription()); + final Label title = new Label(data.get(0).getDescription()); title.setHeight("25px"); - DynamicForm form = new DynamicForm(); + final DynamicForm form = new DynamicForm(); form.setNumCols(4); - yearsItem = new TextItem(MSG.years()); - yearsItem.setValidators(new IsIntegerValidator()); - form.setFields(yearsItem); + this.inputItem = new IntegerItem(this.MSG.year()); + this.inputItem.setShowTitle(false); + form.setFields(this.inputItem); layout.addMember(title); layout.addMember(form); @@ -167,16 +162,12 @@ @Override protected Data[] getData() { validateYears(); - if (yearsItem != null && !yearsItem.getValueAsString().isEmpty()) { - List<Data> data = new ArrayList<Data>(); + if (this.inputItem != null && !this.inputItem.getValueAsString().isEmpty()) { + final List<Data> data = new ArrayList<Data>(); - DataItem yearsdata = new DefaultDataItem( - "years", "years", yearsItem.getValueAsString().trim()); - data.add(new DefaultData( - "years", - null, - null, - new DataItem[] { yearsdata })); + final DataItem yearsdata = new DefaultDataItem(datakey, datakey, this.inputItem.getValueAsString().trim()); // DATA-STRING: years (in + // uinfo.xml) + data.add(new DefaultData(datakey, null, null, new DataItem[] { yearsdata })); return data.toArray(new Data[data.size()]); } @@ -184,113 +175,106 @@ } protected List<String> validateYears() { - List<String> errors = new ArrayList<String>(); - NumberFormat nf = NumberFormat.getDecimalFormat(); + final List<String> errors = new ArrayList<String>(); + final NumberFormat nf = NumberFormat.getDecimalFormat(); - if (yearsItem.getValueAsString() == null || - yearsItem.getValueAsString().trim().isEmpty()) { - errors.add(MESSAGES.empty_filter()); + if (this.inputItem.getValueAsString() == null || this.inputItem.getValueAsString().trim().isEmpty()) { + errors.add(this.MESSAGES.empty_filter()); return errors; } - String [] sValues = yearsItem.getValueAsString().trim().split(" "); + final String sValue = this.inputItem.getValueAsString();// .trim().split(" "); String filtered = ""; int goodValues = 0; - for (String sValue: sValues) { - int value; - try { - value = Integer.parseInt(sValue); - } catch (NumberFormatException e) { - errors.add(MESSAGES.wrongFormat() + ": " + sValue); - continue; + + int value = 0; + try { + value = Integer.parseInt(sValue); + } + catch (final NumberFormatException e) { + errors.add(this.MESSAGES.wrongFormat() + ": " + sValue); + + } + boolean isGood = false; + for (final String validYear : this.validInputs) { + /* No list contains for strings? */ + if (sValue.equals(validYear)) { + isGood = true; + break; } - boolean isGood = false; - for (String validYear: validYears) { - /* No list contains for strings? */ - if (sValue.equals(validYear)) { - isGood = true; - break; - } - } - if (!isGood) { - String tmp = MESSAGES.no_data_for_year(); - tmp = tmp.replace("$1", sValue); - errors.add(tmp); - continue; - } - goodValues++; - if (goodValues > 1) { - filtered += " " + Integer.toString(value); - } else { - filtered = Integer.toString(value); - } + } + if (!isGood) { + String tmp = this.MESSAGES.no_data_for_year(); + tmp = tmp.replace("$1", sValue); + errors.add(tmp); + // continue; + } + goodValues++; + if (goodValues > 1) { + filtered += " " + Integer.toString(value); + } else { + filtered = Integer.toString(value); } return errors; } - protected void fetchSedimentLoadData() { - Config config = Config.getInstance(); - String locale = config.getLocale (); + protected void fetchSedimentLoadData() { + final Config config = Config.getInstance(); + final String locale = config.getLocale(); - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); + final ArtifactDescription adescr = this.artifact.getArtifactDescription(); + final DataList[] data = adescr.getOldData(); - double[] km = artifact.getArtifactDescription().getKMRange(); - String river = artifact.getArtifactDescription().getRiver(); + final double[] km = this.artifact.getArtifactDescription().getKMRange(); + final String river = this.artifact.getArtifactDescription().getRiver(); String sq_ti_id = ""; - validYears = new ArrayList<String>(data.length); - for (int i = 0; i < data.length; i++) { - Data str = getData(data[i].getAll(), "sq_ti_id"); + this.validInputs = new ArrayList<String>(data.length); + for (final DataList element : data) { + final Data str = getData(element.getAll(), "sq_ti_id"); if (str != null) { - DataItem[] strItems = str.getItems(); + final DataItem[] strItems = str.getItems(); sq_ti_id = strItems[0].getStringValue(); break; } } - if (sq_ti_id.isEmpty()){ + if (sq_ti_id.isEmpty()) { GWT.log("Failed to find sq time interval id in data."); } - sedLoadInfoService.getSedimentLoadInfo( - locale, river, "single", km[0], km[1], sq_ti_id, - new AsyncCallback<SedimentLoadInfoObject[]>() { - public void onFailure(Throwable caught) { - GWT.log("Could not recieve sediment load informations."); - SC.warn(MSG.getString(caught.getMessage())); + this.sedLoadInfoService.getSedimentLoadInfo(locale, river, "single", km[0], km[1], sq_ti_id, new AsyncCallback<SedimentLoadInfoObject[]>() { + @Override + public void onFailure(final Throwable caught) { + GWT.log("Could not recieve sediment load informations."); + SC.warn(LoadSingleYearPanel.this.MSG.getString(caught.getMessage())); + } + + @Override + public void onSuccess(final SedimentLoadInfoObject[] sedLoad) { + final int num = sedLoad != null ? sedLoad.length : 0; + GWT.log("Recieved " + num + " sediment load informations."); + + if (num == 0) { + return; } - public void onSuccess(SedimentLoadInfoObject[] sedLoad) { - int num = sedLoad != null ? sedLoad.length :0; - GWT.log("Recieved " + num + " sediment load informations."); - - if (num == 0) { - return; - } - - addSedimentLoadInfo(sedLoad); - } + addSedimentLoadInfo(sedLoad); } - ); + }); } - - protected void addSedimentLoadInfo (SedimentLoadInfoObject[] sedLoad) { - for(SedimentLoadInfoObject sl: sedLoad) { - SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); - sedLoadTable.addData(rec); - validYears.add(rec.getDate()); + protected void addSedimentLoadInfo(final SedimentLoadInfoObject[] sedLoad) { + for (final SedimentLoadInfoObject sl : sedLoad) { + final SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); + this.sedLoadTable.addData(rec); + this.validInputs.add(rec.getDate()); } } - protected void appendYear (String year) { - String oldYears = yearsItem.getValueAsString(); - if (oldYears != null && !oldYears.isEmpty()) { - yearsItem.setValue(oldYears.trim() + " " + year); - } else { - yearsItem.setValue(year); - } + protected void appendValue(final String year) { // SINGLE-Input + final String oldYears = this.inputItem.getValueAsString(); + this.inputItem.setValue(year); } }