ingo@42: package de.intevation.flys.client.client.ui; ingo@42: ingo@564: import java.util.ArrayList; ingo@42: import java.util.LinkedHashMap; ingo@53: import java.util.List; 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@42: 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.BlurHandler; ingo@42: import com.smartgwt.client.widgets.form.fields.events.BlurEvent; ingo@42: import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; ingo@42: import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; ingo@53: import com.smartgwt.client.widgets.layout.HLayout; ingo@42: import com.smartgwt.client.widgets.layout.VLayout; raimund@248: import com.smartgwt.client.widgets.grid.events.CellClickHandler; raimund@248: import com.smartgwt.client.widgets.grid.events.CellClickEvent; ingo@580: import com.smartgwt.client.widgets.tab.TabSet; ingo@580: import com.smartgwt.client.widgets.tab.Tab; ingo@42: ingo@42: import de.intevation.flys.client.shared.model.Data; ingo@47: import de.intevation.flys.client.shared.model.DataItem; ingo@51: import de.intevation.flys.client.shared.model.DataList; ingo@47: import de.intevation.flys.client.shared.model.DefaultData; ingo@47: import de.intevation.flys.client.shared.model.DefaultDataItem; raimund@248: import de.intevation.flys.client.shared.model.WQInfoObject; raimund@248: import de.intevation.flys.client.shared.model.WQInfoRecord; raimund@248: import de.intevation.flys.client.shared.model.ArtifactDescription; raimund@248: ingo@211: import de.intevation.flys.client.client.FLYSConstants; raimund@248: import de.intevation.flys.client.client.FLYSImages; raimund@248: import de.intevation.flys.client.client.Config; ingo@580: import de.intevation.flys.client.client.services.WQInfoService; ingo@580: import de.intevation.flys.client.client.services.WQInfoServiceAsync; ingo@580: import de.intevation.flys.client.client.ui.wq.WTable; ingo@580: import de.intevation.flys.client.client.ui.wq.QDTable; 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: { ingo@42: /** The message class that provides i18n strings.*/ raimund@248: protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); ingo@42: raimund@248: /** The interface that provides the image resources. */ raimund@248: private FLYSImages IMAGES = GWT.create(FLYSImages.class); raimund@248: 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.*/ 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@577: public static final String FIELD_WQ_Q_GAUGE = "Q_GAUGE"; 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: 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@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@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: ingo@42: /** The 'from' value entered in the range Q mode.*/ ingo@42: protected double fromQ; ingo@42: ingo@42: /** The 'to' value entered in the range Q mode.*/ ingo@42: protected double toQ; ingo@42: ingo@42: /** The 'step' value entered in the range Q mode.*/ ingo@42: protected double stepQ; ingo@42: ingo@42: /** The values entered in the single Q mode.*/ ingo@42: protected double[] valuesQ; ingo@42: 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: 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@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() { raimund@912: public void onCellClick(CellClickEvent e) { raimund@912: if (isWMode()) { 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: */ 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: ingo@580: protected void initHelperPanel() { ingo@580: tabs = new TabSet(); ingo@580: tabs.setWidth100(); ingo@580: tabs.setHeight100(); ingo@580: ingo@580: // TODO i18n ingo@580: Tab wTab = new Tab("W"); ingo@580: Tab qTab = new Tab("Q / D"); ingo@580: 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: ingo@53: public Canvas createOld(DataList dataList) { ingo@53: List items = dataList.getAll(); ingo@53: ingo@236: Data dMode = getData(items, "wq_mode"); ingo@595: Data dFree = getData(items, "wq_free"); ingo@236: Data dSelection = getData(items, "wq_selection"); 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@236: boolean wMode = strMode.equals(FIELD_WQ_W); 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@236: String text = null; ingo@236: ingo@236: DataItem[] selItem = dSelection.getItems(); ingo@236: String sel = selItem != null ingo@236: ? selItem[0].getStringValue() ingo@236: : ""; ingo@236: ingo@236: if (sel.equals("single")) { ingo@236: DataItem[] single = dSingle.getItems(); ingo@236: ingo@236: text = wMode ingo@236: ? createWString(single[0]) 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@236: text = wMode 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@595: if (wMode) { ingo@595: wqMode = 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: Label vLabel = new Label(text); ingo@595: mLabel.setWidth(175); ingo@595: mLabel.setHeight(20); ingo@595: vLabel.setWidth(175); ingo@595: vLabel.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@56: DataItem fQItem = getDataItem(f.getItems(), "minQ"); ingo@56: DataItem fWItem = getDataItem(f.getItems(), "minW"); ingo@56: DataItem tQItem = getDataItem(t.getItems(), "maxQ"); ingo@56: DataItem tWItem = getDataItem(t.getItems(), "maxW"); ingo@56: DataItem sQItem = getDataItem(s.getItems(), "stepQ"); ingo@56: DataItem sWItem = getDataItem(s.getItems(), "stepW"); 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@56: this.fromW = minW; ingo@56: this.toW = maxW; ingo@56: this.stepW = stepW; ingo@56: ingo@56: this.fromQ = minQ; ingo@56: this.toQ = maxQ; ingo@56: this.stepQ = stepQ; 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@519: Data m = getData(allData, "wq_mode"); ingo@519: DataItem modeItem = m != null ? m.getDefault() : null; ingo@519: String theMode = modeItem != null ingo@519: ? modeItem.getStringValue() ingo@595: : ""; ingo@595: ingo@595: Data f = getData(allData, "wq_free"); ingo@595: DataItem freeItem = f != null ? f.getDefault() : null; ingo@595: String theFree = freeItem != null ingo@595: ? freeItem.getStringValue() ingo@519: : null; ingo@519: ingo@519: Data s = getData(allData, "wq_selection"); ingo@519: DataItem sI = s != null ? s.getDefault() : null; ingo@519: String theSelection = sI != null ? sI.getStringValue() : null; ingo@519: ingo@519: if (theMode == null || theMode.length() == 0) { ingo@519: return; ingo@519: } ingo@519: ingo@595: boolean isW = theMode.equals(FIELD_WQ_W); ingo@595: boolean isFree = Boolean.valueOf(theFree); ingo@595: ingo@519: initUserSingleValues(list, theMode); ingo@519: initUserRangeValues(list, theMode); ingo@519: ingo@595: if (isW) { ingo@595: modes.setValue(FIELD_WQ, theMode); ingo@595: } ingo@595: else { ingo@595: modes.setValue(FIELD_WQ, isFree ? FIELD_WQ_Q : FIELD_WQ_Q_GAUGE); ingo@595: } ingo@519: ingo@519: if (theSelection != null || theSelection.length() > 0) { ingo@519: modes.setValue(FIELD_MODE, theSelection); ingo@519: updatePanels(theMode, theSelection); ingo@519: } 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. ingo@519: * @param theMode The W or Q mode. ingo@519: */ ingo@519: protected void initUserSingleValues(DataList list, String theMode) { ingo@519: List allData = list.getAll(); ingo@519: ingo@519: Data s = getData(allData, "wq_single"); ingo@519: DataItem i = s != null ? s.getDefault() : null; 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@519: if (theMode.equals("W")) { 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. ingo@519: * @param theMode The W or Q mode. ingo@519: */ ingo@519: protected void initUserRangeValues(DataList list, String theMode) { 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@519: if (theMode.equals("W")) { 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@53: protected String createWString(DataItem from, DataItem to, DataItem step) { 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@53: return sb.toString(); ingo@53: } ingo@53: ingo@53: ingo@236: protected String createWString(DataItem single) { ingo@559: return single.getLabel().replace(" ", " " + MESSAGE.unitWSingle() + " "); ingo@236: } ingo@236: ingo@236: ingo@53: protected String createQString(DataItem from, DataItem to, DataItem step) { 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@53: return sb.toString(); ingo@53: } ingo@53: ingo@53: ingo@236: protected String createQString(DataItem single) { ingo@559: return single.getLabel().replace(" ", " " + MESSAGE.unitQSingle() + " "); 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); ingo@42: wq.setVertical(false); 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()); raimund@248: wqValues.put(FIELD_WQ_Q, MESSAGE.wqQ()); ingo@577: wqValues.put(FIELD_WQ_Q_GAUGE, 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@577: initial.put(FIELD_WQ, FIELD_WQ_Q_GAUGE); 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() { ingo@564: if (isWMode()) { ingo@564: return validateRange(wRangePanel, minW, maxW); ingo@564: } ingo@564: else { ingo@564: return validateRange(qRangePanel, minQ, maxQ); ingo@564: } ingo@564: } ingo@564: ingo@564: ingo@564: protected List validateSingleValues() { ingo@564: if (isWMode()) { ingo@564: return validateSingle(wArrayPanel, minW, maxW); ingo@564: } 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@564: double from = panel.getFrom(); ingo@564: double to = panel.getTo(); ingo@1276: double step = panel.getStep(); 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@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: */ 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; ingo@59: if (isWMode()) { ingo@59: saveSingleWValues(form); ingo@59: } 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: ingo@59: if (isWMode()) { ingo@59: saveRangeWValues(form); ingo@59: } 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@1275: getQMode(), 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@577: getQMode(), 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@577: if (wqMode.equals(FIELD_WQ_Q) || wqMode.equals(FIELD_WQ_Q_GAUGE)) { ingo@577: value = FIELD_WQ_Q; ingo@577: } ingo@577: else { ingo@577: value = FIELD_WQ_W; ingo@577: } ingo@577: ingo@577: DataItem item = new DefaultDataItem("wq_mode", "wq_mode", value); ingo@47: return new DefaultData( ingo@51: "wq_mode", 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@577: protected Data getQMode() { ingo@577: String value = isQFree() ? "true" : "false"; ingo@577: ingo@577: DataItem item = new DefaultDataItem("wq_free", "wq_free", value); ingo@577: return new DefaultData( ingo@577: "wq_free", 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@236: DataItem item = new DefaultDataItem( ingo@236: "wq_selection", "wq_selection", wqSelection); ingo@236: ingo@236: return new DefaultData( ingo@236: "wq_selection", 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() { ingo@236: boolean wMode = isWMode(); ingo@236: ingo@236: return wMode ? getSingleW() : getSingleQ(); 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() { ingo@47: boolean wMode = isWMode(); ingo@47: boolean rangeMode = isRangeMode(); ingo@47: ingo@47: if (rangeMode) { ingo@47: return wMode ? getFromW() : getFromQ(); ingo@47: ingo@47: } ingo@47: else { ingo@47: double[] values = wMode ? getSingleW() : getSingleQ(); ingo@47: double value = Double.MAX_VALUE; ingo@47: 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() { ingo@47: boolean wMode = isWMode(); ingo@47: boolean rangeMode = isRangeMode(); ingo@47: ingo@47: if (rangeMode) { ingo@47: return wMode ? getToW() : getToQ(); ingo@47: ingo@47: } ingo@47: else { ingo@47: double[] values = wMode ? getSingleW() : getSingleQ(); ingo@47: double value = Double.MIN_VALUE; ingo@47: 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() { ingo@47: boolean wMode = isWMode(); ingo@47: boolean rangeMode = isRangeMode(); ingo@47: ingo@47: if (rangeMode) { ingo@234: return wMode ? getStepW() : getStepQ(); 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); sascha@582: return wq.equals(FIELD_WQ_W); ingo@577: } ingo@47: ingo@577: ingo@577: public boolean isQFree() { ingo@577: String wqMode = modes.getValueAsString(FIELD_WQ); ingo@577: return wqMode.equals(FIELD_WQ_Q); ingo@42: } ingo@42: 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: */ ingo@42: public void onChange(ChangeEvent event) { ingo@42: DynamicForm form = event.getForm(); ingo@42: FormItem item = event.getItem(); ingo@42: ingo@42: String wqMode = null; ingo@42: String inputMode = null; ingo@42: ingo@42: if (item.getFieldName().equals(FIELD_MODE)) { ingo@42: wqMode = form.getValueAsString(FIELD_WQ); ingo@42: inputMode = (String) event.getValue(); ingo@42: } ingo@42: else { ingo@42: wqMode = (String) event.getValue(); ingo@42: inputMode = form.getValueAsString(FIELD_MODE); ingo@42: } ingo@42: raimund@912: if (wqMode.equals("Q")) { raimund@912: qdTable.hideIconFields(); raimund@912: } raimund@912: else { raimund@912: qdTable.showIconFields(); raimund@912: } raimund@912: raimund@250: updatePanels(wqMode, inputMode); raimund@250: } ingo@42: ingo@42: raimund@250: protected void updatePanels(String wqMode, String inputMode) { raimund@250: container.removeMembers(container.getMembers()); ingo@580: ingo@42: if (wqMode.equals(FIELD_WQ_W)) { ingo@42: if (inputMode.equals(FIELD_MODE_SINGLE)) { 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@42: else { ingo@42: if (inputMode.equals(FIELD_MODE_SINGLE)) { 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: */ 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: } 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: 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@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: 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@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: 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@59: protected void saveRangeWValue(DoubleRangePanel p, FormItem item) { ingo@59: if (p.validateForm(item)) { ingo@59: setFromW(p.getFrom()); ingo@59: setToW(p.getTo()); ingo@59: setStepW(p.getStep()); ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@59: protected void saveRangeQValue(DoubleRangePanel p, FormItem item) { ingo@59: if (p.validateForm(item)) { ingo@59: setFromQ(p.getFrom()); ingo@59: setToQ(p.getTo()); ingo@59: setStepQ(p.getStep()); ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@42: protected double[] getSingleQ() { ingo@42: return valuesQ; ingo@42: } ingo@42: ingo@42: ingo@42: protected void setSingleQ(double[] values) { ingo@42: valuesQ = values; ingo@42: } ingo@42: ingo@42: ingo@42: protected double getFromQ() { ingo@42: return fromQ; ingo@42: } ingo@42: ingo@42: ingo@42: protected void setFromQ(double fromQ) { ingo@42: this.fromQ = fromQ; ingo@42: } ingo@42: ingo@42: ingo@42: protected double getToQ() { ingo@42: return toQ; ingo@42: } ingo@42: ingo@42: ingo@42: protected void setToQ(double toQ) { ingo@42: this.toQ = toQ; ingo@42: } ingo@42: ingo@42: ingo@42: protected double getStepQ() { ingo@42: return stepQ; ingo@42: } ingo@42: ingo@42: ingo@42: protected void setStepQ(double stepQ) { ingo@42: this.stepQ = stepQ; ingo@42: } ingo@42: ingo@42: ingo@42: protected double[] getSingleW() { ingo@42: return valuesW; ingo@42: } ingo@42: ingo@42: ingo@42: protected void setSingleW(double[] values) { ingo@42: valuesW = values; ingo@42: } ingo@42: ingo@42: ingo@42: protected double getFromW() { ingo@42: return fromW; ingo@42: } ingo@42: ingo@42: ingo@42: protected void setFromW(double fromW) { ingo@42: this.fromW = fromW; ingo@42: } ingo@42: ingo@42: ingo@42: protected double getToW() { ingo@42: return toW; ingo@42: } ingo@42: ingo@42: ingo@42: protected void setToW(double toW) { ingo@42: this.toW = toW; ingo@42: } ingo@42: ingo@42: ingo@42: protected double getStepW() { ingo@42: return stepW; ingo@42: } ingo@42: ingo@42: ingo@42: protected void setStepW(double stepW) { ingo@42: this.stepW = stepW; ingo@42: } raimund@248: 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: */ ingo@579: protected String getRiverName(DataList[] data) { ingo@1279: ArtifactDescription adesc = artifact.getArtifactDescription(); ingo@1279: return adesc.getRiver(); ingo@579: } ingo@579: ingo@579: ingo@580: protected void fetchWQData() { ingo@579: Config config = Config.getInstance(); ingo@579: String url = config.getServerUrl(); ingo@579: 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); ingo@579: String river = getRiverName(data); ingo@579: ingo@579: wqInfoService.getWQInfo(url, locale, river, mm[0], mm[1], raimund@248: new AsyncCallback() { raimund@248: public void onFailure(Throwable caught) { raimund@248: GWT.log("Could not recieve wq informations."); ingo@579: SC.warn(caught.getMessage()); raimund@248: } raimund@248: raimund@248: public void onSuccess(WQInfoObject[] wqi) { raimund@248: int num = wqi != null ? wqi.length :0; raimund@248: GWT.log("Recieved " + 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@519: updatePanels(wq, sr); 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 :