Mercurial > dive4elements > river
changeset 9256:6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/LoadSingleYearSelectState.java Fri Jul 13 12:04:21 2018 +0200 @@ -0,0 +1,89 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.artifacts.bundu.bezugswst; + +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.artifacts.states.AddTableDataHelper; +import org.dive4elements.river.artifacts.states.DefaultState; +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 { + private static final long serialVersionUID = 1L; + /** The log used in this class. */ + private static Logger log = Logger.getLogger(LoadSingleYearSelectState.class); + + /** + * The default constructor that initializes an empty State object. + */ + public LoadSingleYearSelectState() { + } + + /** Year Select Widget. */ + @Override + protected String getUIProvider() { + return "common.state.load_single_year_select.show_hint"; + } + + @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-Check? + 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); + // + // // Second year should be later than first. + // if (access.getYears() == null || access.getYears().length == 0) + // return true; // TODO: richtig in CollisionLoadYear... implementieren + // // throw new IllegalArgumentException("error_years_wrong"); + // + // return true; + } +} \ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractSingleItemPanel.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractSingleItemPanel.java Fri Jul 13 12:04:21 2018 +0200 @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.List; +import org.dive4elements.river.client.client.FLYSConstants; 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; @@ -19,7 +20,6 @@ import org.dive4elements.river.client.shared.model.DefaultData; import org.dive4elements.river.client.shared.model.DefaultDataItem; -import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.form.fields.TextItem; @@ -34,25 +34,30 @@ private static final long serialVersionUID = 1L; - public enum Type { - single, multi, limit5 // "SingleItem" (Klassenname) meint, dass es nur ein einziges Eingabefeld gibt (nicht from-to; epoch) - // Type multi: append (year): es können mehrere Werte eingegeben werden; Leerzeichen-getrennt - // Type single: append (year, sohlhöhendifferenz): nur ein Wert ist zulässig - // Type limit5 TODO: generalize, if needed + public interface IMultiSingleBehaviour { + void appendValue(final TextItem inputItem, final String value); + + List<String> validate(List<String> errors, String sValue); + + void setValidInputs(List<String> validInputs); + + void setErrorForItemMsg(String errorForItemMsg); + + void setMSG(FLYSConstants msg); } - private final Type type; - private TextItem inputItem; private List<String> validInputs = new ArrayList<String>(); + private final IMultiSingleBehaviour behaviour; + protected abstract String getDatakey(); protected abstract Canvas createWidget(final DataList data); - public AbstractSingleItemPanel(final Type type) { - this.type = type; + public AbstractSingleItemPanel(final IMultiSingleBehaviour behaviour) { + this.behaviour = behaviour; } @Override @@ -69,6 +74,9 @@ final FromToTableHelperPanel helper = new FromToTableHelperPanel(data, getDatakey(), this.MSG, fromHandler, null); final Canvas table = helper.getTable(); this.validInputs = helper.getKeycolEntries(); + this.behaviour.setValidInputs(this.validInputs); + this.behaviour.setErrorForItemMsg(this.errorForItemMsg()); + this.behaviour.setMSG(this.MSG); this.helperContainer.addMember(table); @@ -138,121 +146,17 @@ return errors; } - private final List<String> validateSingleInput(final String sValue) { - final List<String> errors = new ArrayList<String>(); - // String filtered = ""; - // int goodValues = 0; - errors.addAll(validateNumber(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 = errorForItemMsg(); - tmp = tmp.replace("$1", sValue); - errors.add(tmp); - // continue; - } - - return errors; - } - - private final List<String> validateNumber(final String sValue) { - final List<String> errors = new ArrayList<String>(); - - try { - Integer.parseInt(sValue); - } - catch (final NumberFormatException e) { - errors.add(this.MSG.wrongFormat() + ": " + sValue); - - } - return errors; - } - protected abstract String errorForItemMsg(); protected final void appendValue(final String value) { - - switch (this.type) { - case multi: - // APPEND = ADD to existing -> MULTI YEAR - final String oldYears = this.inputItem.getValueAsString(); - if (oldYears != null && !oldYears.isEmpty()) - this.inputItem.setValue(oldYears.trim() + " " + value); - else - this.inputItem.setValue(value); - - break; - - case limit5: - // APPEND = ADD to existing -> MULTI YEAR - final String oldValues = this.inputItem.getValueAsString(); - if (oldValues != null && !oldValues.isEmpty()) { - final String[] oldVals = oldValues.split(" "); - if (oldVals.length < 5)// TODO: generalize, if needed - this.inputItem.setValue(oldValues.trim() + " " + value); - else { - // msg TODO: generalize, if needed - SC.warn(this.MSG.error_limit_exceeded_salix()); - } - } - - else - this.inputItem.setValue(value); - - break; - - case single: - this.inputItem.setValue(value); - break; - - default: - throw new IllegalStateException(); - } + this.behaviour.appendValue(this.inputItem, value); } @Override public final List<String> validate() { - final List<String> errors = new ArrayList<String>(); errors.addAll(this.checkForEmpty()); - final String sValue = this.inputItem.getValueAsString(); - - switch (this.type) { - case multi: - if (sValue != null) { - final String[] sValues = sValue.trim().split(" "); - for (final String value : sValues) { - errors.addAll(this.validateSingleInput(value)); - } - } - break; - case limit5: - if (sValue != null) { - final String[] values = sValue.trim().split(" "); - if (values.length > 5) { - errors.add(this.MSG.error_limit_exceeded_salix());// TODO generalize if needed - } - for (int i = 0; i < values.length; i++) { - if (i < 5) - errors.addAll(this.validateNumber(values[i])); - } - } - break; - case single: - errors.addAll(this.validateSingleInput(sValue)); - break; - - default: - throw new IllegalStateException(); - } - - return errors; + return this.behaviour.validate(errors, sValue); } } \ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java Fri Jul 13 12:04:21 2018 +0200 @@ -9,7 +9,6 @@ package org.dive4elements.river.client.client.ui; import org.dive4elements.river.client.client.FLYSConstants; -import org.dive4elements.river.client.client.ui.AbstractSingleItemPanel.Type; import org.dive4elements.river.client.client.ui.fixation.FixEventSelect; import org.dive4elements.river.client.client.ui.fixation.FixFunctionSelect; import org.dive4elements.river.client.client.ui.fixation.FixGaugeSelectPanel; @@ -29,9 +28,11 @@ import org.dive4elements.river.client.client.ui.sinfo.FlowDepthMinMaxTwinPanel; import org.dive4elements.river.client.client.ui.sinfo.FlowDepthTwinPanel; import org.dive4elements.river.client.client.ui.sq.SQPeriodPanel; +import org.dive4elements.river.client.client.ui.uinfo.Limit5SalixBehaviour; import org.dive4elements.river.client.client.ui.uinfo.LoadSedimentHeightPanel; import org.dive4elements.river.client.client.ui.uinfo.LoadSingleYearPanel; import org.dive4elements.river.client.client.ui.uinfo.LoadSingleYearPseudoEpochPanel; +import org.dive4elements.river.client.client.ui.uinfo.SingleBehaviour; import org.dive4elements.river.client.client.ui.uinfo.SupraRegionalTablePanel; import org.dive4elements.river.client.client.ui.uinfo.VegetationzonesTableEditPanel; import org.dive4elements.river.client.client.ui.uinfo.VegetationzonesTablePanel; @@ -175,9 +176,9 @@ } else if (uiProvider.equals("minfo.sedimentload_sqti_select")) { return new SedLoadSQTiPanel(); } else if (uiProvider.equals("uinfo.sedimentheight_select")) { - return new LoadSedimentHeightPanel(Type.single); + return new LoadSedimentHeightPanel(new SingleBehaviour());// Type.single); } else if (uiProvider.equals("uinfo.sedimentheight_select.limit5")) { - return new LoadSedimentHeightPanel(Type.limit5); + return new LoadSedimentHeightPanel(new Limit5SalixBehaviour()); } else if (uiProvider.equals("hws_datacage_panel")) { return new HWSDatacagePanel(user); } else if (uiProvider.equals("user_rgd_panel")) {
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixEventSelect.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixEventSelect.java Fri Jul 13 12:04:21 2018 +0200 @@ -8,58 +8,48 @@ package org.dive4elements.river.client.client.ui.fixation; -import java.util.List; import java.util.ArrayList; - -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; - -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; +import java.util.List; import org.dive4elements.river.client.client.FLYSConstants; - +import org.dive4elements.river.client.client.services.FixingsOverviewService; +import org.dive4elements.river.client.client.services.FixingsOverviewServiceAsync; 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.FixingsOverviewInfo; +import org.dive4elements.river.client.shared.model.FixingsOverviewInfo.FixEvent; import org.dive4elements.river.client.shared.model.IntDataItem; import org.dive4elements.river.client.shared.model.IntegerArrayData; -import org.dive4elements.river.client.shared.model.FixingsOverviewInfo.FixEvent; -import org.dive4elements.river.client.client.services.FixingsOverviewService; -import org.dive4elements.river.client.client.services.FixingsOverviewServiceAsync; +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; /** * This UIProvider lets you select events. * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class FixEventSelect -extends FixationPanel -{ +public class FixEventSelect extends FixationPanel { /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - public static final int MAX_DISPLAYED_ITEMS = 5; + private final FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - protected FixingsOverviewServiceAsync overviewService = - GWT.create(FixingsOverviewService.class); - - protected List<String> events; + private static final int MAX_DISPLAYED_ITEMS = 5; - public FixEventSelect() { - htmlOverview = ""; - events = new ArrayList<String>(); - } + private final FixingsOverviewServiceAsync overviewService = GWT.create(FixingsOverviewService.class); - public Canvas createWidget(DataList data) { + private final List<String> events = new ArrayList<String>(); + + @Override + public Canvas createWidget(final DataList data) { instances.put(this.artifact.getUuid(), this); - VLayout layout = new VLayout(); + final VLayout layout = new VLayout(); - Canvas title = new Label(MESSAGES.eventselect()); + final Canvas title = new Label(this.MESSAGES.eventselect()); title.setHeight("25px"); layout.addMember(title); @@ -67,44 +57,43 @@ } @Override - public Canvas createOld(DataList dataList) { - List<Data> list = dataList.getAll(); + public Canvas createOld(final DataList dataList) { + final List<Data> list = dataList.getAll(); - Data data = getData(list, "events"); + final Data data = getData(list, "events"); - VLayout dataLayout = new VLayout(); + final VLayout dataLayout = new VLayout(); dataLayout.setWidth(130); - DataItem[] items = data.getItems(); + final DataItem[] items = data.getItems(); if (items.length > MAX_DISPLAYED_ITEMS) { - for (int i = 0; i < MAX_DISPLAYED_ITEMS-2; ++i) { - Label l = new Label(items[i].getLabel()); + for (int i = 0; i < MAX_DISPLAYED_ITEMS - 2; ++i) { + final Label l = new Label(items[i].getLabel()); l.setHeight(25); dataLayout.addMember(l); } Label l = new Label("..."); l.setHeight(25); dataLayout.addMember(l); - l = new Label(items[items.length-1].getLabel()); + l = new Label(items[items.length - 1].getLabel()); l.setHeight(25); dataLayout.addMember(l); - } - else { - for (int i = 0; i < items.length; i++) { - Label l = new Label(items[i].getLabel()); + } else { + for (final DataItem item : items) { + final Label l = new Label(item.getLabel()); l.setHeight(25); dataLayout.addMember(l); } } - HLayout layout = new HLayout(); + 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(dataLayout); @@ -113,29 +102,28 @@ return layout; } - /** * This method returns the selected data. * * @return the selected/inserted data. */ + @Override public Data[] getData() { - List<Data> data = new ArrayList<Data>(); + final List<Data> data = new ArrayList<Data>(); - if (events.size() > 0) { - IntDataItem[] arr = new IntDataItem[events.size()]; - for (int i = 0, E = events.size(); i < E; i++) { + if (this.events.size() > 0) { + final IntDataItem[] arr = new IntDataItem[this.events.size()]; + for (int i = 0, E = this.events.size(); i < E; i++) { try { - Integer v = new Integer(events.get(i)); + final Integer v = new Integer(this.events.get(i)); arr[i] = new IntDataItem("id", "id", v.intValue()); } - catch (NumberFormatException nfe) { - return data.toArray(new Data[data.size()]); + catch (final NumberFormatException nfe) { + return data.toArray(new Data[data.size()]); } } - IntegerArrayData iad = - new IntegerArrayData("events", "events", arr); + final IntegerArrayData iad = new IntegerArrayData("events", "events", arr); data.add(iad); } @@ -143,36 +131,33 @@ return data.toArray(new Data[data.size()]); } - @Override - public void setValues(String cid, boolean checked) { + public void setValues(final String cid, final boolean checked) { if (checked) { - events.add(cid); - } - else { - if (events.contains(cid)) { - events.remove(cid); + this.events.add(cid); + } else { + if (this.events.contains(cid)) { + this.events.remove(cid); } } } - @Override public boolean renderCheckboxes() { return true; } - - public void success() { - for (FixEvent fe: fixInfo.getEvents()) { - events.add(fe.getCId()); + @Override + public void success(final FixingsOverviewInfo fixInfo) { + for (final FixEvent fe : fixInfo.getEvents()) { + this.events.add(fe.getCId()); } } - public void dumpGWT(String cid) { - GWT.log("Setting values for cId: " + cid); - GWT.log("River: " + fixInfo.getRiver()); - GWT.log("Date: " + fixInfo.getEventByCId(cid).getDate()); - GWT.log("Name: " + fixInfo.getEventByCId(cid).getDescription()); - } + // public void dumpGWT(String cid) { + // GWT.log("Setting values for cId: " + cid); + // GWT.log("River: " + fixInfo.getRiver()); + // GWT.log("Date: " + fixInfo.getEventByCId(cid).getDate()); + // GWT.log("Name: " + fixInfo.getEventByCId(cid).getDescription()); + // } }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixFunctionSelect.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixFunctionSelect.java Fri Jul 13 12:04:21 2018 +0200 @@ -8,6 +8,17 @@ package org.dive4elements.river.client.client.ui.fixation; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +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.FixingsOverviewInfo; + import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; @@ -16,19 +27,8 @@ import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; -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 java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - public class FixFunctionSelect extends FixationPanel { - private static final Map<String, String> funcDesc = - new HashMap<String, String>(); + private static final Map<String, String> funcDesc = new HashMap<String, String>(); static { funcDesc.put("log", "W(Q) = m*ln(Q + b)"); @@ -40,40 +40,39 @@ funcDesc.put("sq-pow", "S(Q) = a * Q^b"); } - /** The combobox.*/ + /** The combobox. */ protected DynamicForm form; @Override - public Canvas createWidget(DataList data) { - VLayout layout = new VLayout(); + public Canvas createWidget(final DataList data) { + final VLayout layout = new VLayout(); layout.setAlign(VerticalAlignment.TOP); layout.setHeight(25); - LinkedHashMap initial = new LinkedHashMap(); + final LinkedHashMap initial = new LinkedHashMap(); - form = new DynamicForm(); + this.form = new DynamicForm(); - int size = data.size(); + final int size = data.size(); for (int i = 0; i < size; i++) { - Data d = data.get(i); + final Data d = data.get(i); - Label label = new Label(d.getDescription()); + final Label label = new Label(d.getDescription()); label.setValign(VerticalAlignment.TOP); label.setHeight(20); label.setWidth(400); - SelectItem combobox = new SelectItem(d.getLabel()); + final SelectItem combobox = new SelectItem(d.getLabel()); combobox.setWidth(250); - LinkedHashMap<String, String> funcTypes = - new LinkedHashMap<String, String>(); + final LinkedHashMap<String, String> funcTypes = new LinkedHashMap<String, String>(); - boolean defaultSet = false; - boolean first = true; + boolean defaultSet = false; + boolean first = true; - DataItem def = d.getDefault(); - String defValue = def != null ? def.getStringValue() : null; + final DataItem def = d.getDefault(); + final String defValue = def != null ? def.getStringValue() : null; if (defValue != null && defValue.length() > 0) { initial.put(d.getLabel(), def.getStringValue()); @@ -81,7 +80,7 @@ } // I was here. Me 2. - for (DataItem item: d.getItems()) { + for (final DataItem item : d.getItems()) { if (!defaultSet && first) { initial.put(d.getLabel(), item.getStringValue()); first = false; @@ -93,39 +92,37 @@ label.setWidth(50); combobox.setValueMap(funcTypes); combobox.setShowTitle(false); - form.setItems(combobox); + this.form.setItems(combobox); layout.addMember(label); - layout.addMember(form); + layout.addMember(this.form); } - form.setValues(initial); + this.form.setValues(initial); layout.setAlign(VerticalAlignment.TOP); return layout; } - @Override - public Canvas createOld(DataList dataList) { - HLayout layout = new HLayout(); - VLayout vLayout = new VLayout(); + public Canvas createOld(final DataList dataList) { + final HLayout layout = new HLayout(); + final VLayout vLayout = new VLayout(); layout.setWidth("400px"); - Label label = new Label(dataList.getLabel()); + final Label label = new Label(dataList.getLabel()); label.setWidth("200px"); - int size = dataList.size(); + final int size = dataList.size(); for (int i = 0; i < size; i++) { - Data data = dataList.get(i); - DataItem[] items = data.getItems(); + final Data data = dataList.get(i); + final DataItem[] items = data.getItems(); - for (DataItem item: items) { - HLayout hLayout = new HLayout(); + for (final DataItem item : items) { + final HLayout hLayout = new HLayout(); - String desc = funcDesc.containsKey(item.getLabel()) ? - funcDesc.get(item.getLabel()) : item.getLabel(); + final String desc = funcDesc.containsKey(item.getLabel()) ? funcDesc.get(item.getLabel()) : item.getLabel(); hLayout.addMember(label); hLayout.addMember(new Label(desc)); @@ -134,7 +131,7 @@ } } - Canvas back = getBackButton(dataList.getState()); + final Canvas back = getBackButton(dataList.getState()); layout.addMember(label); layout.addMember(vLayout); @@ -143,30 +140,27 @@ return layout; } - @Override public Data[] getData() { - Map<?, ?> values = form.getValues(); - - Data[] list = new Data[values.size()]; - int i = 0; + final Map<?, ?> values = this.form.getValues(); - for (Map.Entry<?, ?>entry: values.entrySet()) { - String fieldname = (String)entry.getKey(); - String selection = (String)entry.getValue(); + final Data[] list = new Data[values.size()]; + int i = 0; - DataItem item = new DefaultDataItem(fieldname, null, selection); + for (final Map.Entry<?, ?> entry : values.entrySet()) { + final String fieldname = (String) entry.getKey(); + final String selection = (String) entry.getValue(); - list[i++] = new DefaultData( - fieldname, null, null, new DataItem[] { item }); + final DataItem item = new DefaultDataItem(fieldname, null, selection); + + list[i++] = new DefaultData(fieldname, null, null, new DataItem[] { item }); } return list; } - @Override - public void setValues(String cid, boolean checked) { + public void setValues(final String cid, final boolean checked) { } @Override @@ -175,7 +169,6 @@ } @Override - public void success() { + public void success(final FixingsOverviewInfo fixInfo) { } - -} +} \ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixGaugeSelectPanel.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixGaugeSelectPanel.java Fri Jul 13 12:04:21 2018 +0200 @@ -8,8 +8,19 @@ package org.dive4elements.river.client.client.ui.fixation; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +import org.dive4elements.river.client.client.FLYSConstants; +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.FixingsOverviewInfo; + import com.google.gwt.core.client.GWT; - import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.form.DynamicForm; @@ -18,26 +29,13 @@ import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; -import org.dive4elements.river.client.client.FLYSConstants; -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 java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; - /** * This UIProvider creates a panel to select discharge classes / sectors * (german Abflussklassen). * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class FixGaugeSelectPanel -extends FixationPanel -{ +public class FixGaugeSelectPanel extends FixationPanel { /** The message class that provides i18n strings. */ protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); @@ -50,42 +48,40 @@ protected LinkedHashMap<String, String> mapValues; public FixGaugeSelectPanel() { - htmlOverview = ""; - - mapValues = new LinkedHashMap<String, String>(); - mapValues.put("0", MESSAGES.gauge_mnq()); - mapValues.put("1", MESSAGES.gauge_mq()); - mapValues.put("2", MESSAGES.gauge_mhq()); - mapValues.put("3", MESSAGES.gauge_hq5()); + this.mapValues = new LinkedHashMap<String, String>(); + this.mapValues.put("0", this.MESSAGES.gauge_mnq()); + this.mapValues.put("1", this.MESSAGES.gauge_mq()); + this.mapValues.put("2", this.MESSAGES.gauge_mhq()); + this.mapValues.put("3", this.MESSAGES.gauge_hq5()); } @Override - public Canvas createWidget(DataList data) { + public Canvas createWidget(final DataList data) { instances.put(this.artifact.getUuid(), this); - VLayout layout = new VLayout(); + final VLayout layout = new VLayout(); - Label title = new Label(MESSAGES.gauge_class()); + final Label title = new Label(this.MESSAGES.gauge_class()); title.setHeight(25); - from = new SelectItem(MESSAGES.from()); - to = new SelectItem(MESSAGES.to()); + this.from = new SelectItem(this.MESSAGES.from()); + this.to = new SelectItem(this.MESSAGES.to()); - from.setShowTitle(false); - to.setShowTitle(false); - from.setValueMap(mapValues); - from.setDefaultValues("0"); - from.setWidth(160); - to.setValueMap(mapValues); - to.setDefaultValues("3"); - to.setWidth(160); + this.from.setShowTitle(false); + this.to.setShowTitle(false); + this.from.setValueMap(this.mapValues); + this.from.setDefaultValues("0"); + this.from.setWidth(160); + this.to.setValueMap(this.mapValues); + this.to.setDefaultValues("3"); + this.to.setWidth(160); - DynamicForm form = new DynamicForm(); - StaticTextItem separator = new StaticTextItem("separator"); + final DynamicForm form = new DynamicForm(); + final StaticTextItem separator = new StaticTextItem("separator"); separator.setShowTitle(false); - separator.setValue(MESSAGES.to()); + separator.setValue(this.MESSAGES.to()); form.setNumCols(5); - form.setFields(from, separator, to); + form.setFields(this.from, separator, this.to); layout.addMember(title); layout.addMember(form); @@ -94,28 +90,28 @@ } @Override - public Canvas createOld(DataList dataList) { - List<Data> items = dataList.getAll(); + public Canvas createOld(final DataList dataList) { + final List<Data> items = dataList.getAll(); - Data f = getData(items, "q1"); - Data t = getData(items, "q2"); - DataItem[] fItems = f.getItems(); - DataItem[] tItems = t.getItems(); + final Data f = getData(items, "q1"); + final Data t = getData(items, "q2"); + final DataItem[] fItems = f.getItems(); + final DataItem[] tItems = t.getItems(); - StringBuilder sb = new StringBuilder(); - sb.append(mapValues.get(fItems[0].getLabel())); - sb.append(" " + MESSAGES.to() + " "); - sb.append(mapValues.get(tItems[0].getLabel())); + final StringBuilder sb = new StringBuilder(); + sb.append(this.mapValues.get(fItems[0].getLabel())); + sb.append(" " + this.MESSAGES.to() + " "); + sb.append(this.mapValues.get(tItems[0].getLabel())); - Label old = new Label(sb.toString()); + final Label old = new Label(sb.toString()); old.setWidth(130); - HLayout layout = new HLayout(); + 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); @@ -123,7 +119,6 @@ return layout; } - /** * This method returns the selected data. * @@ -131,56 +126,46 @@ */ @Override public Data[] getData() { - List<Data> data = new ArrayList<Data>(); + final List<Data> data = new ArrayList<Data>(); - boolean valid = saveClassValues(); + final boolean valid = saveClassValues(); if (valid) { - DataItem firstItem = new DefaultDataItem("q1", "q1", this.first); - DataItem secItem = new DefaultDataItem("q2", "q2", this.second); - data.add(new DefaultData( - "q1", - null, - null, - new DataItem[] { firstItem })); - data.add(new DefaultData( - "q2", - null, - null, - new DataItem[] { secItem })); + final DataItem firstItem = new DefaultDataItem("q1", "q1", this.first); + final DataItem secItem = new DefaultDataItem("q2", "q2", this.second); + data.add(new DefaultData("q1", null, null, new DataItem[] { firstItem })); + data.add(new DefaultData("q2", null, null, new DataItem[] { secItem })); } return data.toArray(new Data[data.size()]); } - @Override - public void setValues(String cid, boolean checked) { + public void setValues(final String cid, final boolean checked) { // No user interaction, do nothing. } - @Override public boolean renderCheckboxes() { // No selection, return false. return false; } - @Override - public void success() {} + public void success(final FixingsOverviewInfo fixInfo) { + } protected boolean saveClassValues() { - String v1 = from.getValueAsString(); - String v2 = to.getValueAsString(); + final String v1 = this.from.getValueAsString(); + final String v2 = this.to.getValueAsString(); try { - int v1i = Integer.parseInt(v1); - int v2i = Integer.parseInt(v2); + final int v1i = Integer.parseInt(v1); + final int v2i = Integer.parseInt(v2); if (v1i <= v2i) { this.first = v1; this.second = v2; return true; } } - catch(NumberFormatException nfe) { + catch (final NumberFormatException nfe) { return false; } return false;
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixLocationPanel.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixLocationPanel.java Fri Jul 13 12:04:21 2018 +0200 @@ -18,6 +18,7 @@ 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.FixingsOverviewInfo; import com.google.gwt.core.client.GWT; import com.smartgwt.client.widgets.Canvas; @@ -49,10 +50,6 @@ double to; double step; - public FixLocationPanel() { - this.htmlOverview = ""; - } - @Override public Canvas createWidget(final DataList data) { instances.put(this.artifact.getUuid(), this); @@ -155,9 +152,9 @@ } @Override - public void success() { - this.inputPanel.setValues(this.fixInfo.getLowerKm(), // TODO: check if revert makes sense - this.fixInfo.getUpperKm(), 100d); + public void success(final FixingsOverviewInfo fixInfo) { + // TODO: check if revert makes sense + this.inputPanel.setValues(fixInfo.getLowerKm(), fixInfo.getUpperKm(), 100d); } /** @@ -178,10 +175,10 @@ final DoubleRangePanel p = (DoubleRangePanel) event.getForm(); } - public void dumpGWT(final String cid) { - GWT.log("Setting values for cId: " + cid); - GWT.log("River: " + this.fixInfo.getRiver()); - GWT.log("Date: " + this.fixInfo.getEventByCId(cid).getDate()); - GWT.log("Name: " + this.fixInfo.getEventByCId(cid).getDescription()); - } + // public void dumpGWT(final String cid) { + // GWT.log("Setting values for cId: " + cid); + // GWT.log("River: " + this.fixInfo.getRiver()); + // GWT.log("Date: " + this.fixInfo.getEventByCId(cid).getDate()); + // GWT.log("Name: " + this.fixInfo.getEventByCId(cid).getDescription()); + // } }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixPeriodPanel.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixPeriodPanel.java Fri Jul 13 12:04:21 2018 +0200 @@ -8,9 +8,21 @@ package org.dive4elements.river.client.client.ui.fixation; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.dive4elements.river.client.client.FLYSConstants; +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.FixingsOverviewInfo; +import org.dive4elements.river.client.shared.model.FixingsOverviewInfo.FixEvent; + import com.google.gwt.core.client.GWT; import com.google.gwt.i18n.client.DateTimeFormat; - import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; @@ -19,26 +31,12 @@ import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; -import org.dive4elements.river.client.client.FLYSConstants; -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.FixingsOverviewInfo.FixEvent; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - /** * This UIProvider creates a panel for location or distance input. * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class FixPeriodPanel -extends FixationPanel -{ +public class FixPeriodPanel extends FixationPanel { /** The message class that provides i18n strings. */ protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); @@ -54,27 +52,26 @@ this("start", "end"); } - public FixPeriodPanel(String startName, String endName) { + public FixPeriodPanel(final String startName, final String endName) { this.startName = startName; - this.endName = endName; - htmlOverview = ""; + this.endName = endName; } @Override - public Canvas createWidget(DataList data) { + public Canvas createWidget(final DataList data) { instances.put(this.artifact.getUuid(), this); - VLayout layout = new VLayout(); + 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(); - inputPanel = new DateRangeItem(); - inputPanel.setToTitle(MESSAGES.to()); - inputPanel.setFromTitle(MESSAGES.from()); - inputPanel.setShowTitle(false); - form.setFields(inputPanel); + final DynamicForm form = new DynamicForm(); + this.inputPanel = new DateRangeItem(); + this.inputPanel.setToTitle(this.MESSAGES.to()); + this.inputPanel.setFromTitle(this.MESSAGES.from()); + this.inputPanel.setShowTitle(false); + form.setFields(this.inputPanel); layout.addMember(title); layout.addMember(form); @@ -83,16 +80,16 @@ } @Override - public Canvas createOld(DataList dataList) { - List<Data> items = dataList.getAll(); + public Canvas createOld(final DataList dataList) { + final List<Data> items = dataList.getAll(); - Data start = getData(items, startName); - Data end = getData(items, endName); - DataItem[] startItem = start.getItems(); - DataItem[] endItem = end.getItems(); + final Data start = getData(items, this.startName); + final Data end = getData(items, this.endName); + final DataItem[] startItem = start.getItems(); + final DataItem[] endItem = end.getItems(); - String v1 = startItem[0].getStringValue(); - String v2 = endItem[0].getStringValue(); + final String v1 = startItem[0].getStringValue(); + final String v2 = endItem[0].getStringValue(); long v1l = 0; long v2l = 0; @@ -100,29 +97,27 @@ v1l = Long.parseLong(v1); v2l = Long.parseLong(v2); } - catch(NumberFormatException nfe) { + catch (final NumberFormatException nfe) { GWT.log(nfe.toString()); } - Date d1 = new Date(v1l); - Date d2 = new Date(v2l); + final Date d1 = new Date(v1l); + final Date d2 = new Date(v2l); - DateTimeFormat f = - DateTimeFormat.getFormat( - DateTimeFormat.PredefinedFormat.DATE_MEDIUM); - StringBuilder sb = new StringBuilder(); + final DateTimeFormat f = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM); + final StringBuilder sb = new StringBuilder(); sb.append(f.format(d1) + " - "); sb.append(f.format(d2)); - Label old = new Label(sb.toString()); + final Label old = new Label(sb.toString()); old.setWidth(130); - HLayout layout = new HLayout(); + 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); @@ -131,7 +126,6 @@ return layout; } - /** * This method returns the selected data. * @@ -139,37 +133,26 @@ */ @Override public Data[] getData() { - List<Data> data = new ArrayList<Data>(); + final List<Data> data = new ArrayList<Data>(); - boolean valid = saveDateValues(); - if(valid) { - String start = Long.valueOf(this.start).toString(); - String end = Long.valueOf(this.end).toString(); - DataItem startItem = new DefaultDataItem( - startName, startName, start); - DataItem endItem = new DefaultDataItem(endName, endName, end); - data.add(new DefaultData( - startName, - null, - null, - new DataItem[] { startItem })); - data.add(new DefaultData( - endName, - null, - null, - new DataItem[] { endItem })); + final boolean valid = saveDateValues(); + if (valid) { + final String start = Long.valueOf(this.start).toString(); + final String end = Long.valueOf(this.end).toString(); + final DataItem startItem = new DefaultDataItem(this.startName, this.startName, start); + final DataItem endItem = new DefaultDataItem(this.endName, this.endName, end); + data.add(new DefaultData(this.startName, null, null, new DataItem[] { startItem })); + data.add(new DefaultData(this.endName, null, null, new DataItem[] { endItem })); } return data.toArray(new Data[data.size()]); } - @Override - public void setValues(String cid, boolean checked) { + public void setValues(final String cid, final boolean checked) { // No user interaction, do nothing. } - @Override public boolean renderCheckboxes() { // No selection, return false. @@ -177,54 +160,49 @@ } @Override - public void success() { - List<FixEvent> list = fixInfo.getEvents(); + public void success(final FixingsOverviewInfo fixInfo) { + final List<FixEvent> list = fixInfo.getEvents(); // The date in FixEvent is always "de" locale, so it seems... - DateTimeFormat df = DateTimeFormat.getFormat("dd.MM.yyyy"); + final DateTimeFormat df = DateTimeFormat.getFormat("dd.MM.yyyy"); if (!setFromAndToDate(list, df)) { - GWT.log("FixPeriodPanel::success(): could not set " - + "from and to dates!"); + GWT.log("FixPeriodPanel::success(): could not set " + "from and to dates!"); } } - protected boolean setFromAndToDate(List<FixEvent> list, DateTimeFormat df) { + protected boolean setFromAndToDate(final List<FixEvent> list, final DateTimeFormat df) { try { setFromDate(list.get(0).getDate(), df); setToDate(list.get(list.size() - 1).getDate(), df); return true; } - catch(IllegalArgumentException ex) { + catch (final IllegalArgumentException ex) { GWT.log("FixPeriodPanel::setFromAndToDate(): " + ex.toString()); return false; } } - protected void setFromDate(String date, DateTimeFormat df) - throws IllegalArgumentException - { - Date from = df.parse(date); + protected void setFromDate(final String date, final DateTimeFormat df) throws IllegalArgumentException { + final Date from = df.parse(date); this.inputPanel.setFromDate(from); } - protected void setToDate(String date, DateTimeFormat df) - throws IllegalArgumentException - { - Date to = df.parse(date); + protected void setToDate(final String date, final DateTimeFormat df) throws IllegalArgumentException { + final Date to = df.parse(date); this.inputPanel.setToDate(to); } protected boolean saveDateValues() { - Date st = inputPanel.getValue().getStartDate(); - Date en = inputPanel.getValue().getEndDate(); + final Date st = this.inputPanel.getValue().getStartDate(); + final Date en = this.inputPanel.getValue().getEndDate(); if (st == null || en == null) { - SC.warn(MESSAGES.error_wrong_date()); + SC.warn(this.MESSAGES.error_wrong_date()); return false; } - long start = st.getTime(); - long end = en.getTime(); + final long start = st.getTime(); + final long end = en.getTime(); if (start <= end) { this.start = start;
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixQSelectPanel.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixQSelectPanel.java Fri Jul 13 12:04:21 2018 +0200 @@ -8,64 +8,57 @@ package org.dive4elements.river.client.client.ui.fixation; -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; - import org.dive4elements.river.client.client.FLYSConstants; - import org.dive4elements.river.client.shared.model.Data; import org.dive4elements.river.client.shared.model.DataList; +import org.dive4elements.river.client.shared.model.FixingsOverviewInfo; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.widgets.Canvas; /** * This UIProvider creates a panel for location or distance input. * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class FixQSelectPanel -extends FixationPanel -{ +public class FixQSelectPanel extends FixationPanel { /** The message class that provides i18n strings. */ protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - public FixQSelectPanel() { - htmlOverview = ""; - } - - public Canvas createWidget(DataList data) { + @Override + public Canvas createWidget(final DataList data) { instances.put(this.artifact.getUuid(), this); return new Canvas(); } @Override - public Canvas createOld(DataList dataList) { + public Canvas createOld(final DataList dataList) { return new Canvas(); } - /** * This method returns the selected data. * * @return the selected/inserted data. */ + @Override public Data[] getData() { return new Data[0]; } - @Override - public void setValues(String cid, boolean checked) { + public void setValues(final String cid, final boolean checked) { // No user interaction, do nothing. } - @Override public boolean renderCheckboxes() { // No selection, return false. return false; } - - public void success() {} -} + @Override + public void success(final FixingsOverviewInfo fixInfo) { + } +} \ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixationPanel.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixationPanel.java Fri Jul 13 12:04:21 2018 +0200 @@ -17,7 +17,6 @@ import org.dive4elements.river.client.client.services.FixingsOverviewServiceAsync; import org.dive4elements.river.client.client.ui.AbstractUIProvider; import org.dive4elements.river.client.shared.model.AbstractFixBunduArtifact; -import org.dive4elements.river.client.shared.model.Data; import org.dive4elements.river.client.shared.model.DataList; import org.dive4elements.river.client.shared.model.FixFilter; import org.dive4elements.river.client.shared.model.FixingsOverviewInfo; @@ -61,20 +60,20 @@ protected static HashMap<String, FixationPanel> instances = new HashMap<String, FixationPanel>(); /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - - protected FixingsOverviewServiceAsync overviewService = GWT.create(FixingsOverviewService.class); + private final FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); - protected String htmlOverview; - protected FixingsOverviewInfo fixInfo; - protected TabSet tabs; - protected Tab events; - protected Tab chart; - protected VLayout chartContainer; - protected Img chartImg; - protected TextItem kmText; + private final FixingsOverviewServiceAsync overviewService = GWT.create(FixingsOverviewService.class); - public static final DateTimeFormat DTF = DateTimeFormat.getFormat("dd.MM.yyyy"); + private String htmlOverview; + private FixingsOverviewInfo fixInfo; + private TabSet tabs; + private Tab events; + private Tab chart; + private VLayout chartContainer; + private Img chartImg; + private TextItem kmText; + + private static final DateTimeFormat DTF = DateTimeFormat.getFormat("dd.MM.yyyy"); public FixationPanel() { this.chartImg = new Img(); @@ -82,20 +81,12 @@ } /** Get the (master) artifact UUID. */ - protected String getArtifactUuid() { + private String getArtifactUuid() { return this.artifact.getUuid(); } - protected void init() { - } - @Override - public Data[] getData() { - return null; - } - - @Override - public Canvas create(final DataList list) { + public final Canvas create(final DataList list) { final VLayout layout = new VLayout(); final Canvas helper = createHelper(); @@ -109,12 +100,7 @@ return layout; } - @Override - public Canvas createOld(final DataList list) { - return new DynamicForm(); - } - - protected Canvas createHelper() { + private Canvas createHelper() { final Config config = Config.getInstance(); final String locale = config.getLocale(); @@ -134,7 +120,7 @@ final HTMLPane eventPane = new HTMLPane(); - final String river = this.artifact.getArtifactDescription().getRiver(); + // final String river = this.artifact.getArtifactDescription().getRiver(); createCallback(); final String callBack = "fixationCallback(this.checked, this.name)"; @@ -177,7 +163,7 @@ eventPane.setContents(FixationPanel.this.htmlOverview); updateChartTab(FixationPanel.this.fixInfo.getLowerKm()); FixationPanel.this.events.setPane(eventPane); - success(); + success(FixationPanel.this.fixInfo); } }); @@ -187,7 +173,7 @@ return this.tabs; } - protected Canvas createChartHelper() { + private Canvas createChartHelper() { final DynamicForm form = new DynamicForm(); final Button lower = new Button("<<"); lower.setWidth(30); @@ -255,7 +241,7 @@ return layout; } - protected void updateChartTab(double km) { + private void updateChartTab(double km) { final Config config = Config.getInstance(); final String locale = config.getLocale(); @@ -302,7 +288,7 @@ } } - protected FixFilter updateChartTabLow() { + private FixFilter updateChartTabLow() { final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; final FixFilter filter = art.getFilter(); @@ -316,7 +302,7 @@ return filter; } - protected FixFilter updateChartTabUp() { + private FixFilter updateChartTabUp() { final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; final FixFilter filter = art.getFilter(); @@ -331,7 +317,7 @@ } @Override - public void onResized(final ResizedEvent re) { + public final void onResized(final ResizedEvent re) { final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; updateChartTab(art.getFilter().getCurrentKm()); @@ -356,16 +342,16 @@ return instances.get(uuid); } - public abstract Canvas createWidget(DataList data); + protected abstract Canvas createWidget(DataList data); - public abstract void setValues(String cid, boolean checked); + protected abstract void setValues(String cid, boolean checked); - public abstract boolean renderCheckboxes(); + protected abstract boolean renderCheckboxes(); - public abstract void success(); + protected abstract void success(FixingsOverviewInfo fixInfo); /** Creates JSON string from filter. */ - public static String getOverviewFilter(final FixFilter filter) { + private static String getOverviewFilter(final FixFilter filter) { final String river = filter.getRiver(); if (river != null && river.length() > 0) { @@ -381,7 +367,7 @@ return ""; } - public String getChartFilter(final FixFilter filter, final int width, final int height) { + private String getChartFilter(final FixFilter filter, final int width, final int height) { final String river = filter.getRiver(); final double currentKm = filter.getCurrentKm(); final double fromKm = filter.getLowerKm(); @@ -411,7 +397,7 @@ return ""; } - protected static JSONObject createFilter(final FixFilter filter, final JSONObject root) { + private static JSONObject createFilter(final FixFilter filter, final JSONObject root) { final double fromKm = filter.getLowerKm(); final double toKm = filter.getUpperKm(); final boolean hasDate = filter.hasDate(); @@ -477,5 +463,4 @@ } return root; } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +} \ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/CollisionLoadYearPanel.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/CollisionLoadYearPanel.java Fri Jul 13 12:04:21 2018 +0200 @@ -22,7 +22,7 @@ private static final long serialVersionUID = 1L; public CollisionLoadYearPanel() { - super(Type.multi); + super(new MultiBehaviour()); } @Override
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/MultiBehaviour.java Fri Jul 13 12:04:21 2018 +0200 @@ -0,0 +1,55 @@ +/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.client.client.ui.sinfo; + +import java.util.List; + +import org.dive4elements.river.client.client.FLYSConstants; +import org.dive4elements.river.client.client.ui.uinfo.ValidationBehaviourSingleMultiInputItem; + +import com.smartgwt.client.widgets.form.fields.TextItem; + +/** + * @author Domenico Nardi Tironi + * + */ +public class MultiBehaviour extends ValidationBehaviourSingleMultiInputItem { + + public MultiBehaviour(final List<String> validInputs, final String errorForItemMsg, final FLYSConstants MSG) { + super(validInputs, errorForItemMsg, MSG); + } + + public MultiBehaviour() { + super(); + } + + @Override + public void appendValue(final TextItem inputItem, final String value) { + // APPEND = ADD to existing -> MULTI YEAR + final String oldYears = inputItem.getValueAsString(); + if (oldYears != null && !oldYears.isEmpty()) + inputItem.setValue(oldYears.trim() + " " + value); + else + inputItem.setValue(value); + + } + + @Override + public List<String> validate(final List<String> errors, final String inputValueString) { + if (inputValueString != null) { + final String[] sValues = inputValueString.trim().split(" "); + for (final String value : sValues) { + errors.addAll(this.validateSingleInput(value)); + } + } + return errors; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/Limit5SalixBehaviour.java Fri Jul 13 12:04:21 2018 +0200 @@ -0,0 +1,66 @@ +/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.client.client.ui.uinfo; + +import java.util.List; + +import org.dive4elements.river.client.client.FLYSConstants; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.form.fields.TextItem; + +/** + * @author Domenico Nardi Tironi + * + */ +public class Limit5SalixBehaviour extends ValidationBehaviourSingleMultiInputItem { + + public Limit5SalixBehaviour(final List<String> validInputs, final String errorForItemMsg, final FLYSConstants MSG) { + super(validInputs, errorForItemMsg, MSG); + } + + public Limit5SalixBehaviour() { + super(); + } + + @Override + public void appendValue(final TextItem inputItem, final String value) { + // APPEND = ADD to existing -> MULTI YEAR + final String oldValues = inputItem.getValueAsString(); + if (oldValues != null && !oldValues.isEmpty()) { + final String[] oldVals = oldValues.split(" "); + if (oldVals.length < 5) + inputItem.setValue(oldValues.trim() + " " + value); + else { + SC.warn(this.MSG.error_limit_exceeded_salix()); + } + } + + else + inputItem.setValue(value); + + } + + @Override + public List<String> validate(final List<String> errors, final String inputValueString) { + if (inputValueString != null) { + final String[] values = inputValueString.trim().split(" "); + if (values.length > 5) { + errors.add(this.MSG.error_limit_exceeded_salix()); + } + for (int i = 0; i < values.length; i++) { + if (i < 5) + errors.addAll(this.validateNumber(values[i])); + } + } + return errors; + } + +}
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSedimentHeightPanel.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSedimentHeightPanel.java Fri Jul 13 12:04:21 2018 +0200 @@ -21,8 +21,8 @@ public class LoadSedimentHeightPanel extends AbstractSingleItemPanel { private static final long serialVersionUID = 1L; - public LoadSedimentHeightPanel(final Type type) { - super(type); + public LoadSedimentHeightPanel(final IMultiSingleBehaviour behaviour) { + super(behaviour); } @Override
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSingleYearPanel.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSingleYearPanel.java Fri Jul 13 12:04:21 2018 +0200 @@ -23,11 +23,11 @@ private boolean showHint = false; public LoadSingleYearPanel() { - super(Type.single); + super(new SingleBehaviour()); } public LoadSingleYearPanel(final boolean showHint) { - super(Type.single); + super(new SingleBehaviour()); this.showHint = showHint; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/SingleBehaviour.java Fri Jul 13 12:04:21 2018 +0200 @@ -0,0 +1,43 @@ +/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.client.client.ui.uinfo; + +import java.util.List; + +import org.dive4elements.river.client.client.FLYSConstants; + +import com.smartgwt.client.widgets.form.fields.TextItem; + +/** + * @author Domenico Nardi Tironi + * + */ +public class SingleBehaviour extends ValidationBehaviourSingleMultiInputItem { + + public SingleBehaviour(final List<String> validInputs, final String errorForItemMsg, final FLYSConstants MSG) { + super(validInputs, errorForItemMsg, MSG); + } + + public SingleBehaviour() { + super(); + } + + @Override + public void appendValue(final TextItem inputItem, final String value) { + inputItem.setValue(value); + } + + @Override + public List<String> validate(final List<String> errors, final String inputValueString) { + errors.addAll(this.validateSingleInput(inputValueString)); + return errors; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/ValidationBehaviourSingleMultiInputItem.java Fri Jul 13 12:04:21 2018 +0200 @@ -0,0 +1,92 @@ +/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.client.client.ui.uinfo; + +import java.util.ArrayList; +import java.util.List; + +import org.dive4elements.river.client.client.FLYSConstants; +import org.dive4elements.river.client.client.ui.AbstractSingleItemPanel.IMultiSingleBehaviour; + +/** + * @author Domenico Nardi Tironi + * + */ +public abstract class ValidationBehaviourSingleMultiInputItem implements IMultiSingleBehaviour { + + private List<String> validInputs = null; + private String errorForItemMsg = null; + protected FLYSConstants MSG = null; + + public ValidationBehaviourSingleMultiInputItem(final List<String> validInputs, final String errorForItemMsg, final FLYSConstants MSG) { + this.validInputs = validInputs; + this.errorForItemMsg = errorForItemMsg; + this.MSG = MSG; // etwas unglücklich... + } + + public ValidationBehaviourSingleMultiInputItem() { + + } + + protected final List<String> validateSingleInput(final String sValue) { + final List<String> errors = new ArrayList<String>(); + // String filtered = ""; + // int goodValues = 0; + errors.addAll(validateNumber(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.errorForItemMsg; + tmp = tmp.replace("$1", sValue); + errors.add(tmp); + // continue; + } + + return errors; + } + + protected final List<String> validateNumber(final String sValue) { + final List<String> errors = new ArrayList<String>(); + + try { + Integer.parseInt(sValue); + } + catch (final NumberFormatException e) { + errors.add(this.MSG.wrongFormat() + ": " + sValue); + + } + return errors; + } + + @Override + public final void setValidInputs(final List<String> validInputs) { + this.validInputs = validInputs; + + } + + @Override + public final void setErrorForItemMsg(final String errorForItemMsg) { + this.errorForItemMsg = errorForItemMsg; + + } + + @Override + public void setMSG(final FLYSConstants msg) { + this.MSG = this.MSG; + + } + +}
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AbstractFixBunduArtifact.java Fri Jul 13 11:56:22 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AbstractFixBunduArtifact.java Fri Jul 13 12:04:21 2018 +0200 @@ -36,13 +36,9 @@ super(uuid, hash, inBackground, messages); } - public FixFilter getFilter() { - return createFilter(); - } - protected abstract String getEventstateId(); - protected FixFilter createFilter() { + public final FixFilter getFilter() { if (this.filter == null) { this.filter = new FixFilter(); }