changeset 1586:dbdf954dbe94

Cosmetics. flys-client/trunk@3873 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 02 Feb 2012 07:40:44 +0000
parents 915ad25f4bb8
children 45cd2364adad
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java
diffstat 4 files changed, 66 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Feb 01 15:39:02 2012 +0000
+++ b/flys-client/ChangeLog	Thu Feb 02 07:40:44 2012 +0000
@@ -1,3 +1,13 @@
+2012-02-02  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/DataFactory.java,
+	  src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java:
+	  Cosmetics.
+
+	* src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java:
+	  Cosmetics, removed MESSAGES, use super.MSG instead, comments, minor
+	  refactoring.
+
 2012-02-01  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java	Wed Feb 01 15:39:02 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java	Thu Feb 02 07:40:44 2012 +0000
@@ -39,7 +39,6 @@
     /** The message class that provides i18n strings.*/
     protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
-
     /** The StepForwardHandlers.*/
     protected List<StepForwardHandler> forwardHandlers;
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Wed Feb 01 15:39:02 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Thu Feb 02 07:40:44 2012 +0000
@@ -65,9 +65,6 @@
 extends      AbstractUIProvider
 implements   FilterHandler
 {
-    /** The message class that provides i18n strings. */
-    protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
-
     /** The DistanceInfoService used to retrieve locations about rivers. */
     protected DistanceInfoServiceAsync distanceInfoService =
         GWT.create(DistanceInfoService.class);
@@ -96,6 +93,10 @@
     /** Text to show number of matched items when filtered. */
     protected StaticTextItem filterResultCount;
 
+    /** Name of the data item that keeps locations. */
+    protected String DATA_ITEM_NAME = "ld_locations";
+
+
     /**
      * Creates a new LocationDistancePanel instance.
      */
@@ -114,11 +115,12 @@
      *
      * @return a panel.
      */
+    @Override
     public Canvas create(DataList data) {
         VLayout layout = new VLayout();
         layout.setMembersMargin(10);
 
-        Label label   = new Label(MESSAGES.location ());
+        Label label   = new Label(MSG.location ());
         Canvas widget = createWidget(data);
         Canvas submit = getNextButton();
 
@@ -149,7 +151,7 @@
         locationTable.setShowRecordComponents(true);
         locationTable.setShowRecordComponentsByCell(true);
         locationTable.setHeight100();
-        locationTable.setEmptyMessage(MESSAGES.empty_filter());
+        locationTable.setEmptyMessage(MSG.empty_filter());
         locationTable.setCanReorderFields(false);
 
         ListGridField addLocation = new ListGridField ("", "");
@@ -169,18 +171,18 @@
                 setLocationValues(selected);
             }
         });
-        addLocation.setCellIcon (baseUrl + MESSAGES.markerGreen());
+        addLocation.setCellIcon (baseUrl + MSG.markerGreen());
 
         ListGridField ldescr = new ListGridField("description",
-                MESSAGES.description());
+                MSG.description());
         ldescr.setType(ListGridFieldType.TEXT);
         ldescr.setWidth("*");
         ListGridField lside = new ListGridField("riverside",
-                MESSAGES.riverside());
+                MSG.riverside());
         lside.setType(ListGridFieldType.TEXT);
         lside.setWidth("10%");
 
-        ListGridField loc = new ListGridField("from", MESSAGES.location());
+        ListGridField loc = new ListGridField("from", MSG.location());
         loc.setCellFormatter(new CellFormatter() {
             public String format(
                 Object value,
@@ -204,12 +206,12 @@
         loc.setWidth("10%");
 
         ListGridField bottom =
-            new ListGridField("bottom", MESSAGES.bottom_edge());
+            new ListGridField("bottom", MSG.bottom_edge());
         bottom.setType(ListGridFieldType.TEXT);
         bottom.setWidth("10%");
 
         ListGridField top =
-            new ListGridField("top", MESSAGES.top_edge());
+            new ListGridField("top", MSG.top_edge());
         top.setType(ListGridFieldType.TEXT);
         top.setWidth("10%");
 
@@ -218,15 +220,19 @@
     }
 
 
+    /**
+     * 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, "ld_locations");
+        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 label = new Label(dataList.getLabel());
         label.setWidth("200px");
 
         Canvas back = getBackButton(dataList.getState());
@@ -264,7 +270,7 @@
             max = Double.parseDouble(iMax.getStringValue());
         }
         catch (NumberFormatException nfe) {
-            SC.warn(MESSAGES.error_read_minmax_values());
+            SC.warn(MSG.error_read_minmax_values());
             min = -Double.MAX_VALUE;
             max = Double.MAX_VALUE;
         }
@@ -283,7 +289,7 @@
 
 
     /**
-     * This method greps the Data with name <i>name</i> from the list and
+     * This method grabs the Data with name <i>name</i> from the list and
      * returns it.
      *
      * @param items A list of Data.
@@ -291,6 +297,7 @@
      *
      * @return the Data with the name <i>name</i>.
      */
+    @Override
     protected Data getData(List<Data> data, String name) {
         for (Data d: data) {
             if (name.equals(d.getLabel())) {
@@ -306,11 +313,11 @@
         VLayout layout       = new VLayout();
         container            = new HLayout();
 
-        // the initial view will display the location input mode
+        // The initial view will display the location input mode.
         locationPanel = new DoubleArrayPanel(
-                MESSAGES.unitLocation(),
-                getLocationValues(),
-                new BlurHandler(){public void onBlur(BlurEvent be) {}});
+            MSG.unitLocation(),
+            getLocationValues(),
+            new BlurHandler(){public void onBlur(BlurEvent be) {}});
 
         locationTable.setAutoFetchData(true);
 
@@ -320,7 +327,7 @@
 
         container.setMembersMargin(30);
 
-        filterResultCount = new StaticTextItem(MESSAGES.resultCount());
+        filterResultCount = new StaticTextItem(MSG.resultCount());
         filterResultCount.setTitleAlign(Alignment.LEFT);
         filterResultCount.setTitleStyle("color: #000");
 
@@ -355,8 +362,8 @@
 
         LinkedHashMap<String, String> filterMap =
             new LinkedHashMap<String, String>();
-        filterMap.put("description", MESSAGES.description());
-        filterMap.put("range", MESSAGES.range());
+        filterMap.put("description", MSG.description());
+        filterMap.put("range", MSG.range());
         filterCriteria.setValueMap(filterMap);
         filterCriteria.setValue("description");
 
@@ -378,6 +385,8 @@
         return layout;
     }
 
+
+    @Override
     public void onFilterCriteriaChanged(StringFilterEvent event) {
         String search = event.getFilter();
 
@@ -392,6 +401,7 @@
     }
 
 
+    @Override
     public void onFilterCriteriaChanged(RangeFilterEvent event) {
         Float from = event.getFrom() - 0.001f;
         Float to = event.getTo() + 0.001f;
@@ -430,7 +440,7 @@
         saveLocationValues(locationPanel);
 
         if (!locationPanel.validateForm()) {
-            errors.add(MESSAGES.wrongFormat());
+            errors.add(MSG.wrongFormat());
             return errors;
         }
 
@@ -439,12 +449,12 @@
         int      idx    = 0;
 
         if (values.length > 1) {
-            errors.add(MESSAGES.too_many_values());
+            errors.add(MSG.too_many_values());
         }
 
         for (double value: values) {
             if (value < min || value > max) {
-                String tmp = MESSAGES.error_validate_range();
+                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));
@@ -468,6 +478,20 @@
     }
 
 
+    /** 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.
      *
@@ -477,30 +501,17 @@
         saveLocationValues(locationPanel);
         double[] values = getLocationValues();
         Data[] data = new Data[values.length+1];
-        DataItem item = new DefaultDataItem();
+
         for (int i = 0; i < values.length; i++) {
-            item = new DefaultDataItem(
-                "ld_locations",
-                "ld_locations",
+            data[i] = createDataArray(DATA_ITEM_NAME,
                 Double.valueOf(values[i]).toString());
-            data[i] = new DefaultData(
-                "ld_locations",
-                null,
-                null,
-                new DataItem[] {item});
         }
-        data[values.length] = new DefaultData(
-            "ld_mode",
-            null, null,
-            new DataItem[] {
-                new DefaultDataItem("ld_mode", "ld_mode", "locations") });
+        data[values.length] = createDataArray("ld_mode", "locations");
 
         return data;
     }
 
 
-
-
     /**
      * Validates and stores all values entered in the location mode.
      *
@@ -533,12 +544,13 @@
     protected void createInputPanel() {
         Config config = Config.getInstance();
         String url    = config.getServerUrl();
-        String locale = config.getLocale ();
         String river  = "";
 
         ArtifactDescription adescr = artifact.getArtifactDescription();
         DataList[] data = adescr.getOldData();
 
+        // Try to find a "river" data item to set the source for the
+        // list grid.
         if (data != null && data.length > 0) {
             for (int i = 0; i < data.length; i++) {
                 DataList dl = data[i];
@@ -561,11 +573,13 @@
     }
 
 
+    /** 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);
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java	Wed Feb 01 15:39:02 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java	Thu Feb 02 07:40:44 2012 +0000
@@ -29,7 +29,6 @@
 
     private static final Logger logger = Logger.getLogger(DataFactory.class);
 
-
     public static final String NS_URI = ArtifactNamespaceContext.NAMESPACE_URI;
 
 

http://dive4elements.wald.intevation.org