changeset 9231:082e8e808902

Finetuning intelligent waterlevel-sounding select. Soundings without year are never shown. All involed datacage elements are assumed to have a 'year' attribute
author gernotbelger
date Fri, 06 Jul 2018 13:09:25 +0200
parents 6a1580b38e7d
children 5030c46d8cb4
files gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/FlowDepthTwinPanel.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/WaterlevelSoundingSelectionController.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/WaterlevelSoundingYearFilter.java
diffstat 3 files changed, 52 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/FlowDepthTwinPanel.java	Fri Jul 06 13:08:15 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/FlowDepthTwinPanel.java	Fri Jul 06 13:09:25 2018 +0200
@@ -21,12 +21,13 @@
 
     private static final long serialVersionUID = 1L;
 
-    private static final DefaultDatacageTwinPanelInfo LEFT_INFO = new DefaultDatacageTwinPanelInfo(MSG.sinfo_columnlabel_soundings(), "bedheight",
+    private static final DefaultDatacageTwinPanelInfo SOUNDING_INFO = new DefaultDatacageTwinPanelInfo(MSG.sinfo_columnlabel_soundings(), "bedheight",
             "sinfo_flowdepth_minfo_heights");
 
-    private static final NilDatacageTwinPanelInfo RIGHT_INFO = new NilDatacageTwinPanelInfo(MSG.sinfo_columnlabel_waterlevels(), "sinfo_flowdepth_waterlevels");
+    private static final NilDatacageTwinPanelInfo WATERLEVEL_INFO = new NilDatacageTwinPanelInfo(MSG.sinfo_columnlabel_waterlevels(),
+            "sinfo_flowdepth_waterlevels");
 
     public FlowDepthTwinPanel(final User user, final int maxCount, final String msgMaxCount) {
-        super(user, new FlowDepthTwinPanelValidator(), new WaterlevelSoundingSelectionController(MSG), LEFT_INFO, RIGHT_INFO, maxCount, msgMaxCount);
+        super(user, new FlowDepthTwinPanelValidator(), new WaterlevelSoundingSelectionController(MSG), SOUNDING_INFO, WATERLEVEL_INFO, maxCount, msgMaxCount);
     }
 }
\ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/WaterlevelSoundingSelectionController.java	Fri Jul 06 13:08:15 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/WaterlevelSoundingSelectionController.java	Fri Jul 06 13:09:25 2018 +0200
@@ -14,6 +14,9 @@
 import org.dive4elements.river.client.client.FLYSConstants;
 import org.dive4elements.river.client.client.ui.DatacagePairWidget.IDatacagePairControler;
 import org.dive4elements.river.client.client.ui.DatacageWidget;
+import org.dive4elements.river.client.client.ui.DatacageWidget.DatacageFilter;
+import org.dive4elements.river.client.shared.model.AttrList;
+import org.dive4elements.river.client.shared.model.DataCageNode;
 
 import com.smartgwt.client.data.DataSource;
 import com.smartgwt.client.data.DataSourceField;
@@ -51,6 +54,28 @@
     @Override
     public void setup(final DatacageWidget soundingWidget, final DatacageWidget waterlevelWidget, final HLayout toolbarLayout) {
 
+        /* do not show ever any soundings that do not have a year */
+        soundingWidget.setFilter(new DatacageFilter() {
+            @Override
+            public boolean accept(final DataCageNode node) {
+
+                final AttrList attributes = node.getAttributes();
+                if (WaterlevelSoundingYearFilter.isFolder(attributes))
+                    return true;
+
+                final String year = attributes.getValue(WaterlevelSoundingSelectionController.ATTRIBUTE_YEAR);
+
+                final Integer waterlevelYear = WaterlevelSoundingYearFilter.parseYear(year);
+                if (waterlevelYear == null) {
+                    // should never happen, we should only show waterlevels that have a year
+                    return false;
+                }
+
+                return true;
+            }
+        });
+
+        /* react to selections of a sounding */
         soundingWidget.getTreeGrid().addSelectionUpdatedHandler(new SelectionUpdatedHandler() {
 
             @Override
@@ -60,6 +85,7 @@
             }
         });
 
+        /* check box to deactivate intellicence */
         final DynamicForm form = createIntelligenCheckbox();
         toolbarLayout.addMember(form);
         form.addItemChangedHandler(new ItemChangedHandler() {
@@ -72,7 +98,7 @@
             }
         });
 
-        /* init to current selection */
+        /* initialize by applying the current selection */
         handleSoundingChanged(waterlevelWidget, soundingWidget.getPlainSelection());
     }
 
@@ -104,11 +130,11 @@
 
         if (this.turnFilterOff) {
             waterlevelWidget.setFilter(DatacageWidget.ACCEPT_ALL_FILTER);
-            waterlevelWidget.getTreeGrid().setEmptyMessage(this.msg.databasket_loading());
+            waterlevelWidget.getTreeGrid().setEmptyMessage(this.msg.databasket_empty());
             return;
         }
 
-        // more than one should never happen, as the have single selection
+        // more than one should never happen, as the bedhhave single selection
         final TreeNode soundingNode = selection.isEmpty() ? null : selection.get(0);
 
         if (soundingNode == null || soundingNode.getAttribute("factory") == null) {
@@ -117,27 +143,15 @@
             return;
         }
 
-        final Integer soundingYear = getYear(soundingNode);
+        final Integer soundingYear = WaterlevelSoundingYearFilter.parseYear(soundingNode.getAttribute(ATTRIBUTE_YEAR));
 
         if (soundingYear == null) {
             // should never happen, as we should only show soundings that actually have a year
             waterlevelWidget.setFilter(DatacageWidget.ACCEPT_NONE_FILTER);
-            waterlevelWidget.getTreeGrid().setEmptyMessage("Der gewählte Wassrspiegel hat keine Informations zum Jahr");
-        } else
+            waterlevelWidget.getTreeGrid().setEmptyMessage("Die gewählte Peilung hat keine Informations zum Jahr");
+        } else {
             waterlevelWidget.setFilter(new WaterlevelSoundingYearFilter(soundingYear));
-    }
-
-    private static Integer getYear(final TreeNode soundingNode) {
-        final String year = soundingNode.getAttribute(ATTRIBUTE_YEAR);
-        if (year == null || year.trim().isEmpty())
-            return null;
-
-        try {
-            return Integer.valueOf(year);
-        }
-        catch (final NumberFormatException e) {
-            e.printStackTrace();
-            return null;
+            waterlevelWidget.getTreeGrid().setEmptyMessage(this.msg.databasket_empty());
         }
     }
 }
\ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/WaterlevelSoundingYearFilter.java	Fri Jul 06 13:08:15 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/WaterlevelSoundingYearFilter.java	Fri Jul 06 13:09:25 2018 +0200
@@ -28,13 +28,12 @@
     public boolean accept(final DataCageNode node) {
 
         final AttrList attributes = node.getAttributes();
-        if (attributes == null)
+
+        if (isFolder(attributes))
             return true;
 
-        if (!attributes.hasAttribute("factory"))
-            return true;
-
-        final Integer waterlevelYear = getYear(attributes);
+        final String year = attributes.getValue(WaterlevelSoundingSelectionController.ATTRIBUTE_YEAR);
+        final Integer waterlevelYear = parseYear(year);
         if (waterlevelYear == null) {
             // should never happen, we should only show waterlevels that have a year
             return false;
@@ -60,9 +59,8 @@
         return 3;
     }
 
-    private static Integer getYear(final AttrList attributes) {
+    static Integer parseYear(final String year) {
 
-        final String year = attributes.getValue(WaterlevelSoundingSelectionController.ATTRIBUTE_YEAR);
         if (year == null || year.trim().isEmpty())
             return null;
 
@@ -74,4 +72,14 @@
             return null;
         }
     }
+
+    static boolean isFolder(final AttrList attributes) {
+        if (attributes == null)
+            return true;
+
+        if (!attributes.hasAttribute("factory"))
+            return true;
+
+        return false;
+    }
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org