changeset 6666:3c4c0ea52bbb

issue1259: in WQAdaptedInputPanel (vollmer w/q-input) allow click selection of W values, analogously to Q values.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 26 Jul 2013 08:59:55 +0200
parents b7945db8a43b
children 84349d440987
files gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedInputPanel.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/QDTable.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/WTable.java
diffstat 3 files changed, 89 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedInputPanel.java	Thu Jul 25 15:08:13 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedInputPanel.java	Fri Jul 26 08:59:55 2013 +0200
@@ -140,6 +140,7 @@
     }
 
 
+    /** Create labels, canvasses, layouts. */
     @Override
     public Canvas create(DataList data) {
         readGaugeRanges(data);
@@ -196,7 +197,7 @@
             qdTables.add(qdTable);
 
             qdTable.showSelect();
-            //wTable.showSelect();
+            wTable.showSelect();
             wTab.setPane(wTable);
             qTab.setPane(qdTable);
 
@@ -267,6 +268,57 @@
             qdTable.addCellClickHandler(handler);
             i++;
         }
+
+        i = 0;
+        for (WTable wTable: wTables) {
+            // Register listener such that values are filled in on click.
+            final WTable table = wTable;
+            final int fi = i;
+            CellClickHandler handler = new CellClickHandler() {
+                @Override
+                public void onCellClick(CellClickEvent e) {
+                    if (!isWMode() /*|| table.isLocked()*/) {
+                        return;
+                    }
+
+                    Record r   = e.getRecord();
+                    double val = r.getAttributeAsDouble("value");
+
+                    doubleArrayPanels.get(fi).setValues(new double[]{val});
+                    // If a named value for first gauge is chosen, try to find and set
+                    // the values to the other panels too.
+                    if (fi == 0) {
+                        String valueName = r.getAttribute("name");
+                        int oi = 0;
+                        // TODO instead of oi use random access.
+                        for (WTable otherWTable: wTables) {
+                            if (oi == 0) {
+                                oi++;
+                                continue;
+                            }
+                            Double value = otherWTable.findRecordValue(valueName);
+                            if (value == null) {
+                                // TODO: afterwards it freaks out
+                                SC.warn(MSG.noMainValueAtGauge());
+                            }
+                            else {
+                                doubleArrayPanels.get(oi).setValues(new double[]{value});
+                            }
+                            oi++;
+                        }
+                    }
+                    else {
+                        // Focus next.
+                        if (fi != doubleArrayPanels.size()-1) {
+                            doubleArrayPanels.get(fi+1).focusInItem(1);
+                        }
+                    }
+                }
+            };
+
+            wTable.addCellClickHandler(handler);
+            i++;
+        }
     }
 
 
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/QDTable.java	Thu Jul 25 15:08:13 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/QDTable.java	Fri Jul 26 08:59:55 2013 +0200
@@ -22,7 +22,12 @@
 
 
 /**
- * Table showing Q and D main values, allowing for selection.
+ * Table showing Q and D main values, allowing for selection, if
+ * showSelect is called. In that case, a CellClickHandler should
+ * be registered.
+ *
+ * TODO becomes very similiar to WTable. Probably mergeable.
+ *
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class QDTable extends ListGrid {
@@ -119,6 +124,7 @@
         hideField("min");
     }
 
+    /** Whether or not can be clicked on. */
     public boolean isLocked() {
         return lockClick;
     }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/WTable.java	Thu Jul 25 15:08:13 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/wq/WTable.java	Fri Jul 26 08:59:55 2013 +0200
@@ -21,6 +21,8 @@
 import org.dive4elements.river.client.client.FLYSConstants;
 
 /**
+ * Table showing W main values.
+ * TODO becomes very similiar to QDTable. Probably mergeable.
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class WTable extends ListGrid {
@@ -30,6 +32,8 @@
 
 
     public WTable() {
+        String baseUrl = GWT.getHostPageBaseURL();
+
         setWidth100();
         setHeight100();
         setSelectionType(SelectionStyle.NONE);
@@ -68,7 +72,31 @@
             }
         });
 
-        setFields(name, type, value);
+        ListGridField select = new ListGridField("select", MESSAGE.selection());
+        select.setType(ListGridFieldType.ICON);
+        select.setWidth(70);
+        select.setCellIcon(baseUrl + MESSAGE.markerGreen());
+
+        setFields(select, name, type, value);
+        hideField("select");
+    }
+
+    public void showSelect() {
+        showField("select");
+    }
+
+
+    /**
+     * Search all records for one with attribute name equals to given name.
+     * @return null if none found.
+     * */
+    public Double findRecordValue(String name) {
+        for (ListGridRecord record : getRecords()) {
+            if (record.getAttribute("name").equals(name)) {
+                return record.getAttributeAsDouble("value");
+            }
+        }
+        return null;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org