[PATCH] (issue1795) Handle modules configuration for any module

Wald Commits scm-commit at wald.intevation.org
Tue Feb 17 16:17:37 CET 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1424186251 -3600
# Node ID f7d1a7e66b1283398d42e21fe81e026cc392af4a
# Parent  76a2268942c63c74970ef614236276f7ea536e0f
(issue1795) Handle modules configuration for any module

diff -r 76a2268942c6 -r f7d1a7e66b12 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java	Tue Feb 17 12:36:13 2015 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java	Tue Feb 17 16:17:31 2015 +0100
@@ -62,8 +62,7 @@
     /** The ModuleService used to retrieve the available modules of a user.*/
     protected ModuleServiceAsync moduleService = GWT.create(ModuleService.class);
 
-    private List<String> fixRivers;
-    private List<String> minfoRivers;
+    private Map<String, List<String> > modulesRiverMap;
     protected Map<String, HLayout> rivers;
 
     /**
@@ -71,9 +70,7 @@
      */
     public ModuleSelection() {
         rivers = null;
-        //TODO: put all the rivers into a config file, or something.
-        fixRivers = new ArrayList<String>();
-        minfoRivers = new ArrayList<String>();
+        modulesRiverMap = new LinkedHashMap<String, List<String> >();
 
         readModules();
     }
@@ -123,6 +120,29 @@
         });
     }
 
+    private void checkRivers(String selected) {
+        if (selected == null) {
+            selected = getSelectedModule();
+        }
+        if (rivers != null && !rivers.isEmpty() && modules != null && selected != null) {
+            List<String> allowedRivers = modulesRiverMap.get(selected);
+            if ( allowedRivers == null ) {
+                GWT.log("No configured rivers for module: " + selected);
+            }
+            for (Map.Entry<String, HLayout> s: rivers.entrySet()) {
+                if ( allowedRivers == null ) {
+                    s.getValue().hide();
+                    continue;
+                }
+                if (!allowedRivers.contains(s.getKey())) {
+                    s.getValue().hide();
+                } else {
+                    s.getValue().show();
+                }
+            }
+        }
+    }
+
     private void setModules() {
         LinkedHashMap<String, String> values = new LinkedHashMap<String, String>();
 
@@ -135,21 +155,13 @@
                         radio.setDefaultValue(module.getName());
                     }
                 }
-                if (module.getName().equals("fixanalysis")) {
-                    for (String river: module.getRivers()) {
-                        fixRivers.add(river);
-                    }
-                }
-                if (module.getName().equals("minfo")) {
-                    for (String river: module.getRivers()) {
-                        minfoRivers.add(river);
-                    }
-                }
+                modulesRiverMap.put(module.getName(), module.getRivers());
             }
         }
         if (radio != null) {
             radio.setValueMap(values);
         }
+        checkRivers(null);
     }
 
     /**
@@ -167,20 +179,7 @@
         radio.addChangeHandler(new ChangeHandler() {
             @Override
             public void onChange(ChangeEvent event) {
-                String selected = (String)event.getValue();
-                if (!rivers.isEmpty()) {
-                    for (Map.Entry<String, HLayout> s: rivers.entrySet()) {
-                        if (selected.equals("minfo") && !minfoRivers.contains(s.getKey())) {
-                            s.getValue().hide();
-                        }
-                        else if (selected.equals("fixanalysis") && !fixRivers.contains(s.getKey())) {
-                            s.getValue().hide();
-                        }
-                        else {
-                            s.getValue().show();
-                        }
-                    }
-                }
+                checkRivers((String)event.getValue());
             }
         });
 
@@ -232,6 +231,9 @@
     }-*/;
 
     private static String getSelectedModule() {
+        if (radio == null) {
+            return null;
+        }
         return radio.getValueAsString();
     }
 }


More information about the Dive4Elements-commits mailing list