changeset 3518:33ed40aa1201

User ModuleService to get all modules for a user Don't hardcode the Modules instead load them from the ModuleService. This allows to show only modules that a user is allowed to access. flys-client/trunk@5292 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Wed, 29 Aug 2012 12:38:06 +0000
parents 40ddd713d9fd
children f9ef72f4c6d5
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/ModuleSelection.java
diffstat 2 files changed, 55 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Aug 29 12:34:25 2012 +0000
+++ b/flys-client/ChangeLog	Wed Aug 29 12:38:06 2012 +0000
@@ -1,3 +1,8 @@
+2012-08-30	Björn Ricks	<bjoern.ricks@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/ModuleSelection.java:
+	  Load modules from the ModuleService instead of using hardcoded strings.
+
 2012-08-30	Björn Ricks	<bjoern.ricks@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/server/ModuleServiceImpl.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ModuleSelection.java	Wed Aug 29 12:34:25 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ModuleSelection.java	Wed Aug 29 12:38:06 2012 +0000
@@ -3,8 +3,10 @@
 import java.util.LinkedHashMap;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.types.VerticalAlignment;
+import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.form.DynamicForm;
@@ -12,12 +14,16 @@
 import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
 
+import de.intevation.flys.client.client.services.ModuleService;
+import de.intevation.flys.client.client.services.ModuleServiceAsync;
 import de.intevation.flys.client.shared.model.Data;
 import de.intevation.flys.client.shared.model.DataItem;
 import de.intevation.flys.client.shared.model.DataList;
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
+import de.intevation.flys.client.shared.model.Module;
 
+import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYSConstants;
 
 /**
@@ -56,11 +62,18 @@
     /** The module checkboxes.*/
     protected RadioGroupItem radio;
 
+    /** */
+    protected Module[] modules;
+
+    /** The ModuleService used to retrieve the available modules of a user.*/
+    protected ModuleServiceAsync moduleService = GWT.create(ModuleService.class);
+
 
     /**
      * The default constructor.
      */
     public ModuleSelection() {
+        readModules();
     }
 
 
@@ -73,6 +86,7 @@
      * @return the module selection combined with the river selection.
      */
     public Canvas create(DataList data) {
+        GWT.log("ModuleSelection - create()");
         VLayout newLayout = new VLayout();
         newLayout.setMembersMargin(10);
         newLayout.setAlign(VerticalAlignment.TOP);
@@ -85,6 +99,37 @@
         return newLayout;
     }
 
+    private void readModules() {
+        Config config = Config.getInstance();
+        String locale = config.getLocale();
+
+        moduleService.list(locale, new AsyncCallback<Module[]>() {
+            @Override
+            public void onFailure(Throwable caught) {
+                GWT.log("Could not recieve a list of modules.");
+                SC.warn(MSG.getString(caught.getMessage()));
+            }
+
+            @Override
+            public void onSuccess(Module[] newmodules) {
+                GWT.log("Retrieved " + newmodules.length + " modules.");
+                modules = newmodules;
+                setModules();
+            }
+        });
+    }
+
+    private void setModules() {
+        LinkedHashMap values = new LinkedHashMap();
+        if (this.modules!= null) {
+            for(Module module : this.modules) {
+                values.put(module.getName(), module.getLocalizedName());
+            }
+        }
+        if (radio != null) {
+            radio.setValueMap(values);
+        }
+    }
 
     /**
      * Creates a widget that displays a checkbox for each module.
@@ -102,22 +147,17 @@
         label.setWidth(50);
         label.setHeight(25);
 
-        LinkedHashMap values = new LinkedHashMap();
-        values.put(FIELD_PLUGIN_WINFO, messages.winfo());
-        values.put(FIELD_PLUGIN_MINFO, messages.minfo());
-        values.put(FIELD_PLUGIN_FIX, messages.fix());
-        values.put(FIELD_PLUGIN_CHART, messages.new_chart());
-        values.put(FIELD_PLUGIN_MAP, messages.new_map());
 
         radio.setShowTitle(false);
         radio.setVertical(true);
-        radio.setValueMap(values);
 
-        LinkedHashMap initial = new LinkedHashMap();
-        initial.put(FIELD_PLUGIN, FIELD_PLUGIN_WINFO);
+        setModules();
+
+        /* LinkedHashMap initial = new LinkedHashMap(); */
+        /* initial.put(FIELD_PLUGIN, FIELD_PLUGIN_WINFO); */
 
         form.setFields(radio);
-        form.setValues(initial);
+        /* form.setValues(initial); */
 
         layout.addMember(label);
         layout.addMember(form);

http://dive4elements.wald.intevation.org