diff flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java @ 1591:8ab010967f78

Refactored. flys-client/trunk@3888 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 03 Feb 2012 08:30:58 +0000
parents 4b773cfd11b5
children ff9d71469b7c
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Thu Feb 02 13:42:12 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Fri Feb 03 08:30:58 2012 +0000
@@ -42,28 +42,13 @@
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class SingleLocationPanel
-extends      AbstractUIProvider
+extends      LocationPanel
 implements   RecordClickHandler
 {
     /** The DistanceInfoService used to retrieve locations about rivers. */
     protected DistanceInfoServiceAsync distanceInfoService =
         GWT.create(DistanceInfoService.class);
 
-    /** A container that will contain the location or the distance panel. */
-    protected HLayout container;
-
-    /** The minimal value that the user is allowed to enter. */
-    protected double min;
-
-    /** The maximal value that the user is allowed to enter. */
-    protected double max;
-
-    /** The values entered in the location mode. */
-    protected double[] values;
-
-    /** The input panel for locations. */
-    protected DoubleArrayPanel locationPanel;
-
     /** The table data. */
     protected DistanceInfoObject[] tableData;
 
@@ -97,7 +82,6 @@
         layout.setMembersMargin(10);
 
         Label label   = new Label(MSG.location ());
-        //picker = new LocationPicker(this);
         Canvas widget = createWidget(data);
         Canvas submit = getNextButton();
 
@@ -116,35 +100,6 @@
     }
 
 
-
-    /**
-     * This method creates a Canvas element showing the old Data objects in the
-     * DataList <i>data</i>.
-     */
-    public Canvas createOld(DataList dataList) {
-        List<Data> items = dataList.getAll();
-        Data dLocation = getData(items, DATA_ITEM_NAME);
-        DataItem[] loc = dLocation.getItems();
-
-        HLayout layout = new HLayout();
-        layout.setWidth("400px");
-
-        Label label = new Label(dataList.getLabel());
-        label.setWidth("200px");
-
-        Canvas back = getBackButton(dataList.getState());
-
-        Label selected = new Label(loc[0].getLabel());
-        selected.setWidth("130px");
-
-        layout.addMember(label);
-        layout.addMember(selected);
-        layout.addMember(back);
-
-        return layout;
-    }
-
-
     /**
      * This method reads the default values defined in the DataItems of the Data
      * objects in <i>list</i>.
@@ -203,6 +158,34 @@
     }
 
 
+    protected Canvas createWidget(DataList data) {
+        VLayout layout = new VLayout();
+        inputLayout      = new HLayout();
+
+        // The initial view will display the location input mode.
+        locationPanel = new DoubleArrayPanel(
+            MSG.unitLocation(),
+            getLocationValues(),
+            new BlurHandler(){public void onBlur(BlurEvent be) {}});
+
+        picker.getLocationTable().setAutoFetchData(true);
+
+        inputLayout.addMember(locationPanel);
+
+        layout.addMember(inputLayout);
+
+        inputLayout.setMembersMargin(30);
+
+        picker.prepareFilter();
+
+        helperContainer.addMember(picker.getLocationTable());
+        helperContainer.addMember(picker.getFilterLayout());
+        helperContainer.addMember(picker.getResultCountForm());
+        setPickerDataSource();
+        return layout;
+    }
+
+
     /**
      * This method grabs the Data with name <i>name</i> from the list and
      * returns it.
@@ -224,94 +207,6 @@
     }
 
 
-    protected Canvas createWidget(DataList data) {
-        VLayout layout       = new VLayout();
-        container            = new HLayout();
-
-        // The initial view will display the location input mode.
-        locationPanel = new DoubleArrayPanel(
-            MSG.unitLocation(),
-            getLocationValues(),
-            new BlurHandler(){public void onBlur(BlurEvent be) {}});
-
-        picker.getLocationTable().setAutoFetchData(true);
-
-        container.addMember(locationPanel);
-
-        layout.addMember(container);
-
-        container.setMembersMargin(30);
-
-        picker.prepareFilter();
-
-        helperContainer.addMember(picker.getLocationTable());
-        helperContainer.addMember(picker.getFilterLayout());
-        helperContainer.addMember(picker.getResultCountForm());
-        createInputPanel();
-        return layout;
-    }
-
-
-    @Override
-    public List<String> validate() {
-        List<String> errors = new ArrayList<String>();
-        NumberFormat nf     = NumberFormat.getDecimalFormat();
-
-        saveLocationValues(locationPanel);
-
-        if (!locationPanel.validateForm()) {
-            errors.add(MSG.wrongFormat());
-            return errors;
-        }
-
-        double[] values = getLocationValues();
-        double[] good   = new double[values.length];
-        int      idx    = 0;
-
-        if (values.length > 1) {
-            errors.add(MSG.too_many_values());
-        }
-
-        for (double value: values) {
-            if (value < min || value > max) {
-                String tmp = MSG.error_validate_range();
-                tmp = tmp.replace("$1", nf.format(value));
-                tmp = tmp.replace("$2", nf.format(min));
-                tmp = tmp.replace("$3", nf.format(max));
-                errors.add(tmp);
-            }
-            else {
-                good[idx++] = value;
-            }
-        }
-
-        double[] justGood = new double[idx];
-        for (int i = 0; i < justGood.length; i++) {
-            justGood[i] = good[i];
-        }
-
-        if (!errors.isEmpty()) {
-            locationPanel.setValues(justGood);
-        }
-
-        return errors;
-    }
-
-
-    /** Create simple DefaultData with single DataItem inside. */
-    public DefaultData createDataArray(String name, String value) {
-        DataItem item = new DefaultDataItem(
-            name,
-            name,
-            value);
-
-        return new DefaultData(name,
-            null,
-            null,
-            new DataItem[] {item});
-    }
-
-
     /**
      * This method returns the selected data.
      *
@@ -332,36 +227,8 @@
     }
 
 
-    /**
-     * Validates and stores all values entered in the location mode.
-     *
-     * @param p The DoubleArrayPanel.
-     */
-    protected void saveLocationValues(DoubleArrayPanel p) {
-        FormItem[] formItems = p.getFields();
-
-        for (FormItem item: formItems) {
-            if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) {
-                saveLocationValue(p, item);
-            }
-        }
-    }
-
-
-    /**
-     * Validates and stores a value entered in the location mode.
-     *
-     * @param p The DoubleArrayPanel.
-     * @param item The item that needs to be validated.
-     */
-    protected void saveLocationValue(DoubleArrayPanel p, FormItem item) {
-        if (p.validateForm(item)) {
-            setLocationValues(p.getInputValues(item));
-        }
-    }
-
-
-    protected void createInputPanel() {
+    /** Hook service to the listgrid with possible input values. */
+    protected void setPickerDataSource() {
         Config config = Config.getInstance();
         String url    = config.getServerUrl();
         String river  = "";
@@ -389,20 +256,7 @@
         }
 
         picker.getLocationTable().setDataSource(new DistanceInfoDataSource(
-            url, /*river*/ "Saar" , "locations"));
-    }
-
-
-    /** Get the location values. */
-    protected double[] getLocationValues() {
-        return values;
-    }
-
-
-    /** Sets Location values and updates the panel. */
-    protected void setLocationValues(double[] values) {
-        this.values = values;
-        locationPanel.setValues(values);
+            url, river, "locations"));
     }
 
 

http://dive4elements.wald.intevation.org