Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedInputPanel.java @ 9288:82c67b859aa7
bundu.bezugswst worklflow incl. service impl for mainValues to be calculated
author | gernotbelger |
---|---|
date | Tue, 24 Jul 2018 10:39:03 +0200 |
parents | 717c9dc1859f |
children | bc9a45d2b1fa |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedInputPanel.java Tue Jul 24 10:36:18 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedInputPanel.java Tue Jul 24 10:39:03 2018 +0200 @@ -14,13 +14,10 @@ import java.util.List; import java.util.Map; -import org.dive4elements.river.client.client.Config; -import org.dive4elements.river.client.client.FLYSConstants; import org.dive4elements.river.client.client.services.WQInfoService; import org.dive4elements.river.client.client.services.WQInfoServiceAsync; import org.dive4elements.river.client.client.ui.wq.QDTable; import org.dive4elements.river.client.client.ui.wq.WTable; -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; @@ -28,12 +25,10 @@ import org.dive4elements.river.client.shared.model.DefaultDataItem; import org.dive4elements.river.client.shared.model.WQDataItem; import org.dive4elements.river.client.shared.model.WQInfoObject; -import org.dive4elements.river.client.shared.model.WQInfoRecord; 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.TitleOrientation; import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.util.SC; @@ -41,18 +36,13 @@ import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.RadioGroupItem; -import com.smartgwt.client.widgets.form.fields.events.BlurEvent; -import com.smartgwt.client.widgets.form.fields.events.BlurHandler; import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; import com.smartgwt.client.widgets.form.fields.events.FocusEvent; import com.smartgwt.client.widgets.form.fields.events.FocusHandler; -import com.smartgwt.client.widgets.grid.events.CellClickEvent; -import com.smartgwt.client.widgets.grid.events.CellClickHandler; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.tab.Tab; -import com.smartgwt.client.widgets.tab.TabSet; /** * This UIProvider creates a widget to enter W or Q data for discharge @@ -60,257 +50,204 @@ * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ -public class WQAdaptedInputPanel extends AbstractUIProvider implements ChangeHandler, BlurHandler, FocusHandler { +public class WQAdaptedInputPanel extends AbstractWQAdaptedInputPanel implements FocusHandler { private static final long serialVersionUID = -3218827566805476423L; - - /** The message class that provides i18n strings. */ - protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); - - public static final String FIELD_WQ_MODE = "wq_isq"; - public static final String FIELD_WQ_W = "W"; - public static final String FIELD_WQ_Q = "Q"; - - public static final String GAUGE_SEPARATOR = ":"; - - public static final String GAUGE_PART_SEPARATOR = ";"; - - public static final String VALUE_SEPARATOR = ","; - - public static final int ROW_HEIGHT = 20; - - /** The constant field name for choosing w or q mode. */ - public static final String FIELD_WQ = "wq"; - - /** The constant field name for choosing single values or range. */ - public static final String FIELD_MODE = "mode"; - - /** The constant field value for range input mode. */ - public static final String FIELD_MODE_RANGE = "range"; - - /** Service to fetch W/Q MainValues. */ - protected WQInfoServiceAsync wqInfoService = GWT.create(WQInfoService.class); - - /** The message class that provides i18n strings. */ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - /** Stores the input panels related to their keys. */ - protected Map<String, DoubleArrayPanel> wqranges; - - /** List of doubleArrayPanels shown. */ - protected ArrayList<DoubleArrayPanel> doubleArrayPanels; - - /** [startkm,endkm] per gauge in selected range. */ - protected List<Double[]> gaugeRanges; - - /** Stores the min/max values for each q range (gauge). */ - protected Map<String, double[]> qranges; + private static final String FIELD_WQ_MODE = "wq_isq"; + private static final String FIELD_WQ_W = "W"; + private static final String FIELD_WQ_Q = "Q"; /** Stores the min/max values for each w range (gauge). */ - protected Map<String, double[]> wranges; - - /** The RadioGroupItem that determines the w/q input mode. */ - protected DynamicForm modes; + private final Map<String, double[]> wranges = new HashMap<String, double[]>(); - /** List of wTables in inputhelper section. */ - protected List<WTable> wTables; - - /** List of QDTables in inputhelper section. */ - protected List<QDTable> qdTables; - - /** Tabs in inputhelper area. */ - protected TabSet tabs; + /** Service to fetch W/Q MainValues. */ + private final WQInfoServiceAsync wqInfoService = GWT.create(WQInfoService.class); /** The currently focussed Input element. */ - protected DoubleArrayPanel itemWithFocus; + private DoubleArrayPanel itemWithFocus; - public WQAdaptedInputPanel() { - this.wqranges = new HashMap<String, DoubleArrayPanel>(); - this.doubleArrayPanels = new ArrayList<DoubleArrayPanel>(); - this.qranges = new HashMap<String, double[]>(); - this.wranges = new HashMap<String, double[]>(); - this.wTables = new ArrayList<WTable>(); - this.qdTables = new ArrayList<QDTable>(); + private void enableWTabs() { + for (int i = 0; i < this.doubleArrayPanels.size(); i++) { + this.tabs.disableTab(2 * i); + this.tabs.enableTab(2 * i + 1); + } } - /** Create labels, canvasses, layouts. */ - @Override - public Canvas create(final DataList data) { - readGaugeRanges(data); - initHelperPanel(); - - final Canvas submit = getNextButton(); - final Canvas widget = createWidget(data); - final Label label = new Label(this.MSG.wqadaptedTitle()); - - label.setHeight(25); + private void enableQTabs() { + for (int i = 0; i < this.doubleArrayPanels.size(); i++) { + this.tabs.enableTab(2 * i); + this.tabs.disableTab(2 * i + 1); + } + } - final VLayout layout = new VLayout(); - layout.setMembersMargin(10); - layout.setWidth(350); + /** + * Create radio button for switching w and q input. + * Radiobutton-change also triggers helper panel tab selection. + */ - layout.addMember(label); - layout.addMember(widget); - layout.addMember(submit); + private final Canvas createMode(final DataList dataList) { + final RadioGroupItem wq = new RadioGroupItem(FIELD_WQ_MODE); + wq.setShowTitle(false); + wq.setVertical(false); + wq.setWidth(200); - fetchWQData(); + final LinkedHashMap<String, String> wqValues = new LinkedHashMap<String, String>(); + wqValues.put(FIELD_WQ_W, this.MSG.wqW()); + wqValues.put(WQAdaptedInputPanel.FIELD_WQ_Q, this.MSG.wqQatGauge()); - initTableListeners(); + wq.setValueMap(wqValues); + this.modes = new DynamicForm(); + this.modes.setFields(wq); + this.modes.setWidth(200); + wq.addChangeHandler(new ChangeHandler() { + @Override + public void onChange(final ChangeEvent e) { + final DynamicForm form = e.getForm(); + + if (form.getValueAsString(FIELD_WQ_MODE).contains("Q")) { + WQAdaptedInputPanel.this.tabs.selectTab(0); + enableQTabs(); + } else { + WQAdaptedInputPanel.this.tabs.selectTab(1); + enableWTabs(); + } + } + }); + + final LinkedHashMap<String, String> initial = new LinkedHashMap<String, String>(); + initial.put(FIELD_WQ_MODE, this.FIELD_WQ_Q); + this.modes.setValues(initial); + this.tabs.selectTab(1); + return this.modes; + } + + @Override + protected void createTabs() { + for (int i = 0; i < this.gaugeRanges.size(); i++) { + // Later the tabs title will get adjusted to include gauges name. + // TODO the tabs title becomes rather long through that (i18n). + + final Tab wTab = new Tab(this.MSG.wq_table_w()); + final WTable wTable = new WTable(); + this.wTables.add(wTable); + wTable.showSelect(); + wTab.setPane(wTable); + + final Tab qTab = new Tab(this.MSG.wq_table_q()); + final QDTable qdTable = new QDTable(); + this.qdTables.add(qdTable); + qTab.setPane(qdTable); + qdTable.showSelect(); + + this.tabs.addTab(wTab, i * 2 + 0); + this.tabs.addTab(qTab, i * 2 + 1); + + } + + // Defaults at "Q", first input field. + this.tabs.selectTab(0); + enableQTabs(); + } + + @Override + protected void beforeCreate(final DataList data) { + } + + @Override + protected void afterCreate() { // We actually want the first Q tab to be selected and all // Q tabs to be enabled. I sense a bug in TabSet here, as // the code in the W/Q radiogroup-changehandler behaves // exactly vice versa (enabling Q, selecting tab 0). enableWTabs(); this.tabs.selectTab(1); + } + + @Override + protected Canvas createWidget(final DataList dataList) { + final VLayout layout = new VLayout(); + final Canvas mode = createMode(dataList); + final Canvas list = createList(dataList); + + final List<WQDataItem> items = getWQItems(dataList); + final int listHeight = ROW_HEIGHT * items.size(); + + mode.setHeight(25); + mode.setWidth(200); + + layout.addMember(mode); + layout.addMember(list); + + layout.setHeight(25 + listHeight); + layout.setWidth(350); + + initUserDefaults(dataList); return layout; } - /** Inits the helper panel. */ - // TODO duplicate in WQInputPanel - protected void initHelperPanel() { - this.tabs = new TabSet(); - this.tabs.setWidth100(); - this.tabs.setHeight100(); - - // For each gauge, add two tabs with helper tables. - - for (int i = 0; i < this.gaugeRanges.size(); i++) { - // Later the tabs title will get adjusted to include gauges name. - // TODO the tabs title becomes rather long through that (i18n). - final Tab wTab = new Tab(this.MESSAGE.wq_table_w()); - final Tab qTab = new Tab(this.MESSAGE.wq_table_q()); - - final QDTable qdTable = new QDTable(); - final WTable wTable = new WTable(); - - this.wTables.add(wTable); - this.qdTables.add(qdTable); - - qdTable.showSelect(); - wTable.showSelect(); - wTab.setPane(wTable); - qTab.setPane(qdTable); - - this.tabs.addTab(wTab, i * 2 + 0); - this.tabs.addTab(qTab, i * 2 + 1); - // tabs.disableTab(i*2+1); - } - - // Defaults at "Q", first input field. - this.tabs.selectTab(0); - enableQTabs(); - - this.helperContainer.addMember(this.tabs); + private void initUserDefaults(final DataList dataList) { + initUserWQValues(dataList); + initUserWQMode(dataList); } - /** - * Initializes the listeners of the WQD tables. - */ - // TODO dupe from WQInputPanel - protected void initTableListeners() { - int i = 0; - for (final QDTable qdTable : this.qdTables) { - // Register listener such that values are filled in on click. - final QDTable table = qdTable; - final int fi = i; - final CellClickHandler handler = new CellClickHandler() { - @Override - public void onCellClick(final CellClickEvent e) { - if (isWMode() || table.isLocked()) { - return; - } - - final Record r = e.getRecord(); - final double val = r.getAttributeAsDouble("value"); - - WQAdaptedInputPanel.this.doubleArrayPanels.get(fi).setValues(new double[] { val }); - // If a named value for first gauge is chosen, - // try to find and set - // the values to the other panels too. - if (fi == 0) { - final String valueName = r.getAttribute("name"); - int oi = 0; - // TODO instead of oi use random access. - for (final QDTable otherQDTable : WQAdaptedInputPanel.this.qdTables) { - if (oi == 0) { - oi++; - continue; - } - final Double value = otherQDTable.findRecordValue(valueName); - if (value == null) { - SC.warn(WQAdaptedInputPanel.this.MSG.noMainValueAtGauge()); - } else { - WQAdaptedInputPanel.this.doubleArrayPanels.get(oi).setValues(new double[] { value }); - } - oi++; - } - } else { - // Focus next. - if (fi != WQAdaptedInputPanel.this.doubleArrayPanels.size() - 1) { - WQAdaptedInputPanel.this.doubleArrayPanels.get(fi + 1).focusInItem(1); - } - } - } - }; + private void initUserWQMode(final DataList dataList) { + final List<Data> allData = dataList.getAll(); - qdTable.addCellClickHandler(handler); - i++; - } - - i = 0; - for (final WTable wTable : this.wTables) { - // Register listener such that values are filled in on click. - final WTable table = wTable; - final int fi = i; - final CellClickHandler handler = new CellClickHandler() { - @Override - public void onCellClick(final CellClickEvent e) { - if (!isWMode() /* || table.isLocked() */) { - return; - } - - final Record r = e.getRecord(); - final double val = r.getAttributeAsDouble("value"); + final Data dDef = getData(allData, "wq_mode"); + final DataItem def = dDef != null ? dDef.getDefault() : null; + final String value = def != null ? def.getStringValue() : null; - WQAdaptedInputPanel.this.doubleArrayPanels.get(fi).setValues(new double[] { val }); - // If a named value for first gauge is chosen, - // try to find and set - // the values to the other panels too. - if (fi == 0) { - final String valueName = r.getAttribute("name"); - int oi = 0; - // TODO instead of oi use random access. - for (final WTable otherWTable : WQAdaptedInputPanel.this.wTables) { - if (oi == 0) { - oi++; - continue; - } - final Double value = otherWTable.findRecordValue(valueName); - if (value == null) { - // TODO: afterwards it freaks out - SC.warn(WQAdaptedInputPanel.this.MSG.noMainValueAtGauge()); - } else { - WQAdaptedInputPanel.this.doubleArrayPanels.get(oi).setValues(new double[] { value }); - } - oi++; - } - } else { - // Focus next. - if (fi != WQAdaptedInputPanel.this.doubleArrayPanels.size() - 1) { - WQAdaptedInputPanel.this.doubleArrayPanels.get(fi + 1).focusInItem(1); - } - } - } - }; - - wTable.addCellClickHandler(handler); - i++; + if (value != null && value.equals(FIELD_WQ_W)) { + this.modes.setValue(FIELD_WQ_MODE, FIELD_WQ_W); + } else { + this.modes.setValue(FIELD_WQ_MODE, FIELD_WQ_Q); } } + private Canvas createList(final DataList dataList) { + final VLayout layout = new VLayout(); + + final List<WQDataItem> items = getWQItems(dataList); + + int i = 0; + + for (final DataItem item : items) { + if (item instanceof WQDataItem) { + final String title = item.getLabel(); // of form: 70.5;112.0 + final String label = item.getStringValue(); + + // Rename W and Q tab to include gauges name. + this.tabs.getTab(i * 2).setTitle(this.tabs.getTab(i * 2).getTitle() + " (" + label + ")"); + this.tabs.getTab(i * 2 + 1).setTitle(this.tabs.getTab(i * 2 + 1).getTitle() + " (" + label + ")"); + + final DoubleArrayPanel dap = new DoubleArrayPanel(label, null, this, this, TitleOrientation.LEFT); + + this.wqranges.put(title, dap); + this.doubleArrayPanels.add(dap); + + if (item instanceof WQDataItem) { + final WQDataItem wq = (WQDataItem) item; + final double[] mmQ = wq.getQRange(); + final double[] mmW = wq.getWRange(); + + this.qranges.put(title, mmQ); + this.wranges.put(title, mmW); + } + + layout.addMember(dap); + i++; + } + + } + + layout.setHeight(items.size() * ROW_HEIGHT); + + return layout; + } + @Override - public Canvas createOld(final DataList dataList) { + public Canvas createOld(final DataList dataList) { // TODO: OVERRIDE final List<Data> all = dataList.getAll(); final Data wqData = getData(all, "wq_values"); final Data wqMode = getData(all, "wq_isq"); @@ -343,78 +280,6 @@ return vlayout; } - /** Create area showing previously entered w or q data. */ - protected Canvas createOldWQValues(final Data wqData, final boolean isQ) { - final VLayout layout = new VLayout(); - - final DataItem item = wqData.getItems()[0]; - final String value = item.getStringValue(); - - final String[] gauges = value.split(GAUGE_SEPARATOR); - - final String unit = isQ ? "m³/s" : "cm"; - - for (final String gauge : gauges) { - final HLayout h = new HLayout(); - - final String[] parts = gauge.split(GAUGE_PART_SEPARATOR); - final String[] values = parts[3].split(VALUE_SEPARATOR); - - final Label l = new Label(parts[2] + ": "); - - final StringBuilder sb = new StringBuilder(); - boolean first = true; - - for (final String v : values) { - if (!first) { - sb.append(", "); - } - - sb.append(v); - sb.append(" "); - sb.append(unit); - - first = false; - } - - final Label v = new Label(sb.toString()); - - l.setWidth(65); - v.setWidth(65); - - h.addMember(l); - h.addMember(v); - - layout.addMember(h); - } - - return layout; - } - - /** Create non-input helper part of the UI. */ - protected Canvas createWidget(final DataList dataList) { - final VLayout layout = new VLayout(); - - final Canvas mode = createMode(dataList); - final Canvas list = createList(dataList); - - final DataItem[] items = getWQItems(dataList); - final int listHeight = ROW_HEIGHT * items.length; - - mode.setHeight(25); - mode.setWidth(200); - - layout.addMember(mode); - layout.addMember(list); - - layout.setHeight(25 + listHeight); - layout.setWidth(350); - - initUserDefaults(dataList); - - return layout; - } - @Override public List<String> validate() { if (isWMode()) { @@ -424,6 +289,12 @@ } } + private boolean isWMode() { + final String mode = (String) this.modes.getValue(FIELD_WQ_MODE); + + return FIELD_WQ_W.equals(mode); + } + protected List<String> validateRange(final Map<String, double[]> ranges) { final List<String> errors = new ArrayList<String>(); final NumberFormat nf = NumberFormat.getDecimalFormat(); @@ -477,233 +348,7 @@ return errors; } - protected List<String> validateW() { - return validateRange(this.wranges); - } - - protected List<String> validateQ() { - return validateRange(this.qranges); - } - - protected void initUserDefaults(final DataList dataList) { - initUserWQValues(dataList); - initUserWQMode(dataList); - } - - protected void initUserWQMode(final DataList dataList) { - final List<Data> allData = dataList.getAll(); - - final Data dDef = getData(allData, "wq_mode"); - final DataItem def = dDef != null ? dDef.getDefault() : null; - final String value = def != null ? def.getStringValue() : null; - - if (value != null && value.equals(FIELD_WQ_W)) { - this.modes.setValue(FIELD_WQ_MODE, FIELD_WQ_W); - } else { - this.modes.setValue(FIELD_WQ_MODE, FIELD_WQ_Q); - } - } - - protected void initUserWQValues(final DataList dataList) { - final List<Data> allData = dataList.getAll(); - - final Data dDef = getData(allData, "wq_values"); - final DataItem def = dDef != null ? dDef.getDefault() : null; - final String value = def != null ? def.getStringValue() : null; - - if (value == null || value.length() == 0) { - return; - } - - final String[] lines = value.split(GAUGE_SEPARATOR); - - if (lines == null || lines.length == 0) { - return; - } - - for (final String line : lines) { - final String[] cols = line.split(GAUGE_PART_SEPARATOR); - final String title = createLineTitle(line); - - if (cols == null || cols.length < 3) { - continue; - } - - final String[] strValues = cols[2].split(VALUE_SEPARATOR); - final double[] values = new double[strValues.length]; - - int idx = 0; - - for (final String strValue : strValues) { - try { - values[idx++] = Double.valueOf(strValue); - } - catch (final NumberFormatException nfe) { - // do nothing - } - } - - final String key = cols[0] + GAUGE_PART_SEPARATOR + cols[1]; - final DoubleArrayPanel dap = this.wqranges.get(key); - - if (dap == null) { - continue; - } - - dap.setValues(values); - } - } - - /** Populate Gauge Ranges array. */ - private void readGaugeRanges(final DataList dataList) { - final DataItem[] items = getWQItems(dataList); - this.gaugeRanges = new ArrayList<Double[]>(); - - int i = 0; - - for (final DataItem item : items) { - if (item instanceof WQDataItem) { - final String[] startEndKm = item.getLabel().split(";"); - final Double[] kvp = new Double[] { Double.parseDouble(startEndKm[0]), Double.parseDouble(startEndKm[1]) }; - this.gaugeRanges.add(kvp); - } - i++; - } - } - - protected Canvas createList(final DataList dataList) { - final VLayout layout = new VLayout(); - - final DataItem[] items = getWQItems(dataList); - - int i = 0; - - for (final DataItem item : items) { - if (item instanceof WQDataItem) { - final String title = item.getLabel(); // of form: 70.5;112.0 - final String label = item.getStringValue(); - - // Rename W and Q tab to include gauges name. - this.tabs.getTab(i * 2).setTitle(this.tabs.getTab(i * 2).getTitle() + " (" + label + ")"); - this.tabs.getTab(i * 2 + 1).setTitle(this.tabs.getTab(i * 2 + 1).getTitle() + " (" + label + ")"); - - final DoubleArrayPanel dap = new DoubleArrayPanel(label, null, this, this, TitleOrientation.LEFT); - - this.wqranges.put(title, dap); - this.doubleArrayPanels.add(dap); - - if (item instanceof WQDataItem) { - final WQDataItem wq = (WQDataItem) item; - final double[] mmQ = wq.getQRange(); - final double[] mmW = wq.getWRange(); - - this.qranges.put(title, mmQ); - this.wranges.put(title, mmW); - } - - layout.addMember(dap); - } - i++; - } - - layout.setHeight(items.length * ROW_HEIGHT); - - return layout; - } - - /** Get items which are not WQ_MODE. */ - protected DataItem[] getWQItems(final DataList dataList) { - final List<Data> data = dataList.getAll(); - - for (final Data d : data) { - final String name = d.getLabel(); - - if (name.equals(FIELD_WQ_MODE) || name.startsWith("ignore_")) { - continue; - } - - return d.getItems(); - } - - return null; - } - - /** - * Create radio button for switching w and q input. - * Radiobutton-change also triggers helper panel tab selection. - */ - protected Canvas createMode(final DataList dataList) { - final RadioGroupItem wq = new RadioGroupItem(FIELD_WQ_MODE); - wq.setShowTitle(false); - wq.setVertical(false); - wq.setWidth(200); - - final LinkedHashMap wqValues = new LinkedHashMap(); - wqValues.put(FIELD_WQ_W, this.MSG.wqW()); - wqValues.put(FIELD_WQ_Q, this.MSG.wqQatGauge()); - - wq.setValueMap(wqValues); - - this.modes = new DynamicForm(); - this.modes.setFields(wq); - this.modes.setWidth(200); - wq.addChangeHandler(new ChangeHandler() { - @Override - public void onChange(final ChangeEvent e) { - final DynamicForm form = e.getForm(); - - if (form.getValueAsString(FIELD_WQ_MODE).contains("Q")) { - WQAdaptedInputPanel.this.tabs.selectTab(0); - enableQTabs(); - } else { - WQAdaptedInputPanel.this.tabs.selectTab(1); - enableWTabs(); - } - } - }); - - final LinkedHashMap initial = new LinkedHashMap(); - initial.put(FIELD_WQ_MODE, FIELD_WQ_Q); - this.modes.setValues(initial); - this.tabs.selectTab(1); - return this.modes; - } - - public void enableWTabs() { - for (int i = 0; i < this.doubleArrayPanels.size(); i++) { - this.tabs.disableTab(2 * i); - this.tabs.enableTab(2 * i + 1); - } - } - - public void enableQTabs() { - for (int i = 0; i < this.doubleArrayPanels.size(); i++) { - this.tabs.enableTab(2 * i); - this.tabs.disableTab(2 * i + 1); - } - } - - public String createLineTitle(final String key) { - final String[] splitted = key.split(";"); - - return splitted[0] + " - " + splitted[1]; - } - - @Override - public Data[] getData() { - final Data mode = getWQMode(); - final Data values = getWQValues(); - - return new Data[] { mode, values }; - } - - public boolean isWMode() { - final String mode = (String) this.modes.getValue(FIELD_WQ_MODE); - - return FIELD_WQ_W.equals(mode); - } - - protected Data getWQMode() { + private Data getWQMode() { final String wqMode = this.modes.getValueAsString(FIELD_WQ_MODE); String value = "false"; if (wqMode.equals("Q")) { @@ -715,52 +360,22 @@ return mode; } - protected Data getWQValues() { - String wqvalue = null; - - for (final Map.Entry<String, DoubleArrayPanel> entry : this.wqranges.entrySet()) { - final String key = entry.getKey(); - final DoubleArrayPanel dap = entry.getValue(); - final String label = dap.getItemTitle(); + @Override + public Data[] getData() { + final Data mode = getWQMode(); + final Data values = getWQValues("wq_values"); - final double[] values = dap.getInputValues(); - if (wqvalue == null) { - wqvalue = createValueString(key + ";" + label, values); - } else { - wqvalue += GAUGE_SEPARATOR + createValueString(key + ";" + label, values); - } - } - - final DataItem valueItem = new DefaultDataItem("wq_values", "wq_values", wqvalue); - final Data values = new DefaultData("wq_values", null, null, new DataItem[] { valueItem }); - - return values; + return new Data[] { mode, values }; } - protected String createValueString(final String key, final double[] values) { - final StringBuilder sb = new StringBuilder(); - - boolean first = true; - - for (final double value : values) { - if (!first) { - sb.append(","); - } - - sb.append(Double.toString(value)); - - first = false; - } - - return key + ";" + sb.toString(); + private List<String> validateW() { + return validateRange(this.wranges); } - @Override - public void onChange(final ChangeEvent event) { - // TODO IMPLEMENT ME + private List<String> validateQ() { + return validateRange(this.qranges); } - /** Store the currently focussed DoubleArrayPanel and focus helper tab. */ @Override public void onFocus(final FocusEvent event) { this.itemWithFocus = (DoubleArrayPanel) event.getForm(); @@ -771,93 +386,8 @@ } @Override - public void onBlur(final BlurEvent event) { - final DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm(); - dap.validateForm(event.getItem()); + protected void callMainValuesService(final String locale, final String river, final double start, final double end, + final AsyncCallback<WQInfoObject[]> cb) { + this.wqInfoService.getWQInfo(locale, river, start, end, cb); } - - /** Get the WQD data from service and stuck them up that tables. */ - protected void fetchWQData() { - final Config config = Config.getInstance(); - final String locale = config.getLocale(); - - final ArtifactDescription adescr = this.artifact.getArtifactDescription(); - final DataList[] data = adescr.getOldData(); - - final double[] mm = getMinMaxKM(data); - final String river = getRiverName(data); - - int i = 0; - - // Get Data for respective gauge. - for (final Double[] range : this.gaugeRanges) { - // Gauge ranges overlap, move start and end a bit closer - // to each other. - final double rDiff = (range[1] - range[0]) / 10d; - final int fi = i; - this.wqInfoService.getWQInfo(locale, river, range[0] + rDiff, range[1] - rDiff, new AsyncCallback<WQInfoObject[]>() { - @Override - public void onFailure(final Throwable caught) { - GWT.log("Could not recieve wq informations."); - SC.warn(caught.getMessage()); - } - - @Override - public void onSuccess(final WQInfoObject[] wqi) { - final int num = wqi != null ? wqi.length : 0; - GWT.log("Received " + num + " wq informations (" + fi + "."); - - if (num == 0) { - return; - } - - addWQInfo(wqi, fi); - } - }); - i++; - } - } - - /** Add Info to helper table for gauge at index gaugeIdx. */ - protected void addWQInfo(final WQInfoObject[] wqi, final int gaugeIdx) { - for (final WQInfoObject wi : wqi) { - final WQInfoRecord rec = new WQInfoRecord(wi); - - if (wi.getType().equals("W")) { - this.wTables.get(gaugeIdx).addData(rec); - } else { - this.qdTables.get(gaugeIdx).addData(rec); - } - } - } - - /** - * Determines the min and max kilometer value selected in a former state. A - * bit silly, but we need to run over each value of the "old data" to find - * such values because it is not available here. - * - * @param data - * The DataList which contains the whole data inserted for the - * current artifact. - * - * @return a double array with [min, max]. - */ - protected double[] getMinMaxKM(final DataList[] data) { - final ArtifactDescription adesc = this.artifact.getArtifactDescription(); - return adesc.getKMRange(); - } - - /** - * Returns the name of the selected river. - * - * @param data - * The DataList with all data. - * - * @return the name of the current river. - */ - protected String getRiverName(final DataList[] data) { - final ArtifactDescription adesc = this.artifact.getArtifactDescription(); - return adesc.getRiver(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +} \ No newline at end of file