Mercurial > dive4elements > river
changeset 8528:f7d1a7e66b12
(issue1795) Handle modules configuration for any module
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 17 Feb 2015 16:17:31 +0100 |
parents | 76a2268942c6 |
children | 4ead7919e709 |
files | gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java |
diffstat | 1 files changed, 31 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- 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(); } }