changeset 53:3d5d7788d471

The widgets in the static part of the parameter panel are created using UIProviders now. The ParameterList does not build widgets any longer. flys-client/trunk@1509 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 17 Mar 2011 18:34:20 +0000
parents 1d0be51ab93b
children 0db278371632
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProvider.java flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java
diffstat 8 files changed, 205 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Mar 17 18:20:05 2011 +0000
+++ b/flys-client/ChangeLog	Thu Mar 17 18:34:20 2011 +0000
@@ -1,3 +1,22 @@
+2011-03-17  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties:
+	  Fixed a typo.
+
+	* src/main/java/de/intevation/flys/client/client/ui/ParameterList.java:
+	  The widgets displayed in the static panel are created using the
+	  UIProvider defined in the DataList.
+
+	* src/main/java/de/intevation/flys/client/client/ui/UIProvider.java: There
+	  is a new method createOld() that is used to create the static
+	  representation of a DataList.
+
+	* src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java,
+	  src/main/java/de/intevation/flys/client/client/ui/MapSelection.java,
+	  src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java,
+	  src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java:
+	  Implemented the createOld() method.
+
 2011-03-17  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/DataList.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties	Thu Mar 17 18:20:05 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties	Thu Mar 17 18:34:20 2011 +0000
@@ -22,7 +22,7 @@
 location_distance_state = Berechnungsort/strecke wählen
 location = Ort
 distance = Strecke
-unitFrom = km
+unitFrom = km&nbsp;-
 unitTo = km a
 unitWidth = m
 unitLocation = km
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java	Thu Mar 17 18:20:05 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java	Thu Mar 17 18:34:20 2011 +0000
@@ -1,6 +1,7 @@
 package de.intevation.flys.client.client.ui;
 
 import java.util.LinkedHashMap;
+import java.util.List;
 
 import com.google.gwt.core.client.GWT;
 
@@ -54,6 +55,8 @@
      * distance.*/
     public static final String FIELD_WIDTH = "width";
 
+    public static final int WIDTH = 250;
+
 
     /** The radio group for input mode selection.*/
     protected DynamicForm mode;
@@ -107,6 +110,57 @@
     }
 
 
+    public Canvas createOld(DataList dataList) {
+        List<Data> items = dataList.getAll();
+
+        Data dFrom = getData(items, "ld_from");
+        Data dTo   = getData(items, "ld_to");
+        Data dStep = getData(items, "ld_step");
+
+        DataItem[] from = dFrom.getItems();
+        DataItem[] to   = dTo.getItems();
+        DataItem[] step = dStep.getItems();
+
+        HLayout layout = new HLayout();
+        Label   label  = new Label(dataList.getLabel());
+
+        label.setWidth("50%");
+
+        StringBuilder sb = new StringBuilder();
+        sb.append(from[0].getLabel());
+        sb.append(" " + MESSAGES.unitFrom() + " ");
+        sb.append(to[0].getLabel());
+        sb.append(" " + MESSAGES.unitTo() + " ");
+        sb.append(step[0].getLabel());
+        sb.append(" " + MESSAGES.unitWidth());
+
+        layout.addMember(label);
+        layout.addMember(new Label(sb.toString()));
+
+        return layout;
+    }
+
+
+    /**
+     * This method greps the Data with name <i>name</i> from the list and
+     * returns it.
+     *
+     * @param items A list of Data.
+     * @param name The name of the Data that we are searching for.
+     *
+     * @return the Data with the name <i>name</i>.
+     */
+    protected Data getData(List<Data> data, String name) {
+        for (Data d: data) {
+            if (name.equals(d.getLabel())) {
+                return d;
+            }
+        }
+
+        return null;
+    }
+
+
     protected Canvas createWidget(DataList data) {
         VLayout layout       = new VLayout();
         container            = new HLayout();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java	Thu Mar 17 18:20:05 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/MapSelection.java	Thu Mar 17 18:34:20 2011 +0000
@@ -49,6 +49,7 @@
 
         Canvas form  = super.createWidget(data);
         form.setWidth(250);
+        form.setLayoutAlign(VerticalAlignment.TOP);
 
         ImageResource mapRes = IMAGES.riverMap();
         Img map              = new Img(mapRes.getURL(), 400, 452);
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Thu Mar 17 18:20:05 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Thu Mar 17 18:34:20 2011 +0000
@@ -6,6 +6,7 @@
 import com.google.gwt.core.client.GWT;
 
 import com.smartgwt.client.types.VerticalAlignment;
+import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
@@ -35,7 +36,10 @@
 
 
     protected void init() {
+        setWidth(300);
+
         oldItems.setHeight(20);
+        oldItems.setMembersMargin(10);
         currentItems.setHeight("*");
         currentItems.setAlign(VerticalAlignment.TOP);
 
@@ -107,20 +111,10 @@
             h.setAlign(VerticalAlignment.TOP);
             h.setHeight(20);
 
-            int size  = dataList.size();
-            for (int i = 0; i < size; i++) {
-                // TODO Display all Data objects and use the UIProvider to do so!
-                Data data = dataList.get(i);
+            String     provider   = dataList.getUIProvider();
+            UIProvider uiprovider = UIProviderFactory.getProvider(provider);
 
-                DataItem[] items = data.getItems();
-                Label label = new Label(data.getLabel());
-                Label value = new Label(items[0].getLabel());
-
-                h.addMember(label);
-                h.addMember(value);
-
-                oldItems.addMember(h);
-            }
+            oldItems.addMember(uiprovider.createOld(dataList));
         }
 
         int minHeight = oldItems.getMinHeight();
@@ -139,7 +133,10 @@
      */
     public void refreshCurrent() {
         currentItems.removeMembers(currentItems.getMembers());
-        currentItems.addMember(uiProvider.create(current));
+        Canvas c = uiProvider.create(current);
+        c.setLayoutAlign(VerticalAlignment.TOP);
+
+        currentItems.addMember(c);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java	Thu Mar 17 18:20:05 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java	Thu Mar 17 18:34:20 2011 +0000
@@ -12,6 +12,7 @@
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.form.DynamicForm;
 import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
+import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
 
 import de.intevation.flys.client.shared.model.Data;
@@ -61,6 +62,35 @@
     }
 
 
+    public Canvas createOld(DataList dataList) {
+        HLayout layout  = new HLayout();
+        VLayout vLayout = new VLayout();
+
+        Label label = new Label(dataList.getLabel());
+        label.setWidth("50%");
+
+        int size = dataList.size();
+        for (int i = 0; i < size; i++) {
+            Data data        = dataList.get(i);
+            DataItem[] items = data.getItems();
+
+            for (DataItem item: items) {
+                HLayout hLayout = new HLayout();
+
+                hLayout.addMember(label);
+                hLayout.addMember(new Label(item.getStringValue()));
+
+                vLayout.addMember(hLayout);
+            }
+        }
+
+        layout.addMember(label);
+        layout.addMember(vLayout);
+
+        return layout;
+    }
+
+
     /**
      * This method creates the content of the widget.
      *
@@ -82,6 +112,7 @@
 
             Label label = new Label(d.getDescription());
             label.setValign(VerticalAlignment.TOP);
+            label.setHeight(20);
 
             ComboBoxItem combobox = new ComboBoxItem(d.getLabel());
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProvider.java	Thu Mar 17 18:20:05 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProvider.java	Thu Mar 17 18:34:20 2011 +0000
@@ -24,5 +24,16 @@
      * @return the Canvas showing the Data.
      */
     public Canvas create(DataList data);
+
+
+    /**
+     * This method creates a Canvas element showing the old Data objects in the
+     * DataList <i>data</i>.
+     *
+     * @param dataList The DataList which elements should be displayed.
+     *
+     * @return a Canvas displaying the Data.
+     */
+    public Canvas createOld(DataList dataList);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Thu Mar 17 18:20:05 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Thu Mar 17 18:34:20 2011 +0000
@@ -1,6 +1,7 @@
 package de.intevation.flys.client.client.ui;
 
 import java.util.LinkedHashMap;
+import java.util.List;
 
 import com.google.gwt.core.client.GWT;
 
@@ -14,6 +15,7 @@
 import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
+import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
 
 import de.intevation.flys.client.shared.model.Data;
@@ -120,6 +122,81 @@
     }
 
 
+    public Canvas createOld(DataList dataList) {
+        List<Data> items = dataList.getAll();
+
+        Data dMode = getData(items, "wq_mode");
+        Data dFrom = getData(items, "wq_from");
+        Data dTo   = getData(items, "wq_to");
+        Data dStep = getData(items, "wq_step");
+
+        DataItem[] mode = dMode.getItems();
+        DataItem[] from = dFrom.getItems();
+        DataItem[] to   = dTo.getItems();
+        DataItem[] step = dStep.getItems();
+
+        HLayout layout = new HLayout();
+        Label   label  = new Label(dataList.getLabel());
+
+        label.setWidth("50%");
+
+        String text = mode[0].getStringValue().equals(FIELD_WQ_W)
+            ? createWString(from[0], to[0], step[0])
+            : createQString(from[0], to[0], step[0]);
+
+        layout.addMember(label);
+        layout.addMember(new Label(text));
+
+        return layout;
+    }
+
+
+    protected String createWString(DataItem from, DataItem to, DataItem step) {
+        StringBuilder sb = new StringBuilder();
+        sb.append(from.getLabel());
+        sb.append(" " + MSG.unitWFrom() + " ");
+        sb.append(to.getLabel());
+        sb.append(" " + MSG.unitWTo() + " ");
+        sb.append(step.getLabel());
+        sb.append(" " + MSG.unitWStep());
+
+        return sb.toString();
+    }
+
+
+    protected String createQString(DataItem from, DataItem to, DataItem step) {
+        StringBuilder sb = new StringBuilder();
+        sb.append(from.getLabel());
+        sb.append(" " + MSG.unitQFrom() + " ");
+        sb.append(to.getLabel());
+        sb.append(" " + MSG.unitQTo() + " ");
+        sb.append(step.getLabel());
+        sb.append(" " + MSG.unitQStep());
+
+        return sb.toString();
+    }
+
+
+    /**
+     * This method greps the Data with name <i>name</i> from the list and
+     * returns it.
+     *
+     * @param items A list of Data.
+     * @param name The name of the Data that we are searching for.
+     *
+     * @return the Data with the name <i>name</i>.
+     */
+    protected Data getData(List<Data> data, String name) {
+        for (Data d: data) {
+            if (name.equals(d.getLabel())) {
+                return d;
+            }
+        }
+
+        return null;
+    }
+
+
     /**
      * This method creates the whole widget. There is a panel on the left, that
      * allows the user to enter values manually by keyboard. On the right, there

http://dive4elements.wald.intevation.org