comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ModuleSelection.java @ 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 6455bb59a26e
children 8c9c202292fe
comparison
equal deleted inserted replaced
3517:40ddd713d9fd 3518:33ed40aa1201
1 package de.intevation.flys.client.client.ui; 1 package de.intevation.flys.client.client.ui;
2 2
3 import java.util.LinkedHashMap; 3 import java.util.LinkedHashMap;
4 4
5 import com.google.gwt.core.client.GWT; 5 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.user.client.rpc.AsyncCallback;
6 7
7 import com.smartgwt.client.types.VerticalAlignment; 8 import com.smartgwt.client.types.VerticalAlignment;
9 import com.smartgwt.client.util.SC;
8 import com.smartgwt.client.widgets.Canvas; 10 import com.smartgwt.client.widgets.Canvas;
9 import com.smartgwt.client.widgets.Label; 11 import com.smartgwt.client.widgets.Label;
10 import com.smartgwt.client.widgets.form.DynamicForm; 12 import com.smartgwt.client.widgets.form.DynamicForm;
11 import com.smartgwt.client.widgets.form.fields.RadioGroupItem; 13 import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
12 import com.smartgwt.client.widgets.layout.HLayout; 14 import com.smartgwt.client.widgets.layout.HLayout;
13 import com.smartgwt.client.widgets.layout.VLayout; 15 import com.smartgwt.client.widgets.layout.VLayout;
14 16
17 import de.intevation.flys.client.client.services.ModuleService;
18 import de.intevation.flys.client.client.services.ModuleServiceAsync;
15 import de.intevation.flys.client.shared.model.Data; 19 import de.intevation.flys.client.shared.model.Data;
16 import de.intevation.flys.client.shared.model.DataItem; 20 import de.intevation.flys.client.shared.model.DataItem;
17 import de.intevation.flys.client.shared.model.DataList; 21 import de.intevation.flys.client.shared.model.DataList;
18 import de.intevation.flys.client.shared.model.DefaultData; 22 import de.intevation.flys.client.shared.model.DefaultData;
19 import de.intevation.flys.client.shared.model.DefaultDataItem; 23 import de.intevation.flys.client.shared.model.DefaultDataItem;
24 import de.intevation.flys.client.shared.model.Module;
20 25
26 import de.intevation.flys.client.client.Config;
21 import de.intevation.flys.client.client.FLYSConstants; 27 import de.intevation.flys.client.client.FLYSConstants;
22 28
23 /** 29 /**
24 * The ModuleSelection combines the river selection and the module selection in 30 * The ModuleSelection combines the river selection and the module selection in
25 * one widget. It will display a vertical splitted widget - the upper part will 31 * one widget. It will display a vertical splitted widget - the upper part will
54 60
55 61
56 /** The module checkboxes.*/ 62 /** The module checkboxes.*/
57 protected RadioGroupItem radio; 63 protected RadioGroupItem radio;
58 64
65 /** */
66 protected Module[] modules;
67
68 /** The ModuleService used to retrieve the available modules of a user.*/
69 protected ModuleServiceAsync moduleService = GWT.create(ModuleService.class);
70
59 71
60 /** 72 /**
61 * The default constructor. 73 * The default constructor.
62 */ 74 */
63 public ModuleSelection() { 75 public ModuleSelection() {
76 readModules();
64 } 77 }
65 78
66 79
67 /** 80 /**
68 * This method returns a widget that renders the checkboxes for each module 81 * This method returns a widget that renders the checkboxes for each module
71 * @param data The provided rivers. 84 * @param data The provided rivers.
72 * 85 *
73 * @return the module selection combined with the river selection. 86 * @return the module selection combined with the river selection.
74 */ 87 */
75 public Canvas create(DataList data) { 88 public Canvas create(DataList data) {
89 GWT.log("ModuleSelection - create()");
76 VLayout newLayout = new VLayout(); 90 VLayout newLayout = new VLayout();
77 newLayout.setMembersMargin(10); 91 newLayout.setMembersMargin(10);
78 newLayout.setAlign(VerticalAlignment.TOP); 92 newLayout.setAlign(VerticalAlignment.TOP);
79 Canvas moduleSelection = createWidget(); 93 Canvas moduleSelection = createWidget();
80 94
83 newLayout.addMember(moduleSelection); 97 newLayout.addMember(moduleSelection);
84 98
85 return newLayout; 99 return newLayout;
86 } 100 }
87 101
102 private void readModules() {
103 Config config = Config.getInstance();
104 String locale = config.getLocale();
105
106 moduleService.list(locale, new AsyncCallback<Module[]>() {
107 @Override
108 public void onFailure(Throwable caught) {
109 GWT.log("Could not recieve a list of modules.");
110 SC.warn(MSG.getString(caught.getMessage()));
111 }
112
113 @Override
114 public void onSuccess(Module[] newmodules) {
115 GWT.log("Retrieved " + newmodules.length + " modules.");
116 modules = newmodules;
117 setModules();
118 }
119 });
120 }
121
122 private void setModules() {
123 LinkedHashMap values = new LinkedHashMap();
124 if (this.modules!= null) {
125 for(Module module : this.modules) {
126 values.put(module.getName(), module.getLocalizedName());
127 }
128 }
129 if (radio != null) {
130 radio.setValueMap(values);
131 }
132 }
88 133
89 /** 134 /**
90 * Creates a widget that displays a checkbox for each module. 135 * Creates a widget that displays a checkbox for each module.
91 * 136 *
92 * @return a widget with checkboxes. 137 * @return a widget with checkboxes.
100 radio = new RadioGroupItem("plugin"); 145 radio = new RadioGroupItem("plugin");
101 146
102 label.setWidth(50); 147 label.setWidth(50);
103 label.setHeight(25); 148 label.setHeight(25);
104 149
105 LinkedHashMap values = new LinkedHashMap();
106 values.put(FIELD_PLUGIN_WINFO, messages.winfo());
107 values.put(FIELD_PLUGIN_MINFO, messages.minfo());
108 values.put(FIELD_PLUGIN_FIX, messages.fix());
109 values.put(FIELD_PLUGIN_CHART, messages.new_chart());
110 values.put(FIELD_PLUGIN_MAP, messages.new_map());
111 150
112 radio.setShowTitle(false); 151 radio.setShowTitle(false);
113 radio.setVertical(true); 152 radio.setVertical(true);
114 radio.setValueMap(values);
115 153
116 LinkedHashMap initial = new LinkedHashMap(); 154 setModules();
117 initial.put(FIELD_PLUGIN, FIELD_PLUGIN_WINFO); 155
156 /* LinkedHashMap initial = new LinkedHashMap(); */
157 /* initial.put(FIELD_PLUGIN, FIELD_PLUGIN_WINFO); */
118 158
119 form.setFields(radio); 159 form.setFields(radio);
120 form.setValues(initial); 160 /* form.setValues(initial); */
121 161
122 layout.addMember(label); 162 layout.addMember(label);
123 layout.addMember(form); 163 layout.addMember(form);
124 164
125 return layout; 165 return layout;

http://dive4elements.wald.intevation.org