teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.client.ui; ingo@42: ingo@42: import com.google.gwt.core.client.GWT; ingo@564: import com.google.gwt.i18n.client.NumberFormat; raimund@248: import com.google.gwt.user.client.rpc.AsyncCallback; raimund@248: raimund@248: import com.smartgwt.client.data.Record; ingo@579: import com.smartgwt.client.util.SC; ingo@42: import com.smartgwt.client.widgets.Canvas; ingo@42: import com.smartgwt.client.widgets.Label; ingo@42: import com.smartgwt.client.widgets.form.DynamicForm; ingo@42: import com.smartgwt.client.widgets.form.fields.FormItem; ingo@42: import com.smartgwt.client.widgets.form.fields.RadioGroupItem; ingo@42: import com.smartgwt.client.widgets.form.fields.events.BlurEvent; christian@4568: import com.smartgwt.client.widgets.form.fields.events.BlurHandler; christian@4568: import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; ingo@42: import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; christian@4568: import com.smartgwt.client.widgets.grid.events.CellClickEvent; christian@4568: import com.smartgwt.client.widgets.grid.events.CellClickHandler; ingo@53: import com.smartgwt.client.widgets.layout.HLayout; ingo@42: import com.smartgwt.client.widgets.layout.VLayout; christian@4568: import com.smartgwt.client.widgets.tab.Tab; ingo@580: import com.smartgwt.client.widgets.tab.TabSet; ingo@42: teichmann@5835: import org.dive4elements.river.client.client.Config; teichmann@5835: import org.dive4elements.river.client.client.FLYSConstants; teichmann@5835: import org.dive4elements.river.client.client.services.WQInfoService; teichmann@5835: import org.dive4elements.river.client.client.services.WQInfoServiceAsync; teichmann@5835: import org.dive4elements.river.client.client.ui.wq.QDTable; teichmann@5835: import org.dive4elements.river.client.client.ui.wq.WTable; teichmann@5835: import org.dive4elements.river.client.shared.model.ArtifactDescription; teichmann@5835: import org.dive4elements.river.client.shared.model.Data; teichmann@5835: import org.dive4elements.river.client.shared.model.DataItem; teichmann@5835: import org.dive4elements.river.client.shared.model.DataList; teichmann@5835: import org.dive4elements.river.client.shared.model.DefaultData; teichmann@5835: import org.dive4elements.river.client.shared.model.DefaultDataItem; teichmann@5835: import org.dive4elements.river.client.shared.model.WQInfoObject; teichmann@5835: import org.dive4elements.river.client.shared.model.WQInfoRecord; raimund@248: christian@4568: import java.util.ArrayList; christian@4568: import java.util.LinkedHashMap; christian@4568: import java.util.List; ingo@42: ingo@42: ingo@42: /** ingo@42: * This UIProvider creates a widget to enter W or Q data. ingo@42: * ingo@42: * @author Ingo Weinzierl ingo@42: */ ingo@42: public class WQInputPanel ingo@42: extends AbstractUIProvider ingo@42: implements ChangeHandler, BlurHandler ingo@42: { christian@4568: private static final long serialVersionUID = 4797387993390350341L; christian@4568: ingo@42: /** The message class that provides i18n strings.*/ raimund@248: protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); ingo@42: raimund@248: protected WQInfoServiceAsync wqInfoService = raimund@248: GWT.create(WQInfoService.class); ingo@42: ingo@42: /** The constant field name for choosing w or q mode.*/ sascha@1535: public static final String FIELD_WQ_W_FREE = "WFREE"; sascha@1535: sascha@1535: /** The constant field name for choosing w or q mode.*/ ingo@42: public static final String FIELD_WQ = "wq"; ingo@42: ingo@42: /** The constant field value for W input mode.*/ ingo@42: public static final String FIELD_WQ_W = "W"; ingo@42: ingo@42: /** The constant field value for Q input mode.*/ ingo@42: public static final String FIELD_WQ_Q = "Q"; ingo@42: ingo@577: /** The constant field value for Q input mode.*/ ingo@2392: public static final String FIELD_WQ_Q_FREE = "QFREE"; ingo@577: ingo@42: /** The constant field name for choosing single values or range.*/ ingo@42: public static final String FIELD_MODE = "mode"; ingo@42: ingo@42: /** The constant field value for single input mode.*/ ingo@42: public static final String FIELD_MODE_SINGLE = "single"; ingo@42: ingo@42: /** The constant field value for range input mode.*/ ingo@42: public static final String FIELD_MODE_RANGE = "range"; ingo@42: ingo@42: /** The constant value that determines the width of the left panel.*/ ingo@596: public static final int WIDTH_LEFT_UPPER = 400; ingo@577: ingo@596: public static final int WIDTH_LEFT_LOWER = 223; ingo@42: ingo@42: /** The container that manages the w and q panels.*/ raimund@248: protected HLayout container; ingo@42: ingo@42: /** The RadioGroupItem that determines the w/q input mode.*/ ingo@42: protected DynamicForm modes; ingo@42: ingo@56: /** The min values for the 'from' property in the W-Range input mode.*/ ingo@56: protected double minW; ingo@56: ingo@56: /** The min values for the 'from' property in the Q-Range input mode.*/ ingo@56: protected double minQ; ingo@56: ingo@1485: /** The min value for the 'from' property in the free Q-Range input mode.*/ ingo@1485: protected double minQFree; ingo@1485: raimund@2473: /** The min value for the 'from' property in the free W-Range input mode.*/ raimund@2473: protected double minWFree; raimund@2473: ingo@56: /** The max values for the 'from' property in the W-Range input mode.*/ ingo@56: protected double maxW; ingo@56: ingo@56: /** The max values for the 'from' property in the Q-Range input mode.*/ ingo@56: protected double maxQ; ingo@56: ingo@1485: /** The max value for the 'from' property in the free Q-Range input mode.*/ ingo@1485: protected double maxQFree; ingo@1485: raimund@2473: /** The max value for the 'from' property in the free W-Range input mode.*/ raimund@2473: protected double maxWFree; raimund@2473: ingo@42: /** The 'from' value entered in the range W mode.*/ ingo@42: protected double fromW; ingo@42: ingo@42: /** The 'to' value entered in the range W mode.*/ ingo@42: protected double toW; ingo@42: ingo@42: /** The 'step' value entered in the range W mode.*/ ingo@42: protected double stepW; ingo@42: ingo@42: /** The values entered in the single W mode.*/ ingo@42: protected double[] valuesW; ingo@42: raimund@2473: /** The values entered in the single W mode.*/ raimund@2473: protected double[] valuesWFree; raimund@2473: ingo@42: /** The 'from' value entered in the range Q mode.*/ ingo@42: protected double fromQ; ingo@42: ingo@1485: /** The 'from' value entered in the range free Q mode.*/ ingo@1485: protected double fromQFree; ingo@1485: raimund@2473: /** The 'from' value entered in the range free W mode.*/ raimund@2473: protected double fromWFree; raimund@2473: ingo@42: /** The 'to' value entered in the range Q mode.*/ ingo@42: protected double toQ; ingo@42: ingo@1485: /** The 'to' value entered in the range free Q mode.*/ ingo@1485: protected double toQFree; ingo@1485: raimund@2473: /** The 'to' value entered in the range free W mode.*/ raimund@2473: protected double toWFree; raimund@2473: ingo@42: /** The 'step' value entered in the range Q mode.*/ ingo@42: protected double stepQ; ingo@42: ingo@1485: /** The 'step' value entered in the range free Q mode.*/ ingo@1485: protected double stepQFree; ingo@1485: raimund@2473: /** The 'step' value entered in the range free W mode.*/ raimund@2473: protected double stepWFree; raimund@2473: ingo@42: /** The values entered in the single Q mode.*/ ingo@42: protected double[] valuesQ; ingo@42: ingo@1485: /** The values entered in the single free Q mode.*/ ingo@1485: protected double[] valuesQFree; ingo@1485: raimund@249: /** The input panel for W values*/ raimund@249: protected DoubleArrayPanel wArrayPanel; raimund@249: raimund@249: /** The input panel for q values*/ raimund@249: protected DoubleArrayPanel qArrayPanel; raimund@249: ingo@1485: /** The input panel for free q values*/ ingo@1485: protected DoubleArrayPanel qFreeArrayPanel; ingo@1485: raimund@2473: /** The input panel for free w values*/ raimund@2473: protected DoubleArrayPanel wFreeArrayPanel; raimund@2473: raimund@249: /** The input panel for w range*/ raimund@249: protected DoubleRangePanel wRangePanel; raimund@249: raimund@249: /** The input panel for q range*/ raimund@249: protected DoubleRangePanel qRangePanel; raimund@249: ingo@1485: /** The input panel for free q range*/ ingo@1485: protected DoubleRangePanel qFreeRangePanel; ingo@1485: raimund@2473: /** The input panel for free w range*/ raimund@2473: protected DoubleRangePanel wFreeRangePanel; raimund@2473: ingo@580: protected QDTable qdTable; raimund@248: ingo@580: protected WTable wTable; raimund@248: ingo@580: protected TabSet tabs; ingo@42: ingo@42: /** ingo@42: * Creates a new WQInputPanel instance. ingo@42: */ ingo@42: public WQInputPanel() { ingo@580: qdTable = new QDTable(); ingo@580: wTable = new WTable(); raimund@912: raimund@912: initTableListeners(); raimund@912: } raimund@912: raimund@912: raimund@912: /** raimund@912: * Initializes the listeners of the WQD tables. raimund@912: */ raimund@912: protected void initTableListeners() { raimund@912: CellClickHandler handler = new CellClickHandler() { christian@4568: @Override raimund@912: public void onCellClick(CellClickEvent e) { raimund@1369: if (isWMode() || qdTable.isLocked()) { raimund@912: return; raimund@912: } raimund@912: raimund@912: int idx = e.getColNum(); raimund@912: Record r = e.getRecord (); raimund@912: double val = r.getAttributeAsDouble("value"); raimund@912: raimund@912: if (idx == 0) { raimund@912: if (isRangeMode()) { raimund@912: qRangePanel.setFrom(val); raimund@912: } raimund@912: else { raimund@912: qArrayPanel.addValue(val); raimund@912: } raimund@912: } raimund@912: else if (idx == 1) { raimund@912: if (isRangeMode()) { raimund@912: qRangePanel.setTo(val); raimund@912: } raimund@912: else { raimund@912: qArrayPanel.addValue(val); raimund@912: } raimund@912: } raimund@912: } raimund@912: }; raimund@912: raimund@912: qdTable.addCellClickHandler(handler); ingo@42: } ingo@42: ingo@42: ingo@42: /** ingo@42: * This method calls createWidget and puts a 'next' button to the bottom. ingo@42: * ingo@42: * @param data The data that is displayed. ingo@42: * ingo@42: * @return the widget. ingo@42: */ christian@4568: @Override ingo@51: public Canvas create(DataList data) { ingo@56: initDefaults(data); ingo@56: ingo@42: Canvas widget = createWidget(data); ingo@57: Canvas submit = getNextButton(); raimund@248: Label label = new Label(MESSAGE.wqTitle()); ingo@42: ingo@42: label.setHeight(25); ingo@42: ingo@42: VLayout layout = new VLayout(); ingo@83: layout.setMembersMargin(10); ingo@83: ingo@42: layout.addMember(label); ingo@42: layout.addMember(widget); ingo@42: layout.addMember(submit); ingo@42: ingo@580: initHelperPanel(); ingo@519: initUserDefaults(data); ingo@519: ingo@42: return layout; ingo@42: } ingo@42: ingo@42: felix@5334: /** Inits the helper panel. */ felix@5334: // TODO duplicate in WQAdaptedInputPanel ingo@580: protected void initHelperPanel() { ingo@580: tabs = new TabSet(); ingo@580: tabs.setWidth100(); ingo@580: tabs.setHeight100(); ingo@580: ingo@2460: Tab wTab = new Tab(MESSAGE.wq_table_w()); ingo@2460: Tab qTab = new Tab(MESSAGE.wq_table_q()); ingo@580: raimund@3543: qdTable.showSelect(); ingo@580: wTab.setPane(wTable); ingo@580: qTab.setPane(qdTable); ingo@580: ingo@580: tabs.addTab(wTab, 0); ingo@580: tabs.addTab(qTab, 1); ingo@580: ingo@788: helperContainer.addMember(tabs); ingo@580: ingo@580: fetchWQData(); ingo@580: } ingo@580: ingo@580: christian@4568: @Override ingo@53: public Canvas createOld(DataList dataList) { ingo@53: List items = dataList.getAll(); ingo@53: ingo@2392: Data dMode = getData(items, "wq_isq"); ingo@2392: Data dFree = getData(items, "wq_isfree"); ingo@2392: Data dSelection = getData(items, "wq_isrange"); ingo@236: Data dSingle = getData(items, "wq_single"); ingo@236: Data dFrom = getData(items, "wq_from"); ingo@236: Data dTo = getData(items, "wq_to"); ingo@236: Data dStep = getData(items, "wq_step"); ingo@53: ingo@53: DataItem[] mode = dMode.getItems(); ingo@236: String strMode = mode[0].getStringValue(); ingo@2392: boolean isQMode = Boolean.valueOf(strMode); ingo@53: ingo@595: DataItem[] free = dFree.getItems(); ingo@595: String strFree = free[0].getStringValue(); ingo@595: boolean isFree = Boolean.valueOf(strFree); ingo@595: ingo@53: HLayout layout = new HLayout(); raimund@91: layout.setWidth("400px"); raimund@91: ingo@236: Label label = new Label(dataList.getLabel()); raimund@91: label.setWidth("200px"); ingo@53: ingo@1355: VLayout vLabel = null; ingo@236: ingo@236: DataItem[] selItem = dSelection.getItems(); ingo@2392: boolean isRange = selItem != null ingo@2392: ? Boolean.valueOf(selItem[0].getStringValue()) ingo@2392: : false; ingo@236: ingo@2392: if (!isRange) { ingo@236: DataItem[] single = dSingle.getItems(); ingo@236: ingo@2392: vLabel = !isQMode andre@8624: ? createWString(single[0], isFree) ingo@236: : createQString(single[0]); ingo@236: } ingo@236: else { ingo@236: DataItem[] from = dFrom.getItems(); ingo@236: DataItem[] to = dTo.getItems(); ingo@236: DataItem[] step = dStep.getItems(); ingo@236: ingo@2392: vLabel = !isQMode ingo@236: ? createWString(from[0], to[0], step[0]) ingo@236: : createQString(from[0], to[0], step[0]); ingo@236: } ingo@53: ingo@595: VLayout selectedLayout = new VLayout(); ingo@595: String wqMode = null; ingo@595: ingo@2392: if (!isQMode) { raimund@2473: wqMode = isFree ? MESSAGE.wqWFree() : MESSAGE.wqW(); ingo@595: } ingo@595: else { ingo@595: wqMode = isFree ? MESSAGE.wqQ() : MESSAGE.wqQGauge(); ingo@595: } ingo@595: ingo@595: Label mLabel = new Label(wqMode); ingo@595: mLabel.setWidth(175); ingo@595: mLabel.setHeight(20); ingo@595: ingo@595: selectedLayout.addMember(mLabel); ingo@595: selectedLayout.addMember(vLabel); ingo@595: selectedLayout.setHeight(40); raimund@91: ingo@58: Canvas back = getBackButton(dataList.getState()); ingo@58: ingo@53: layout.addMember(label); ingo@595: layout.addMember(selectedLayout); ingo@58: layout.addMember(back); ingo@53: ingo@53: return layout; ingo@53: } ingo@53: ingo@53: ingo@56: /** ingo@56: * This method reads the default values defined in the DataItems of the Data ingo@56: * objects in list. ingo@56: * ingo@56: * @param list The DataList container that stores the Data objects. ingo@56: */ ingo@56: protected void initDefaults(DataList list) { ingo@56: Data f = getData(list.getAll(), "wq_from"); ingo@56: Data t = getData(list.getAll(), "wq_to"); ingo@56: Data s = getData(list.getAll(), "wq_step"); ingo@56: ingo@1485: DataItem fQItem = getDataItem(f.getItems(), "minQ"); ingo@1485: DataItem fWItem = getDataItem(f.getItems(), "minW"); ingo@1485: DataItem tQItem = getDataItem(t.getItems(), "maxQ"); ingo@1485: DataItem tWItem = getDataItem(t.getItems(), "maxW"); ingo@1485: DataItem sQItem = getDataItem(s.getItems(), "stepQ"); ingo@1485: DataItem sWItem = getDataItem(s.getItems(), "stepW"); ingo@1485: DataItem fQFItem = getDataItem(f.getItems(), "minQFree"); ingo@1485: DataItem tQFItem = getDataItem(t.getItems(), "maxQFree"); ingo@1485: DataItem sQFItem = getDataItem(s.getItems(), "stepQFree"); raimund@2473: DataItem fWFItem = getDataItem(f.getItems(), "minWFree"); raimund@2473: DataItem tWFItem = getDataItem(t.getItems(), "maxWFree"); raimund@2473: DataItem sWFItem = getDataItem(s.getItems(), "stepWFree"); ingo@56: ingo@56: minW = Double.valueOf(fWItem.getStringValue()); ingo@56: maxW = Double.valueOf(tWItem.getStringValue()); ingo@56: stepW = Double.valueOf(sWItem.getStringValue()); ingo@56: ingo@56: minQ = Double.valueOf(fQItem.getStringValue()); ingo@56: maxQ = Double.valueOf(tQItem.getStringValue()); ingo@56: stepQ = Double.valueOf(sQItem.getStringValue()); ingo@56: ingo@1485: minQFree = Double.valueOf(fQFItem.getStringValue()); ingo@1485: maxQFree = Double.valueOf(tQFItem.getStringValue()); ingo@1485: stepQFree = Double.valueOf(sQFItem.getStringValue()); ingo@1485: raimund@2473: minWFree = Double.valueOf(fWFItem.getStringValue()); raimund@2473: maxWFree = Double.valueOf(tWFItem.getStringValue()); raimund@2473: stepWFree = Double.valueOf(sWFItem.getStringValue()); raimund@2473: ingo@56: this.fromW = minW; ingo@56: this.toW = maxW; ingo@56: ingo@56: this.fromQ = minQ; ingo@56: this.toQ = maxQ; ingo@1485: ingo@1485: this.fromQFree = minQFree; ingo@1485: this.toQFree = maxQFree; raimund@2473: raimund@2473: this.fromWFree = minWFree; raimund@2473: this.toWFree = maxWFree; ingo@56: } ingo@56: ingo@56: ingo@519: /** ingo@519: * Initializes the form items with former inserted user data. ingo@519: * ingo@519: * @param list The DataList that contains the user data. ingo@519: */ ingo@519: protected void initUserDefaults(DataList list) { ingo@519: List allData = list.getAll(); ingo@519: ingo@2392: Data m = getData(allData, "wq_isq"); ingo@519: DataItem modeItem = m != null ? m.getDefault() : null; ingo@2392: boolean isQ = modeItem != null ingo@2392: ? Boolean.valueOf(modeItem.getStringValue()) ingo@2392: : false; ingo@595: ingo@2392: Data f = getData(allData, "wq_isfree"); ingo@595: DataItem freeItem = f != null ? f.getDefault() : null; ingo@2392: boolean isFree = freeItem != null ingo@2392: ? Boolean.valueOf(freeItem.getStringValue()) ingo@2392: : false; ingo@519: ingo@2392: Data s = getData(allData, "wq_isrange"); ingo@519: DataItem sI = s != null ? s.getDefault() : null; ingo@2392: boolean isRange = sI != null ingo@2392: ? Boolean.valueOf(sI.getStringValue()) ingo@2392: : false; ingo@519: ingo@2392: initUserSingleValues(list, isQ); ingo@2392: initUserRangeValues(list, isQ); ingo@2392: ingo@2392: if (isQ) { ingo@2392: modes.setValue(FIELD_WQ, isQ); ingo@2392: } ingo@2392: else { ingo@2392: modes.setValue(FIELD_WQ, isFree ? FIELD_WQ_Q_FREE : FIELD_WQ_Q); ingo@519: } ingo@519: ingo@2392: if(isRange) { ingo@2392: modes.setValue(FIELD_MODE, FIELD_MODE_RANGE); ingo@595: } ingo@595: else { ingo@2392: modes.setValue(FIELD_MODE, FIELD_MODE_SINGLE); ingo@595: } ingo@2392: updatePanels(isQ, isFree, isRange); ingo@519: } ingo@519: ingo@519: ingo@519: /** ingo@519: * Initializes the single values of W or Q from DataList. ingo@519: * ingo@519: * @param list The DataList that contains the 'wq_single' object. felix@3351: * @param isQ W or Q mode? ingo@519: */ ingo@2392: protected void initUserSingleValues(DataList list, boolean isQ) { ingo@519: List allData = list.getAll(); ingo@519: ingo@2392: ingo@519: Data s = getData(allData, "wq_single"); ingo@519: DataItem i = s != null ? s.getDefault() : null; ingo@2392: GWT.log("init values: " + i.getStringValue()); ingo@519: ingo@519: if (i != null) { ingo@519: String value = i.getStringValue(); ingo@519: String[] split = value.split(" "); ingo@519: ingo@519: int num = split != null ? split.length : 0; ingo@519: ingo@519: double[] values = new double[num]; ingo@519: ingo@519: for (int j = 0; j < num; j++) { ingo@519: try { ingo@519: values[j] = Double.valueOf(split[j]); ingo@519: } ingo@519: catch (NumberFormatException nfe) { ingo@519: // nothing to do ingo@519: } ingo@519: } ingo@519: ingo@2392: if (!isQ) { ingo@519: setSingleW(values); ingo@519: } ingo@519: else { ingo@519: setSingleQ(values); ingo@519: } ingo@519: } ingo@519: } ingo@519: ingo@519: ingo@519: /** ingo@519: * Initializes the range values of W or Q from DataList. ingo@519: * ingo@519: * @param list The DataList that contains the 'wq_single' object. felix@3351: * @param isQ W or Q mode? ingo@519: */ ingo@2392: protected void initUserRangeValues(DataList list, boolean isQ) { ingo@519: List allData = list.getAll(); ingo@519: ingo@519: // init range mode values ingo@519: Data f = getData(allData, "wq_from"); ingo@519: Data t = getData(allData, "wq_to"); ingo@519: Data s = getData(allData, "wq_step"); ingo@519: ingo@519: if (f != null && t != null && s != null) { ingo@519: DataItem dF = f.getDefault(); ingo@519: DataItem dT = t.getDefault(); ingo@519: DataItem dS = s.getDefault(); ingo@519: ingo@519: String fS = dF != null ? dF.getStringValue() : null; ingo@519: String tS = dT != null ? dT.getStringValue() : null; ingo@519: String sS = dS != null ? dS.getStringValue() : null; ingo@519: ingo@519: try { ingo@519: double from = Double.valueOf(fS); ingo@519: double to = Double.valueOf(tS); ingo@519: double step = Double.valueOf(sS); ingo@519: ingo@2392: if (!isQ) { ingo@519: setWRangeValues(from, to, step); ingo@519: } ingo@519: else { ingo@519: setQRangeValues(from, to, step); ingo@519: } ingo@519: } ingo@519: catch (NumberFormatException nfe) { ingo@519: // do nothing ingo@519: } ingo@519: } ingo@519: } ingo@519: ingo@519: ingo@519: protected void setQRangeValues(double f, double t, double s) { ingo@519: setFromQ(f); ingo@519: setToQ(t); ingo@519: setStepQ(s); ingo@519: } ingo@519: ingo@519: ingo@519: protected void setWRangeValues(double f, double t, double s) { ingo@519: setFromW(f); ingo@519: setToW(t); ingo@519: setStepW(s); ingo@519: } ingo@519: ingo@519: ingo@1355: protected VLayout createWString(DataItem from, DataItem to, DataItem step) { ingo@1355: VLayout v = new VLayout(); ingo@1355: ingo@53: StringBuilder sb = new StringBuilder(); ingo@53: sb.append(from.getLabel()); raimund@248: sb.append(" " + MESSAGE.unitWFrom() + " "); ingo@53: sb.append(to.getLabel()); raimund@248: sb.append(" " + MESSAGE.unitWTo() + " "); ingo@53: sb.append(step.getLabel()); raimund@248: sb.append(" " + MESSAGE.unitWStep()); ingo@53: ingo@1355: v.addMember(new Label(sb.toString())); ingo@1355: ingo@1355: return v; ingo@53: } ingo@53: ingo@53: andre@8624: protected VLayout createWString(DataItem single, boolean isFree) { ingo@1454: String label = single.getLabel().trim(); ingo@1459: String[] cols = label.split(";"); ingo@1355: ingo@1355: VLayout v = new VLayout(); ingo@1355: ingo@1355: for (String col: cols) { andre@8624: Label l = new Label(col + " " + (isFree ? MESSAGE.unitWFree() : MESSAGE.unitWSingle())); ingo@1355: l.setHeight(20); ingo@1355: ingo@1355: v.addMember(l); ingo@1355: } ingo@1355: ingo@1355: return v; ingo@236: } ingo@236: ingo@236: ingo@1355: protected VLayout createQString(DataItem from, DataItem to, DataItem step) { ingo@1355: VLayout v = new VLayout(); ingo@1355: ingo@53: StringBuilder sb = new StringBuilder(); ingo@53: sb.append(from.getLabel()); raimund@248: sb.append(" " + MESSAGE.unitQFrom() + " "); ingo@53: sb.append(to.getLabel()); raimund@248: sb.append(" " + MESSAGE.unitQTo() + " "); ingo@53: sb.append(step.getLabel()); raimund@248: sb.append(" " + MESSAGE.unitQStep()); ingo@53: ingo@1355: v.addMember(new Label(sb.toString())); ingo@1355: ingo@1355: return v; ingo@53: } ingo@53: ingo@53: ingo@1355: protected VLayout createQString(DataItem single) { ingo@1454: String label = single.getLabel().trim(); ingo@1459: String[] cols = label.split(";"); ingo@1355: ingo@1355: VLayout v = new VLayout(); ingo@1355: ingo@1355: for (String col: cols) { ingo@1355: Label l = new Label(col + " " + MESSAGE.unitQSingle()); ingo@1355: l.setHeight(20); ingo@1355: ingo@1355: v.addMember(l); ingo@1355: } ingo@1355: ingo@1355: return v; ingo@236: } ingo@236: ingo@236: ingo@53: /** ingo@42: * This method creates the whole widget. There is a panel on the left, that ingo@42: * allows the user to enter values manually by keyboard. On the right, there ingo@42: * is a table that allows the user to enter values by mouse click. ingo@42: * ingo@42: * @param data The data that is displayed in the table on the right. ingo@42: * ingo@42: * @return the widget. ingo@42: */ ingo@51: protected Canvas createWidget(DataList data) { ingo@42: VLayout layout = new VLayout(); raimund@248: container = new HLayout(); ingo@42: Canvas modeForm = createModePanel(); ingo@42: raimund@248: container.setMembersMargin(30); ingo@519: ingo@48: // the initial panel is the Single-W panel. ingo@519: double[] values = getSingleQ(); ingo@519: qArrayPanel = new DoubleArrayPanel( ingo@519: MESSAGE.unitQSingle(), values, this); ingo@519: container.addMember(qArrayPanel); ingo@519: ingo@42: layout.addMember(modeForm); ingo@42: layout.addMember(container); ingo@42: ingo@42: return layout; ingo@42: } ingo@42: ingo@42: ingo@42: /** ingo@42: * This method creates the mode panel. It contains two radio button panels ingo@42: * that allows the user to switch the input mode between w/q and ingo@42: * single/range input. ingo@42: * ingo@42: * @return a panel. ingo@42: */ ingo@42: protected Canvas createModePanel() { ingo@42: RadioGroupItem wq = new RadioGroupItem(FIELD_WQ); ingo@42: wq.setShowTitle(false); sascha@1535: wq.setVertical(true); ingo@577: wq.setWidth(WIDTH_LEFT_UPPER); ingo@596: wq.setWrap(false); ingo@42: ingo@42: RadioGroupItem mode = new RadioGroupItem(FIELD_MODE); ingo@42: mode.setShowTitle(false); ingo@42: mode.setVertical(false); ingo@577: mode.setWidth(WIDTH_LEFT_LOWER); ingo@42: ingo@42: LinkedHashMap wqValues = new LinkedHashMap(); raimund@248: wqValues.put(FIELD_WQ_W, MESSAGE.wqW()); sascha@1535: wqValues.put(FIELD_WQ_W_FREE, MESSAGE.wqWFree()); ingo@2392: wqValues.put(FIELD_WQ_Q_FREE, MESSAGE.wqQ()); ingo@2392: wqValues.put(FIELD_WQ_Q, MESSAGE.wqQGauge()); ingo@42: ingo@42: LinkedHashMap modeValues = new LinkedHashMap(); raimund@248: modeValues.put(FIELD_MODE_SINGLE, MESSAGE.wqSingle()); raimund@248: modeValues.put(FIELD_MODE_RANGE, MESSAGE.wqRange()); ingo@42: ingo@42: wq.setValueMap(wqValues); ingo@42: mode.setValueMap(modeValues); ingo@42: ingo@42: wq.addChangeHandler(this); ingo@42: mode.addChangeHandler(this); ingo@42: ingo@42: modes = new DynamicForm(); ingo@42: modes.setFields(wq, mode); ingo@577: modes.setWidth(WIDTH_LEFT_UPPER); ingo@42: modes.setNumCols(1); ingo@42: ingo@42: LinkedHashMap initial = new LinkedHashMap(); ingo@2392: initial.put(FIELD_WQ, FIELD_WQ_Q); ingo@42: initial.put(FIELD_MODE, FIELD_MODE_SINGLE); ingo@42: modes.setValues(initial); ingo@42: ingo@42: return modes; ingo@42: } ingo@42: ingo@42: ingo@564: @Override ingo@564: public List validate() { ingo@564: if (isRangeMode()) { ingo@564: return validateRangeValues(); ingo@564: } ingo@564: else { ingo@564: return validateSingleValues(); ingo@564: } ingo@564: } ingo@564: ingo@564: ingo@564: protected List validateRangeValues() { raimund@2473: if (isWFree()) { raimund@2473: return validateRange(wFreeRangePanel, minWFree, maxWFree); ingo@564: } ingo@1485: else if (isQFree()) { ingo@1485: return validateRange(qFreeRangePanel, minQFree, maxQFree); ingo@1485: } raimund@2473: else if (isWMode()) { sascha@1535: return validateRange(wRangePanel, minW, maxW); sascha@1535: } ingo@564: else { ingo@564: return validateRange(qRangePanel, minQ, maxQ); ingo@564: } ingo@564: } ingo@564: ingo@564: protected List validateSingleValues() { sascha@2389: if (isWFree()) { raimund@2473: return validateSingle(wFreeArrayPanel, minWFree, maxWFree); sascha@2389: } sascha@2389: else if (isWMode()) { raimund@2473: return validateSingle(wArrayPanel, minW, maxW); raimund@2473: //return validateSingle(wArrayPanel, 0, 100000); ingo@564: } ingo@1485: else if (isQFree()) { ingo@1485: return validateSingle(qFreeArrayPanel, minQFree, maxQFree); ingo@1485: } ingo@564: else { ingo@564: return validateSingle(qArrayPanel, minQ, maxQ); ingo@564: } ingo@564: } ingo@564: ingo@564: ingo@564: protected List validateRange( ingo@564: DoubleRangePanel panel, ingo@564: double min, double max) ingo@564: { ingo@564: List errors = new ArrayList(); ingo@564: NumberFormat nf = NumberFormat.getDecimalFormat(); ingo@564: ingo@564: if (!panel.validateForm()) { ingo@564: errors.add(MESSAGE.wrongFormat()); ingo@564: } ingo@564: ingo@1490: double from; ingo@1490: double to; ingo@1490: double step; ingo@1490: ingo@1490: try { ingo@1490: from = panel.getFrom(); ingo@1490: to = panel.getTo(); ingo@1490: step = panel.getStep(); ingo@1490: } ingo@1490: catch (NullPointerException npe) { ingo@1490: errors.add(MESSAGE.missingInput()); ingo@1490: return errors; ingo@1490: } ingo@564: ingo@564: if (from < min || from > max) { ingo@564: String tmp = MESSAGE.error_validate_lower_range(); ingo@564: tmp = tmp.replace("$1", nf.format(from)); ingo@564: tmp = tmp.replace("$2", nf.format(min)); ingo@564: errors.add(tmp); ingo@564: from = min; ingo@564: } ingo@564: ingo@564: if (to < min || to > max) { ingo@564: String tmp = MESSAGE.error_validate_upper_range(); ingo@564: tmp = tmp.replace("$1", nf.format(to)); ingo@564: tmp = tmp.replace("$2", nf.format(max)); ingo@564: errors.add(tmp); ingo@564: to = max; ingo@564: } ingo@564: ingo@1276: if (!errors.isEmpty()) { ingo@1276: panel.setValues(from, to, step); ingo@1276: } ingo@1276: ingo@564: return errors; ingo@564: } ingo@564: ingo@564: ingo@564: protected List validateSingle( ingo@564: DoubleArrayPanel panel, ingo@564: double min, double max) ingo@564: { ingo@564: List errors = new ArrayList(); ingo@564: NumberFormat nf = NumberFormat.getDecimalFormat(); ingo@564: ingo@564: if (!panel.validateForm()) { ingo@564: errors.add(MESSAGE.wrongFormat()); ingo@564: } ingo@564: ingo@564: double[] values = panel.getInputValues(); ingo@1490: ingo@1490: if (values == null || values.length == 0) { ingo@1490: errors.add(MESSAGE.atLeastOneValue()); ingo@1490: return errors; ingo@1490: } ingo@1490: ingo@564: double[] good = new double[values.length]; ingo@564: int idx = 0; ingo@564: ingo@564: for (double value: values) { ingo@564: if (value < min || value > max) { ingo@564: String tmp = MESSAGE.error_validate_range(); ingo@564: tmp = tmp.replace("$1", nf.format(value)); ingo@564: tmp = tmp.replace("$2", nf.format(min)); ingo@564: tmp = tmp.replace("$3", nf.format(max)); ingo@564: errors.add(tmp); ingo@564: } ingo@564: else { ingo@564: good[idx++] = value; ingo@564: } ingo@564: } ingo@564: ingo@564: double[] justGood = new double[idx]; ingo@564: for (int i = 0; i < justGood.length; i++) { ingo@564: justGood[i] = good[i]; ingo@564: } ingo@564: ingo@564: if (!errors.isEmpty()) { ingo@564: panel.setValues(justGood); ingo@564: } ingo@564: ingo@564: return errors; ingo@564: } ingo@564: ingo@564: ingo@42: /** ingo@42: * This method returns the selected data. ingo@42: * ingo@42: * @return the selected/inserted data. ingo@42: */ christian@4568: @Override ingo@42: public Data[] getData() { ingo@59: // XXX If we have entered a value and click right afterwards on the ingo@59: // 'next' button, the BlurEvent is not fired, and the values are not ingo@59: // saved. So, we gonna save those values explicitly. ingo@59: if (!isRangeMode()) { ingo@59: Canvas member = container.getMember(0); ingo@59: if (member instanceof DoubleArrayPanel) { ingo@59: DoubleArrayPanel form = (DoubleArrayPanel) member; raimund@2473: if (isWFree()) { raimund@2473: saveSingleWFreeValues(form); raimund@2473: } raimund@2473: else if (isWMode()) { ingo@59: saveSingleWValues(form); ingo@59: } ingo@1485: else if (isQFree()) { ingo@1485: saveSingleQFreeValues(form); ingo@1485: } ingo@59: else { ingo@59: saveSingleQValues(form); ingo@59: } ingo@59: } ingo@236: ingo@1275: return getSingleData(); ingo@59: } ingo@59: else { ingo@59: Canvas member = container.getMember(0); ingo@59: if (member instanceof DoubleRangePanel) { ingo@59: DoubleRangePanel form = (DoubleRangePanel) member; ingo@59: raimund@2473: if (isWFree()) { raimund@2473: saveRangeWFreeValues(form); raimund@2473: } raimund@2473: else if (isWMode()) { ingo@59: saveRangeWValues(form); ingo@59: } ingo@1485: else if (isQFree()) { ingo@1485: saveRangeQFreeValues(form); ingo@1485: } ingo@59: else { ingo@59: saveRangeQValues(form); ingo@59: } ingo@59: } ingo@59: ingo@1275: return getRangeData(); ingo@1275: } ingo@1275: } ingo@1275: ingo@1275: ingo@1275: /** ingo@1275: * Collects the required data for single mode and resets the data for range ingo@1275: * mode. ingo@1275: */ ingo@1275: protected Data[] getSingleData() { ingo@1275: DataItem from = new DefaultDataItem("wq_from", "wq_from", ""); ingo@1275: DataItem to = new DefaultDataItem("wq_to", "wq_to", ""); ingo@1275: DataItem step = new DefaultDataItem("wq_step", "wq_step", ""); ingo@1275: ingo@1275: return new Data[] { ingo@1275: getDataMode(), ingo@2392: getFree(), ingo@1275: getDataSelectionMode(), ingo@1275: getDataSingle(), ingo@1275: new DefaultData( ingo@1275: "wq_from", ingo@1275: null, ingo@1275: null, ingo@1275: new DataItem[] {from}), ingo@1275: new DefaultData( ingo@1275: "wq_to", ingo@1275: null, ingo@1275: null, ingo@1275: new DataItem[] {to}), ingo@1275: new DefaultData( ingo@1275: "wq_step", ingo@1275: null, ingo@1275: null, ingo@1275: new DataItem[] {step}) }; ingo@1275: } ingo@1275: ingo@1275: ingo@1275: /** ingo@1275: * Collects the required data for range mode and resets the data for single ingo@1275: * mode. ingo@1275: */ ingo@1275: protected Data[] getRangeData() { ingo@1275: DataItem item = new DefaultDataItem("wq_single", "wq_single", ""); ingo@1275: ingo@1275: return new Data[] { ingo@236: getDataMode(), ingo@2392: getFree(), ingo@236: getDataSelectionMode(), ingo@236: getDataFrom(), ingo@236: getDataTo(), ingo@1275: getDataStep(), ingo@1275: new DefaultData( ingo@1275: "wq_single", ingo@1275: null, ingo@1275: null, ingo@1275: new DataItem[] {item}) }; ingo@47: } ingo@42: ingo@47: ingo@47: /** ingo@47: * Returns the Data object for the 'mode' attribute. ingo@47: * ingo@47: * @return the Data object for the 'mode' attribute. ingo@47: */ ingo@47: protected Data getDataMode() { ingo@47: String wqMode = modes.getValueAsString(FIELD_WQ); ingo@577: ingo@577: String value = null; ingo@2392: if (wqMode.equals(FIELD_WQ_Q_FREE) || wqMode.equals(FIELD_WQ_Q)) { ingo@2392: GWT.log("getData: FIELD_WQ_Q || FIELD_WQ_Q_FREE"); ingo@2392: value = "true"; sascha@2387: } ingo@577: else { raimund@2473: GWT.log("getData: FIELD_WQ_W || FIELD_WQ_W_FREE"); ingo@2392: value = "false"; ingo@577: } ingo@577: ingo@2392: DataItem item = new DefaultDataItem("wq_isq", "wq_isq", value); ingo@47: return new DefaultData( ingo@2392: "wq_isq", null, null, new DataItem[] { item }); ingo@47: } ingo@47: ingo@47: ingo@47: /** ingo@577: * Returns the Q mode. The Q mode can be "true" or "false". True means, the ingo@577: * calculation is not based on a gauge, false means the calculation should ingo@577: * be based on a gauge. ingo@577: * ingo@577: * @return the Data object for the 'wq_free' attribute. ingo@577: */ ingo@2392: protected Data getFree() { ingo@2392: String value = ""; ingo@2392: if(!isWMode()) { ingo@2392: value = isQFree() ? "true" : "false"; ingo@2392: } ingo@2392: else { ingo@2392: value = isWFree() ? "true" : "false"; ingo@2392: } ingo@2392: DataItem item = new DefaultDataItem("wq_isfree", "wq_isfree", value); ingo@577: return new DefaultData( ingo@2392: "wq_isfree", null, null, new DataItem[] { item }); ingo@577: } ingo@577: ingo@577: ingo@577: /** ingo@236: * Returns the Data object for the 'mode' attribute. ingo@236: * ingo@236: * @return the Data object for the 'mode' attribute. ingo@236: */ ingo@236: protected Data getDataSelectionMode() { ingo@236: String wqSelection = modes.getValueAsString(FIELD_MODE); ingo@2392: ingo@2392: String isRange = "true"; ingo@2392: if (wqSelection.equals(FIELD_MODE_SINGLE)) { ingo@2392: isRange = "false"; ingo@2392: } ingo@236: DataItem item = new DefaultDataItem( ingo@2392: "wq_isrange", "wq_isrange", isRange); ingo@236: ingo@236: return new DefaultData( ingo@2392: "wq_isrange", null, null, new DataItem[] { item }); ingo@236: } ingo@236: ingo@236: ingo@236: /** ingo@236: * Returns the data object for the 'single' attribute. ingo@236: * ingo@236: * @return the Data object for the 'single' attribute. ingo@236: */ ingo@236: protected Data getDataSingle() { ingo@236: double[] values = getFinalSingle(); ingo@236: StringBuilder sb = new StringBuilder(); ingo@236: for (double value: values) { ingo@236: sb.append(Double.toString(value)); ingo@236: sb.append(" "); ingo@236: } ingo@236: ingo@236: DataItem item = new DefaultDataItem( ingo@236: "wq_single", "wq_single", sb.toString()); ingo@236: ingo@236: return new DefaultData( ingo@236: "wq_single", null, null, new DataItem[] { item }); ingo@236: } ingo@236: ingo@236: ingo@236: /** ingo@47: * Returns the Data object for the 'from' attribute. ingo@47: * ingo@47: * @return the Data object for the 'from' attribute. ingo@47: */ ingo@47: protected Data getDataFrom() { ingo@47: String value = Double.valueOf(getFinalFrom()).toString(); ingo@47: DataItem item = new DefaultDataItem("wq_from", "wq_from", value); ingo@47: return new DefaultData( ingo@51: "wq_from", null, null, new DataItem[] { item }); ingo@47: } ingo@47: ingo@47: ingo@47: /** ingo@47: * Returns the Data object for the 'to' attribute. ingo@47: * ingo@47: * @return the Data object for the 'to' attribute. ingo@47: */ ingo@47: protected Data getDataTo() { ingo@47: String value = Double.valueOf(getFinalTo()).toString(); ingo@47: DataItem item = new DefaultDataItem("wq_to", "wq_to", value); ingo@47: return new DefaultData( ingo@51: "wq_to", null, null, new DataItem[] { item }); ingo@47: } ingo@47: ingo@47: ingo@47: /** ingo@47: * Returns the Data object for the 'step' attribute. ingo@47: * ingo@47: * @return the Data object for the 'step' attribute. ingo@47: */ ingo@47: protected Data getDataStep() { ingo@47: String value = Double.valueOf(getFinalStep()).toString(); ingo@47: DataItem item = new DefaultDataItem("wq_step","wq_step", value); ingo@47: return new DefaultData( ingo@51: "wq_step", null, null, new DataItem[] { item }); ingo@47: } ingo@47: ingo@47: ingo@236: protected double[] getFinalSingle() { raimund@2473: if (isWFree()) { raimund@2473: return getSingleWFree(); raimund@2473: } raimund@2473: else if (isWMode()) { ingo@1485: return getSingleW(); ingo@1485: } ingo@1485: else if (isQFree()) { ingo@1485: return getSingleQFree(); ingo@1485: } ingo@1485: else { ingo@1485: return getSingleQ(); ingo@1485: } ingo@236: } ingo@236: ingo@236: ingo@47: /** ingo@47: * Returns the value of 'from' depending on the selected input mode. ingo@47: * ingo@47: * @return the value of 'from' depending on the selected input mode. ingo@47: */ ingo@47: protected double getFinalFrom() { raimund@2473: if (isRangeMode()) { raimund@2473: if (isWFree()) { raimund@2473: return getFromWFree(); raimund@2473: } raimund@2473: else if (isWMode()) { ingo@1485: return getFromW(); ingo@1485: } ingo@1485: else if (isQFree()) { ingo@1485: return getFromQFree(); ingo@1485: } ingo@1485: else { ingo@1485: return getFromQ(); ingo@1485: } ingo@47: } ingo@47: else { ingo@1485: double[] values = null; ingo@47: raimund@2473: if (isWFree()) { raimund@2473: values = getSingleWFree(); raimund@2473: } raimund@2473: else if (isWMode()) { ingo@1485: values = getSingleW(); ingo@1485: } ingo@1485: else if (isQFree()) { ingo@1485: values = getSingleQFree(); ingo@1485: } ingo@1485: else { ingo@1485: values = getSingleQ(); ingo@1485: } ingo@1485: ingo@1485: double value = Double.MAX_VALUE; ingo@47: for (double v: values) { ingo@47: value = value < v ? value : v; ingo@47: } ingo@47: ingo@47: return value; ingo@47: } ingo@47: } ingo@47: ingo@47: ingo@47: /** ingo@47: * Returns the value of 'to' depending on the selected input mode. ingo@47: * ingo@47: * @return the value of 'to' depending on the selected input mode. ingo@47: */ ingo@47: protected double getFinalTo() { raimund@2473: if (isRangeMode()) { raimund@2473: if (isWFree()) { raimund@2473: return getToWFree(); raimund@2473: } raimund@2473: else if (isWMode()) { ingo@1485: return getToW(); ingo@1485: } ingo@1485: else if (isQFree()) { ingo@1485: return getToQFree(); ingo@1485: } ingo@1485: else { ingo@1485: return getToQ(); ingo@1485: } ingo@47: } ingo@47: else { ingo@1485: double[] values = null; ingo@47: raimund@2473: if (isWFree()) { raimund@2473: values = getSingleWFree(); raimund@2473: } raimund@2473: else if (isWMode()) { ingo@1485: values = getSingleW(); ingo@1485: } ingo@1485: else if (isQFree()) { ingo@1485: values = getSingleQFree(); ingo@1485: } ingo@1485: else { ingo@1485: values = getSingleQ(); ingo@1485: } ingo@1485: ingo@1485: double value = Double.MIN_VALUE; ingo@47: for (double v: values) { ingo@47: value = value > v ? value : v; ingo@47: } ingo@47: ingo@47: return value; ingo@47: } ingo@47: } ingo@47: ingo@47: ingo@47: /** ingo@47: * Returns the value of 'step' depending on the selected input mode. ingo@47: * ingo@47: * @return the value of 'step' depending on the selected input mode. ingo@47: */ ingo@47: protected double getFinalStep() { raimund@2473: if (isRangeMode()) { raimund@2473: if (isWFree()) { raimund@2473: return getStepWFree(); raimund@2473: } raimund@2473: else if (isWMode()) { ingo@1485: return getStepW(); ingo@1485: } ingo@1485: else if (isQFree()) { ingo@1485: return getStepQFree(); ingo@1485: } ingo@1485: else { ingo@1485: return getStepQ(); ingo@1485: } ingo@47: } ingo@47: else { ingo@234: // we have no field to enter the 'step' attribute in the ingo@234: // single mode ingo@234: return 0d; ingo@47: } ingo@47: } ingo@47: ingo@47: ingo@47: /** ingo@47: * Determines the range/single mode. ingo@47: * ingo@47: * @return true if the range mode is activated. ingo@47: */ ingo@47: public boolean isRangeMode() { ingo@47: String rMode = modes.getValueAsString(FIELD_MODE); ingo@47: sascha@582: return rMode.equals(FIELD_MODE_RANGE); ingo@47: } ingo@47: ingo@47: ingo@47: /** ingo@47: * Determines the w/q mode. ingo@47: * ingo@47: * @return true, if the W mode is activated. ingo@47: */ ingo@47: public boolean isWMode() { ingo@47: String wq = modes.getValueAsString(FIELD_WQ); ingo@2392: return wq.contains("W"); ingo@577: } ingo@47: ingo@577: ingo@577: public boolean isQFree() { ingo@577: String wqMode = modes.getValueAsString(FIELD_WQ); ingo@2392: return wqMode.equals(FIELD_WQ_Q_FREE); ingo@42: } ingo@42: sascha@1535: protected boolean isWFree() { sascha@1535: String wqMode = modes.getValueAsString(FIELD_WQ); sascha@1535: return wqMode.equals(FIELD_WQ_W_FREE); sascha@1535: } sascha@1535: ingo@42: ingo@42: /** ingo@42: * This method changes the lower panel with the input fields depending on ingo@42: * the combination of the two radio button panels. ingo@42: * ingo@42: * @param event The ChangeEvent. ingo@42: */ christian@4568: @Override ingo@42: public void onChange(ChangeEvent event) { ingo@42: DynamicForm form = event.getForm(); ingo@42: FormItem item = event.getItem(); ingo@42: ingo@2392: boolean isQ = false; ingo@2392: boolean isFree = false; ingo@2392: boolean isRange = false; ingo@42: ingo@42: if (item.getFieldName().equals(FIELD_MODE)) { ingo@2392: String wq = form.getValueAsString(FIELD_WQ); ingo@2392: isQ = wq.contains("Q"); ingo@2392: isFree = wq.contains("FREE"); ingo@2392: isRange = ((String) event.getValue()).equals(FIELD_MODE_RANGE); ingo@42: } ingo@42: else { ingo@2392: String wq = ((String) event.getValue()); ingo@2392: isQ = wq.contains("Q"); ingo@2392: isFree = wq.contains("FREE"); ingo@2392: isRange = ingo@2392: form.getValueAsString(FIELD_MODE).equals(FIELD_MODE_RANGE); ingo@42: } ingo@42: ingo@2392: if (isQ && isFree) { raimund@912: qdTable.hideIconFields(); raimund@912: } raimund@912: else { raimund@912: qdTable.showIconFields(); raimund@912: } raimund@912: raimund@3543: if (!isRange) { raimund@3543: qdTable.showSelect(); raimund@3543: } raimund@3543: else { raimund@3543: qdTable.showIconFields(); raimund@3543: } raimund@3543: ingo@2392: updatePanels(isQ, isFree, isRange); raimund@250: } ingo@42: ingo@42: ingo@2392: protected void updatePanels(boolean isQ, boolean isFree, boolean isRange) { raimund@250: container.removeMembers(container.getMembers()); ingo@580: raimund@2473: if (!isQ && isFree) { raimund@2473: if (!isRange) { raimund@2473: // Single W mode raimund@2473: double[] values = getSingleWFree(); raimund@2473: raimund@2473: wFreeArrayPanel = new DoubleArrayPanel( andre@8624: MESSAGE.unitWFree(), values, this); raimund@2473: raimund@2473: container.addMember(wFreeArrayPanel); raimund@2473: } raimund@2473: else { raimund@2473: // Range W mode raimund@2473: double from = getFromWFree(); raimund@2473: double to = getToWFree(); raimund@2473: double step = getStepWFree(); raimund@2473: raimund@2473: wFreeRangePanel = new DoubleRangePanel( raimund@2473: MESSAGE.unitWFrom(), MESSAGE.unitWTo(), MESSAGE.unitWStep(), raimund@2473: from, to, step, raimund@2473: 250, raimund@2473: this); raimund@2473: container.addMember(wFreeRangePanel); raimund@2473: } raimund@2473: raimund@2473: tabs.selectTab(0); raimund@2473: } raimund@2473: else if (!isQ) { ingo@2392: if (!isRange) { ingo@42: // Single W mode ingo@42: double[] values = getSingleW(); ingo@42: raimund@249: wArrayPanel = new DoubleArrayPanel( raimund@248: MESSAGE.unitWSingle(), values, this); raimund@248: raimund@249: container.addMember(wArrayPanel); ingo@42: } ingo@42: else { ingo@42: // Range W mode ingo@42: double from = getFromW(); ingo@42: double to = getToW(); ingo@42: double step = getStepW(); ingo@42: raimund@249: wRangePanel = new DoubleRangePanel( raimund@248: MESSAGE.unitWFrom(), MESSAGE.unitWTo(), MESSAGE.unitWStep(), ingo@42: from, to, step, ingo@42: 250, ingo@42: this); raimund@249: container.addMember(wRangePanel); ingo@42: } ingo@580: ingo@580: tabs.selectTab(0); ingo@42: } ingo@2392: else if (isQ && isFree) { ingo@2392: if (!isRange) { ingo@1485: // Single Q mode ingo@1485: double[] values = getSingleQFree(); ingo@1485: ingo@1485: qFreeArrayPanel = new DoubleArrayPanel( ingo@1485: MESSAGE.unitQSingle(), values, this); ingo@1485: container.addMember(qFreeArrayPanel); ingo@1485: } ingo@1485: else { ingo@1485: // Range Q mode ingo@1485: double from = getFromQFree(); ingo@1485: double to = getToQFree(); ingo@1485: double step = getStepQFree(); ingo@1485: ingo@1485: qFreeRangePanel = new DoubleRangePanel( ingo@1485: MESSAGE.unitQFrom(), MESSAGE.unitQTo(), MESSAGE.unitQStep(), ingo@1485: from, to, step, ingo@1485: 250, ingo@1485: this); ingo@1485: container.addMember(qFreeRangePanel); ingo@1485: } ingo@1485: ingo@1485: tabs.selectTab(1); ingo@1485: } ingo@42: else { ingo@2392: if (!isRange) { ingo@42: // Single Q mode ingo@42: double[] values = getSingleQ(); ingo@42: raimund@249: qArrayPanel = new DoubleArrayPanel( raimund@248: MESSAGE.unitQSingle(), values, this); raimund@249: container.addMember(qArrayPanel); ingo@42: } ingo@42: else { ingo@42: // Range Q mode ingo@42: double from = getFromQ(); ingo@42: double to = getToQ(); ingo@42: double step = getStepQ(); ingo@42: raimund@249: qRangePanel = new DoubleRangePanel( raimund@248: MESSAGE.unitQFrom(), MESSAGE.unitQTo(), MESSAGE.unitQStep(), ingo@42: from, to, step, ingo@42: 250, ingo@42: this); raimund@249: container.addMember(qRangePanel); ingo@42: } ingo@580: ingo@580: tabs.selectTab(1); ingo@42: } ingo@42: } ingo@42: ingo@42: /** ingo@42: * This method is called if the value of one of the input fields might have ingo@42: * changed. The entered values are validated and stored. ingo@42: * ingo@42: * @param event The BlurEvent. ingo@42: */ christian@4568: @Override ingo@42: public void onBlur(BlurEvent event) { ingo@42: DynamicForm form = event.getForm(); ingo@42: FormItem item = event.getItem(); ingo@42: ingo@42: String wqMode = (String) modes.getValue(FIELD_WQ); ingo@42: String inputMode = (String) modes.getValue(FIELD_MODE); ingo@42: ingo@42: if (wqMode.equals(FIELD_WQ_W)) { ingo@42: if (inputMode.equals(FIELD_MODE_SINGLE)) { ingo@42: DoubleArrayPanel p = (DoubleArrayPanel) form; ingo@59: saveSingleWValue(p, item); ingo@42: } ingo@42: else { ingo@42: DoubleRangePanel p = (DoubleRangePanel) form; ingo@59: saveRangeWValue(p, item); ingo@42: } ingo@42: } raimund@2473: else if (wqMode.equals(FIELD_WQ_W_FREE)) { raimund@2473: if (inputMode.equals(FIELD_MODE_SINGLE)) { raimund@2473: DoubleArrayPanel p = (DoubleArrayPanel) form; raimund@2473: saveSingleWFreeValue(p, item); raimund@2473: } raimund@2473: else { raimund@2473: DoubleRangePanel p = (DoubleRangePanel) form; raimund@2473: saveRangeWFreeValue(p, item); raimund@2473: } raimund@2473: } raimund@2473: else if (wqMode.equals(FIELD_WQ_Q_FREE)) { ingo@1485: if (inputMode.equals(FIELD_MODE_SINGLE)) { ingo@1485: DoubleArrayPanel p = (DoubleArrayPanel) form; ingo@1485: saveSingleQFreeValue(p, item); ingo@1485: } ingo@1485: else { ingo@1485: DoubleRangePanel p = (DoubleRangePanel) form; ingo@1485: saveRangeQFreeValue(p, item); ingo@1485: } ingo@1485: } ingo@42: else { ingo@42: if (inputMode.equals(FIELD_MODE_SINGLE)) { ingo@42: DoubleArrayPanel p = (DoubleArrayPanel) form; ingo@59: saveSingleQValue(p, item); ingo@42: } ingo@42: else { ingo@42: DoubleRangePanel p = (DoubleRangePanel) form; ingo@59: saveRangeQValue(p, item); ingo@59: } ingo@59: } ingo@59: } ingo@42: ingo@59: ingo@59: protected void saveSingleWValues(DoubleArrayPanel p) { ingo@59: FormItem[] formItems = p.getFields(); ingo@59: ingo@59: for (FormItem item: formItems) { ingo@59: if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { ingo@59: saveSingleWValue(p, item); ingo@42: } ingo@42: } ingo@42: } ingo@42: ingo@42: raimund@2473: protected void saveSingleWFreeValues(DoubleArrayPanel p) { raimund@2473: FormItem[] formItems = p.getFields(); raimund@2473: raimund@2473: for (FormItem item: formItems) { raimund@2473: if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { raimund@2473: saveSingleWFreeValue(p, item); raimund@2473: } raimund@2473: } raimund@2473: } raimund@2473: raimund@2473: ingo@59: protected void saveSingleQValues(DoubleArrayPanel p) { ingo@59: FormItem[] formItems = p.getFields(); ingo@59: ingo@59: for (FormItem item: formItems) { ingo@59: if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { ingo@59: saveSingleQValue(p, item); ingo@59: } ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@1485: protected void saveSingleQFreeValues(DoubleArrayPanel p) { ingo@1485: FormItem[] formItems = p.getFields(); ingo@1485: ingo@1485: for (FormItem item: formItems) { ingo@1485: if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { ingo@1485: saveSingleQFreeValue(p, item); ingo@1485: } ingo@1485: } ingo@1485: } ingo@1485: ingo@1485: ingo@59: protected void saveSingleWValue(DoubleArrayPanel p, FormItem item) { ingo@59: if (p.validateForm(item)) { ingo@59: setSingleW(p.getInputValues(item)); ingo@59: } ingo@59: } ingo@59: ingo@59: raimund@2473: protected void saveSingleWFreeValue(DoubleArrayPanel p, FormItem item) { raimund@2473: if (p.validateForm(item)) { raimund@2473: setSingleWFree(p.getInputValues(item)); raimund@2473: } raimund@2473: } raimund@2473: raimund@2473: ingo@59: protected void saveSingleQValue(DoubleArrayPanel p, FormItem item) { ingo@59: if (p.validateForm(item)) { ingo@59: setSingleQ(p.getInputValues(item)); ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@1485: protected void saveSingleQFreeValue(DoubleArrayPanel p, FormItem item) { ingo@1485: if (p.validateForm(item)) { ingo@1485: setSingleQFree(p.getInputValues(item)); ingo@1485: } ingo@1485: } ingo@1485: ingo@1485: ingo@59: protected void saveRangeWValues(DoubleRangePanel p) { ingo@59: FormItem[] formItems = p.getFields(); ingo@59: ingo@59: for (FormItem item: formItems) { ingo@59: saveRangeWValue(p, item); ingo@59: } ingo@59: } ingo@59: ingo@59: raimund@2473: protected void saveRangeWFreeValues(DoubleRangePanel p) { raimund@2473: FormItem[] formItems = p.getFields(); raimund@2473: raimund@2473: for (FormItem item: formItems) { raimund@2473: saveRangeWFreeValue(p, item); raimund@2473: } raimund@2473: } raimund@2473: raimund@2473: ingo@59: protected void saveRangeQValues(DoubleRangePanel p) { ingo@59: FormItem[] formItems = p.getFields(); ingo@59: ingo@59: for (FormItem item: formItems) { ingo@59: saveRangeQValue(p, item); ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@1485: protected void saveRangeQFreeValues(DoubleRangePanel p) { ingo@1485: FormItem[] formItems = p.getFields(); ingo@1485: ingo@1485: for (FormItem item: formItems) { ingo@1485: saveRangeQFreeValue(p, item); ingo@1485: } ingo@1485: } ingo@1485: ingo@1485: ingo@59: protected void saveRangeWValue(DoubleRangePanel p, FormItem item) { ingo@1490: if (p.validateForm()) { ingo@59: setFromW(p.getFrom()); ingo@59: setToW(p.getTo()); ingo@59: setStepW(p.getStep()); ingo@59: } ingo@59: } ingo@59: ingo@59: raimund@2473: protected void saveRangeWFreeValue(DoubleRangePanel p, FormItem item) { raimund@2473: if (p.validateForm()) { raimund@2474: setFromWFree(p.getFrom()); raimund@2474: setToWFree(p.getTo()); raimund@2474: setStepWFree(p.getStep()); raimund@2473: } raimund@2473: } raimund@2473: raimund@2473: ingo@59: protected void saveRangeQValue(DoubleRangePanel p, FormItem item) { ingo@1490: if (p.validateForm()) { ingo@59: setFromQ(p.getFrom()); ingo@59: setToQ(p.getTo()); ingo@59: setStepQ(p.getStep()); ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@1485: protected void saveRangeQFreeValue(DoubleRangePanel p, FormItem item) { ingo@1490: if (p.validateForm()) { ingo@1485: setFromQFree(p.getFrom()); ingo@1485: setToQFree(p.getTo()); ingo@1485: setStepQFree(p.getStep()); ingo@1485: } ingo@1485: } ingo@1485: ingo@1485: ingo@42: protected double[] getSingleQ() { ingo@42: return valuesQ; ingo@42: } ingo@42: ingo@42: ingo@1485: protected double[] getSingleQFree() { ingo@1485: return valuesQFree; ingo@1485: } ingo@1485: ingo@1485: ingo@42: protected void setSingleQ(double[] values) { ingo@42: valuesQ = values; ingo@42: } ingo@42: ingo@42: ingo@1485: protected void setSingleQFree(double[] values) { ingo@1485: valuesQFree = values; ingo@1485: } ingo@1485: ingo@1485: ingo@42: protected double getFromQ() { ingo@42: return fromQ; ingo@42: } ingo@42: ingo@42: ingo@1485: protected double getFromQFree() { ingo@1485: return fromQFree; ingo@1485: } ingo@1485: ingo@1485: ingo@42: protected void setFromQ(double fromQ) { ingo@42: this.fromQ = fromQ; ingo@42: } ingo@42: ingo@42: ingo@1485: protected void setFromQFree(double fromQ) { ingo@1485: this.fromQFree = fromQ; ingo@1485: } ingo@1485: ingo@1485: ingo@42: protected double getToQ() { ingo@42: return toQ; ingo@42: } ingo@42: ingo@42: ingo@1485: protected double getToQFree() { ingo@1485: return toQFree; ingo@1485: } ingo@1485: ingo@1485: ingo@42: protected void setToQ(double toQ) { ingo@42: this.toQ = toQ; ingo@42: } ingo@42: ingo@42: ingo@1485: protected void setToQFree(double toQ) { ingo@1485: this.toQFree = toQ; ingo@1485: } ingo@1485: ingo@1485: ingo@42: protected double getStepQ() { ingo@42: return stepQ; ingo@42: } ingo@42: ingo@42: ingo@1485: protected double getStepQFree() { ingo@1485: return stepQFree; ingo@1485: } ingo@1485: ingo@1485: ingo@42: protected void setStepQ(double stepQ) { ingo@42: this.stepQ = stepQ; ingo@42: } ingo@42: ingo@42: ingo@1485: protected void setStepQFree(double stepQ) { ingo@1485: this.stepQFree = stepQ; ingo@1485: } ingo@1485: ingo@42: protected double[] getSingleW() { ingo@42: return valuesW; ingo@42: } ingo@42: raimund@2473: protected double[] getSingleWFree() { raimund@2473: return valuesWFree; raimund@2473: } ingo@42: ingo@42: protected void setSingleW(double[] values) { ingo@42: valuesW = values; ingo@42: } ingo@42: raimund@2473: protected void setSingleWFree(double[] values) { raimund@2473: valuesWFree = values; raimund@2473: } ingo@42: ingo@42: protected double getFromW() { ingo@42: return fromW; ingo@42: } ingo@42: raimund@2473: protected double getFromWFree() { raimund@2473: return fromWFree; raimund@2473: } ingo@42: ingo@42: protected void setFromW(double fromW) { ingo@42: this.fromW = fromW; ingo@42: } ingo@42: raimund@2473: protected void setFromWFree(double fromW) { raimund@2473: this.fromW = fromW; raimund@2473: } ingo@42: ingo@42: protected double getToW() { ingo@42: return toW; ingo@42: } ingo@42: raimund@2473: protected double getToWFree() { raimund@2473: return toWFree; raimund@2473: } ingo@42: ingo@42: protected void setToW(double toW) { ingo@42: this.toW = toW; ingo@42: } ingo@42: raimund@2473: protected void setToWFree(double toW) { raimund@2473: this.toWFree = toW; raimund@2473: } ingo@42: ingo@42: protected double getStepW() { ingo@42: return stepW; ingo@42: } ingo@42: raimund@2473: protected double getStepWFree() { raimund@2473: return stepWFree; raimund@2473: } ingo@42: ingo@42: protected void setStepW(double stepW) { ingo@42: this.stepW = stepW; ingo@42: } raimund@248: raimund@2473: protected void setStepWFree(double stepW) { raimund@2473: this.stepWFree = stepW; raimund@2473: } raimund@248: ingo@579: /** ingo@579: * Determines the min and max kilometer value selected in a former state. A ingo@579: * bit silly, but we need to run over each value of the "old data" to find ingo@579: * such values because it is not available here. ingo@579: * ingo@579: * @param data The DataList which contains the whole data inserted for the ingo@579: * current artifact. ingo@579: * ingo@579: * @return a double array with [min, max]. ingo@579: */ ingo@579: protected double[] getMinMaxKM(DataList[] data) { ingo@1279: ArtifactDescription adesc = artifact.getArtifactDescription(); ingo@1279: return adesc.getKMRange(); ingo@579: } ingo@579: ingo@579: ingo@579: /** ingo@579: * Returns the name of the selected river. ingo@579: * ingo@579: * @param data The DataList with all data. ingo@579: * ingo@579: * @return the name of the current river. ingo@579: */ felix@4982: protected String getRiverName() { ingo@1279: ArtifactDescription adesc = artifact.getArtifactDescription(); ingo@1279: return adesc.getRiver(); ingo@579: } ingo@579: ingo@579: ingo@580: protected void fetchWQData() { felix@4983: Config config = Config.getInstance(); felix@4983: String locale = config.getLocale (); ingo@579: ingo@579: ArtifactDescription adescr = artifact.getArtifactDescription(); ingo@579: DataList[] data = adescr.getOldData(); ingo@579: ingo@579: double[] mm = getMinMaxKM(data); felix@4982: String river = getRiverName(); ingo@579: raimund@1425: wqInfoService.getWQInfo(locale, river, mm[0], mm[1], raimund@248: new AsyncCallback() { christian@4568: @Override raimund@248: public void onFailure(Throwable caught) { felix@6557: GWT.log("Could not receive wq informations."); ingo@579: SC.warn(caught.getMessage()); raimund@248: } raimund@248: christian@4568: @Override raimund@248: public void onSuccess(WQInfoObject[] wqi) { raimund@248: int num = wqi != null ? wqi.length :0; felix@6557: GWT.log("Received " + num + " wq informations."); raimund@248: raimund@248: if (num == 0) { raimund@248: return; raimund@248: } ingo@580: raimund@248: addWQInfo(wqi); ingo@519: ingo@519: String wq = (String) modes.getValue(FIELD_WQ); ingo@519: String sr = (String) modes.getValue(FIELD_MODE); ingo@2392: GWT.log("sending: " + wq + ", " + sr); ingo@2392: boolean isQ = wq.contains("Q"); ingo@2392: boolean isFree = wq.contains("FREE"); ingo@2392: boolean isRange = sr.equals(FIELD_MODE_RANGE); ingo@2392: ingo@2392: updatePanels(isQ, isFree, isRange); raimund@248: } raimund@248: } raimund@248: ); raimund@248: } raimund@248: raimund@248: raimund@248: protected void addWQInfo (WQInfoObject[] wqi) { raimund@248: for(WQInfoObject wi: wqi) { ingo@580: WQInfoRecord rec = new WQInfoRecord(wi); ingo@580: ingo@580: if (wi.getType().equals("W")) { ingo@580: wTable.addData(rec); ingo@580: } ingo@580: else { ingo@580: qdTable.addData(rec); ingo@580: } raimund@248: } raimund@248: } ingo@42: } ingo@42: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :