comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java @ 579:f1b977657880

#140 Code cleanup in WQ table. flys-client/trunk@2152 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 17 Jun 2011 13:46:28 +0000
parents bcf1a37223a5
children 42512fce9b1b
comparison
equal deleted inserted replaced
578:bcf1a37223a5 579:f1b977657880
8 import com.google.gwt.i18n.client.NumberFormat; 8 import com.google.gwt.i18n.client.NumberFormat;
9 import com.google.gwt.user.client.rpc.AsyncCallback; 9 import com.google.gwt.user.client.rpc.AsyncCallback;
10 10
11 import com.smartgwt.client.data.Record; 11 import com.smartgwt.client.data.Record;
12 12
13 import com.smartgwt.client.util.SC;
13 import com.smartgwt.client.widgets.Canvas; 14 import com.smartgwt.client.widgets.Canvas;
14 import com.smartgwt.client.widgets.Label; 15 import com.smartgwt.client.widgets.Label;
15 import com.smartgwt.client.widgets.form.DynamicForm; 16 import com.smartgwt.client.widgets.form.DynamicForm;
16 import com.smartgwt.client.widgets.form.fields.FormItem; 17 import com.smartgwt.client.widgets.form.fields.FormItem;
17 import com.smartgwt.client.widgets.form.fields.RadioGroupItem; 18 import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
1362 protected void setStepW(double stepW) { 1363 protected void setStepW(double stepW) {
1363 this.stepW = stepW; 1364 this.stepW = stepW;
1364 } 1365 }
1365 1366
1366 1367
1368 /**
1369 * Determines the min and max kilometer value selected in a former state. A
1370 * bit silly, but we need to run over each value of the "old data" to find
1371 * such values because it is not available here.
1372 *
1373 * @param data The DataList which contains the whole data inserted for the
1374 * current artifact.
1375 *
1376 * @return a double array with [min, max].
1377 */
1378 protected double[] getMinMaxKM(DataList[] data) {
1379 int num = data != null ? data.length : 0;
1380 double[] mm = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
1381
1382 for (int i = 0; i < num; i++) {
1383 DataList dl = data[i];
1384
1385 if (dl.getState().equals("state.winfo.location_distance")) {
1386 for (int j = 0, n = dl.size(); j < n; j++) {
1387 Data d = dl.get(j);
1388
1389 String label = d.getLabel();
1390 if (label.equals("ld_step") || label.equals("ld_mode")) {
1391 continue;
1392 }
1393
1394 for (DataItem item: d.getItems()) {
1395 String itemValue = item.getStringValue();
1396
1397 try {
1398 double v = Double.valueOf(itemValue);
1399
1400 mm[0] = mm[0] < v ? mm[0] : v;
1401 mm[1] = mm[1] > v ? mm[1] : v;
1402 }
1403 catch (NumberFormatException nfe) {
1404 // do nothing
1405 }
1406 }
1407 }
1408 }
1409 }
1410
1411 return mm;
1412 }
1413
1414
1415 /**
1416 * Returns the name of the selected river.
1417 *
1418 * @param data The DataList with all data.
1419 *
1420 * @return the name of the current river.
1421 */
1422 protected String getRiverName(DataList[] data) {
1423 if (data != null && data.length > 0) {
1424 for (int i = 0; i < data.length; i++) {
1425 DataList dl = data[i];
1426
1427 if (dl.getState().equals("state.winfo.river")) {
1428 for (int j = 0; j < dl.size(); j++) {
1429 Data d = dl.get(j);
1430 DataItem[] di = d.getItems();
1431
1432 if (di != null && di.length == 1) {
1433 return d.getItems()[0].getStringValue();
1434 }
1435 }
1436 }
1437 }
1438 }
1439
1440 return null;
1441 }
1442
1443
1367 protected void createWQInputTable() { 1444 protected void createWQInputTable() {
1368 Config config = Config.getInstance(); 1445 Config config = Config.getInstance();
1369 String url = config.getServerUrl(); 1446 String url = config.getServerUrl();
1370 String locale = config.getLocale (); 1447 String locale = config.getLocale ();
1371 String river = "";
1372 String value_min = "";
1373 String value_max = "";
1374 1448
1375 ArtifactDescription adescr = artifact.getArtifactDescription(); 1449 ArtifactDescription adescr = artifact.getArtifactDescription();
1376 DataList[] data = adescr.getOldData(); 1450 DataList[] data = adescr.getOldData();
1377 1451
1378 //TODO: get the information about old data. 1452 double[] mm = getMinMaxKM(data);
1379 if (data != null && data.length > 0) { 1453 String river = getRiverName(data);
1380 for (int i = 0; i < data.length; i++) { 1454
1381 DataList dl = data[i]; 1455 wqInfoService.getWQInfo(url, locale, river, mm[0], mm[1],
1382 if (dl.getState().equals("state.winfo.river")) {
1383 for (int j = 0; j < dl.size(); j++) {
1384 Data d = dl.get(j);
1385 DataItem[] di = d.getItems();
1386 if (di != null && di.length == 1) {
1387 river = d.getItems()[0].getStringValue();
1388 }
1389 }
1390 }
1391 else if (dl.getState().equals("state.winfo.location_distance")){
1392 for (int j = 0; j < dl.size(); j++) {
1393 Data d = dl.get(j);
1394 DataItem[] di = d.getItems();
1395 if (di != null && di.length >= 1 && j == 0) {
1396 value_max = d.getItems()[0].getStringValue();
1397 }
1398 else if (di != null &&
1399 di.length >= 1 &&
1400 j == dl.size() - 1) {
1401 value_min = d.getItems()[0].getStringValue();
1402 }
1403 }
1404 }
1405 }
1406 }
1407
1408 double from = Double.valueOf(value_min);
1409 double to = Double.valueOf(value_max);
1410 wqInfoService.getWQInfo(url, locale, river, from, to,
1411 new AsyncCallback<WQInfoObject[]>() { 1456 new AsyncCallback<WQInfoObject[]>() {
1412 public void onFailure(Throwable caught) { 1457 public void onFailure(Throwable caught) {
1413 GWT.log("Could not recieve wq informations."); 1458 GWT.log("Could not recieve wq informations.");
1414 GWT.log(caught.getMessage()); 1459 SC.warn(caught.getMessage());
1415 } 1460 }
1416 1461
1417 public void onSuccess(WQInfoObject[] wqi) { 1462 public void onSuccess(WQInfoObject[] wqi) {
1418 int num = wqi != null ? wqi.length :0; 1463 int num = wqi != null ? wqi.length :0;
1419 GWT.log("Recieved " + num + " wq informations."); 1464 GWT.log("Recieved " + num + " wq informations.");

http://dive4elements.wald.intevation.org