Mercurial > dive4elements > river
changeset 9077:2b13de1b0897
moved single_year/multi_year common code to AbstractPanel
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/LoadMultipleEpochSelectState.java Tue May 22 11:58:30 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/LoadMultipleEpochSelectState.java Tue May 22 15:32:00 2018 +0200 @@ -40,9 +40,9 @@ @Override protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) { - + final String datakey = "epochs"; try { - if ("epochs".equals(name)) { + if (datakey.equals(name)) { final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); @@ -57,12 +57,8 @@ final Integer year = coll.getYear(); final Map<String, String> row = new HashMap<>(); row.put("year", year.toString()); // Nullpointer? - try { - helper.addRow(row); - } - catch (final Exception e) { - e.printStackTrace(); - } + helper.addRow(row); + } helper.submitMapToXml(); }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/LoadMultipleYearSelectState.java Tue May 22 11:58:30 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/LoadMultipleYearSelectState.java Tue May 22 15:32:00 2018 +0200 @@ -45,9 +45,10 @@ protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) { try { - if ("years".equals(name)) { + final String dataKeyofState = "years";// siehe sinfo.xml + if (dataKeyofState.equals(name)) { - final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); + final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); // "year" not to be confused with datakey helper.addColumn(0, "pinfrom", "60", "common.client.ui.selection", "ICON", "CENTER", "from"); helper.addColumn(1, "year", "60", "year", "INTEGER", "LEFT", null); @@ -59,12 +60,8 @@ final Integer year = coll.getYear(); final Map<String, String> row = new HashMap<>(); row.put("year", year.toString()); // Nullpointer? - try { - helper.addRow(row); - } - catch (final Exception e) { - e.printStackTrace(); - } + helper.addRow(row); + } helper.submitMapToXml(); }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/AddTableDataHelper.java Tue May 22 11:58:30 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/AddTableDataHelper.java Tue May 22 15:32:00 2018 +0200 @@ -64,7 +64,7 @@ } - public void addRow(final Map<String, String> colValMap) throws Exception { + public void addRow(final Map<String, String> colValMap) { final Element item = this.creator.create("item"); @@ -72,7 +72,12 @@ if (this.meta.containsKey(entry.getKey())) { this.creator.addAttr(item, entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : ""); } else { - throw new Exception("Error: No such column " + entry.getKey()); + try { + throw new Exception("Error: No such column " + entry.getKey()); + } + catch (final Exception e) { + e.printStackTrace(); + } } } this.select.appendChild(item);
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/LoadSingleYearSelectState.java Tue May 22 11:58:30 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/LoadSingleYearSelectState.java Tue May 22 15:32:00 2018 +0200 @@ -8,8 +8,19 @@ package org.dive4elements.river.artifacts.states; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.log4j.Logger; import org.dive4elements.artifacts.Artifact; +import org.dive4elements.artifacts.CallContext; +import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.access.RiverAccess; +import org.dive4elements.river.artifacts.model.CollisionHibernateFactory; +import org.dive4elements.river.model.sinfo.Collision; +import org.w3c.dom.Element; /** State in which to fetch years for sedminent load calculation. */ public class LoadSingleYearSelectState extends DefaultState { @@ -30,6 +41,38 @@ } @Override + protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) { + final String dataKey = "singleyear"; + try { + if (dataKey.equals(name)) { + + final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); // pinKeycolum; nicht zu verweschseln mit + // datakey..artifact. + + helper.addColumn(0, "pinfrom", "60", "common.client.ui.selection", "ICON", "CENTER", "from"); + helper.addColumn(1, "year", "60", "year", "INTEGER", "LEFT", null); + + final RiverAccess access = new RiverAccess((D4EArtifact) artifact); + final List<Collision> collisions = CollisionHibernateFactory.getCollisionsByRiver(access.getRiver());// TODO: DATASOURCE?! Has to be + // uinfo.inundation_duration + // (Überflutungsdauern Aue) irgendwas... + + for (final Collision coll : collisions) { + final Integer year = coll.getYear(); + final Map<String, String> row = new HashMap<>(); + row.put("year", year.toString()); // Nullpointer? + helper.addRow(row); + + } + helper.submitMapToXml(); + } + } + catch (final IllegalArgumentException iae) { + iae.printStackTrace(); + } + } + + @Override public boolean validate(final Artifact artifact) throws IllegalArgumentException { return true; // final CollisionLoadYearEpochAccess access = new CollisionLoadYearEpochAccess((D4EArtifact) artifact); @@ -41,5 +84,4 @@ // // return true; } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : +} \ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/CollisionLoadYearPanel.java Tue May 22 11:58:30 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/CollisionLoadYearPanel.java Tue May 22 15:32:00 2018 +0200 @@ -8,182 +8,25 @@ package org.dive4elements.river.client.client.ui.sinfo; -import java.util.ArrayList; -import java.util.List; - -import org.dive4elements.river.client.client.FLYSConstants; -import org.dive4elements.river.client.client.ui.AbstractUIProvider; -import org.dive4elements.river.client.client.ui.FromToTableHelperPanel; -import org.dive4elements.river.client.client.ui.FromToTableHelperPanel.IColumnClickHandler; -import org.dive4elements.river.client.shared.model.Data; -import org.dive4elements.river.client.shared.model.DataItem; -import org.dive4elements.river.client.shared.model.DataList; -import org.dive4elements.river.client.shared.model.DefaultData; -import org.dive4elements.river.client.shared.model.DefaultDataItem; +import org.dive4elements.river.client.client.ui.AbstractPanel; -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; -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.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; +public class CollisionLoadYearPanel extends AbstractPanel { -public class CollisionLoadYearPanel extends AbstractUIProvider { - - private final FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - private TextItem yearsItem; - - private List<String> validYears = new ArrayList<String>(); - - private ListGrid table; + @Override + protected String getDatakey() { + return "years"; // MULTIPLE; get From server (sinfo.xml data for state) + } public CollisionLoadYearPanel() { } @Override - public Canvas createOld(final DataList dataList) { - final List<Data> items = dataList.getAll(); - final Data years = getData(items, "years"); - final DataItem[] yearsItems = years.getItems(); - - final String v1 = yearsItems[0].getStringValue().replace(" ", ", "); - - final Label old = new Label(v1); - final HLayout layout = new HLayout(); - layout.setWidth("400px"); - - final Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - final Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(old); - layout.addMember(back); - - return layout; - } - - @Override - public List<String> validate() { - return validateYears(); - } - - @Override - public Canvas create(final DataList data) { - final VLayout layout = new VLayout(); - final IColumnClickHandler fromHandler = new IColumnClickHandler() { // add to external class - - @Override - public void columnClicked(final String value) { - appendYear(value); - } - }; - - final FromToTableHelperPanel helper = new FromToTableHelperPanel(data, "years", this.MSG, fromHandler, null); - final Canvas table = helper.getTable(); - this.validYears = helper.getKeycolEntries(); - - this.helperContainer.addMember(table); - - final Canvas submit = getNextButton(); - final Canvas widget = createWidget(data); - - layout.addMember(widget); - layout.addMember(submit); - - return layout; - } - - public Canvas createWidget(final DataList data) { - final VLayout layout = new VLayout(); - - final Label title = new Label(data.get(0).getDescription()); - title.setHeight("25px"); - - final DynamicForm form = new DynamicForm(); - form.setNumCols(4); - this.yearsItem = new TextItem(this.MSG.years()); - this.yearsItem.setValidators(new IsIntegerValidator()); - form.setFields(this.yearsItem); // TODO: move to helper - - layout.addMember(title); - layout.addMember(form); - - return layout; - } - - @Override - protected Data[] getData() { - validateYears(); - if (this.yearsItem != null && !this.yearsItem.getValueAsString().isEmpty()) { - final List<Data> data = new ArrayList<Data>(); - - final DataItem yearsdata = new DefaultDataItem("years", "years", this.yearsItem.getValueAsString().trim()); - data.add(new DefaultData("years", null, null, new DataItem[] { yearsdata })); - - return data.toArray(new Data[data.size()]); - } - return new Data[0]; - } - - private List<String> validateYears() { - final List<String> errors = new ArrayList<String>(); - final NumberFormat nf = NumberFormat.getDecimalFormat(); - - if (this.yearsItem.getValueAsString() == null || this.yearsItem.getValueAsString().trim().isEmpty()) { - errors.add(this.MESSAGES.empty_filter()); - return errors; - } - - final String[] sValues = this.yearsItem.getValueAsString().trim().split(" "); - String filtered = ""; - int goodValues = 0; - for (final String sValue : sValues) { - int value; - try { - value = Integer.parseInt(sValue); - } - catch (final NumberFormatException e) { - errors.add(this.MESSAGES.wrongFormat() + ": " + sValue); - continue; - } - boolean isGood = false; - for (final String validYear : this.validYears) { - /* No list contains for strings? */ - if (sValue.equals(validYear)) { - isGood = true; - break; - } - } - 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 final void appendYear(final String year) { - final String oldYears = this.yearsItem.getValueAsString(); + protected final void appendValue(final String value) { // APPEND = ADD to existing -> MULTI YEAR + final String oldYears = super.inputItem.getValueAsString(); if (oldYears != null && !oldYears.isEmpty()) { - this.yearsItem.setValue(oldYears.trim() + " " + year); + super.inputItem.setValue(oldYears.trim() + " " + value); } else { - this.yearsItem.setValue(year); + super.inputItem.setValue(value); } } }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSingleYearPanel.java Tue May 22 11:58:30 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSingleYearPanel.java Tue May 22 15:32:00 2018 +0200 @@ -8,271 +8,19 @@ package org.dive4elements.river.client.client.ui.uinfo; -import java.util.ArrayList; -import java.util.List; - -import org.dive4elements.river.client.client.Config; -import org.dive4elements.river.client.client.FLYSConstants; -import org.dive4elements.river.client.client.services.SedimentLoadInfoService; -import org.dive4elements.river.client.client.services.SedimentLoadInfoServiceAsync; -import org.dive4elements.river.client.client.ui.AbstractUIProvider; -import org.dive4elements.river.client.shared.model.ArtifactDescription; -import org.dive4elements.river.client.shared.model.Data; -import org.dive4elements.river.client.shared.model.DataItem; -import org.dive4elements.river.client.shared.model.DataList; -import org.dive4elements.river.client.shared.model.DefaultData; -import org.dive4elements.river.client.shared.model.DefaultDataItem; -import org.dive4elements.river.client.shared.model.SedimentLoadInfoObject; -import org.dive4elements.river.client.shared.model.SedimentLoadInfoRecord; +import org.dive4elements.river.client.client.ui.AbstractPanel; -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 AbstractPanel { -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 inputItem; - - private ListGrid sedLoadTable; - - protected List<String> validInputs; + @Override + protected String getDatakey() { + return "singleyear"; + } public LoadSingleYearPanel() { } @Override - public Canvas createOld(final DataList dataList) { - final List<Data> items = dataList.getAll(); - final Data item = getData(items, datakey); - final DataItem[] alreadySetItems = item.getItems(); - - final String v1 = alreadySetItems[0].getStringValue().replace(" ", ", "); - - final Label old = new Label(v1); - final HLayout layout = new HLayout(); - layout.setWidth("400px"); - - final Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - - final Canvas back = getBackButton(dataList.getState()); - - layout.addMember(label); - layout.addMember(old); - layout.addMember(back); - - return layout; - } - - @Override - public List<String> validate() { - return validateYears(); - } - - @Override - public Canvas create(final DataList data) { - final VLayout layout = new VLayout(); - - final Canvas helper = createHelper(); - this.helperContainer.addMember(helper); - - final Canvas submit = getNextButton(); - final Canvas widget = createWidget(data); - - layout.addMember(widget); - layout.addMember(submit); - - fetchSedimentLoadData(); - - return layout; - } - - private Canvas createHelper() { - 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); - - final ListGridField date = new ListGridField("date", this.MSG.year()); - date.setType(ListGridFieldType.TEXT); - date.setWidth(100); - - final ListGridField descr = new ListGridField("description", this.MSG.description()); - descr.setType(ListGridFieldType.TEXT); - descr.setWidth("*"); - - 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() { - @Override - public void onRecordClick(final RecordClickEvent e) { - final Record r = e.getRecord(); - appendValue(r.getAttribute("date")); - } - }); - - this.sedLoadTable.setFields(pinFrom, date, descr); - return this.sedLoadTable; - } - - public Canvas createWidget(final DataList data) { - final VLayout layout = new VLayout(); - - final Label title = new Label(data.get(0).getDescription()); - title.setHeight("25px"); - - final DynamicForm form = new DynamicForm(); - form.setNumCols(4); - this.inputItem = new IntegerItem(this.MSG.year()); - this.inputItem.setShowTitle(false); - form.setFields(this.inputItem); - - layout.addMember(title); - layout.addMember(form); - - return layout; - } - - @Override - protected Data[] getData() { - validateYears(); - if (this.inputItem != null && !this.inputItem.getValueAsString().isEmpty()) { - final List<Data> data = new ArrayList<Data>(); - - 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()]); - } - return new Data[0]; - } - - protected List<String> validateYears() { - final List<String> errors = new ArrayList<String>(); - final NumberFormat nf = NumberFormat.getDecimalFormat(); - - if (this.inputItem.getValueAsString() == null || this.inputItem.getValueAsString().trim().isEmpty()) { - errors.add(this.MESSAGES.empty_filter()); - return errors; - } - - final String sValue = this.inputItem.getValueAsString();// .trim().split(" "); - String filtered = ""; - int goodValues = 0; - - 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; - } - } - 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() { - final Config config = Config.getInstance(); - final String locale = config.getLocale(); - - final ArtifactDescription adescr = this.artifact.getArtifactDescription(); - final DataList[] data = adescr.getOldData(); - - final double[] km = this.artifact.getArtifactDescription().getKMRange(); - final String river = this.artifact.getArtifactDescription().getRiver(); - - String 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) { - final DataItem[] strItems = str.getItems(); - sq_ti_id = strItems[0].getStringValue(); - break; - } - } - - if (sq_ti_id.isEmpty()) { - GWT.log("Failed to find sq time interval id in data."); - } - - 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; - } - - addSedimentLoadInfo(sedLoad); - } - }); - } - - 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 appendValue(final String year) { // SINGLE-Input final String oldYears = this.inputItem.getValueAsString(); this.inputItem.setValue(year);