Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/ModuleSelection.java@360e22afb98b |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 import com.google.gwt.user.client.rpc.AsyncCallback; | |
5 | |
6 import com.smartgwt.client.types.VerticalAlignment; | |
7 import com.smartgwt.client.util.SC; | |
8 import com.smartgwt.client.widgets.Canvas; | |
9 import com.smartgwt.client.widgets.Label; | |
10 import com.smartgwt.client.widgets.form.DynamicForm; | |
11 import com.smartgwt.client.widgets.form.fields.RadioGroupItem; | |
12 import com.smartgwt.client.widgets.layout.HLayout; | |
13 import com.smartgwt.client.widgets.layout.VLayout; | |
14 | |
15 import de.intevation.flys.client.client.Config; | |
16 import de.intevation.flys.client.client.FLYSConstants; | |
17 import de.intevation.flys.client.client.services.ModuleService; | |
18 import de.intevation.flys.client.client.services.ModuleServiceAsync; | |
19 import de.intevation.flys.client.shared.model.Data; | |
20 import de.intevation.flys.client.shared.model.DataItem; | |
21 import de.intevation.flys.client.shared.model.DataList; | |
22 import de.intevation.flys.client.shared.model.DefaultData; | |
23 import de.intevation.flys.client.shared.model.DefaultDataItem; | |
24 import de.intevation.flys.client.shared.model.Module; | |
25 | |
26 import java.util.LinkedHashMap; | |
27 | |
28 /** | |
29 * The ModuleSelection combines the river selection and the module selection in | |
30 * one widget. It will display a vertical splitted widget - the upper part will | |
31 * render checkboxes for each module, the lower one will display a combobox at | |
32 * the left and a map panel on the right to choose the river. | |
33 * | |
34 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
35 */ | |
36 public class ModuleSelection extends MapSelection { | |
37 | |
38 private static final long serialVersionUID = -5634831815175543328L; | |
39 | |
40 /** The message class that provides i18n strings.*/ | |
41 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | |
42 | |
43 /** The module checkboxes.*/ | |
44 protected RadioGroupItem radio; | |
45 | |
46 /** */ | |
47 protected Module[] modules; | |
48 | |
49 /** The ModuleService used to retrieve the available modules of a user.*/ | |
50 protected ModuleServiceAsync moduleService = GWT.create(ModuleService.class); | |
51 | |
52 | |
53 /** | |
54 * The default constructor. | |
55 */ | |
56 public ModuleSelection() { | |
57 readModules(); | |
58 } | |
59 | |
60 | |
61 /** | |
62 * This method returns a widget that renders the checkboxes for each module | |
63 * and the MapSelection that lets the user choose the river. | |
64 * | |
65 * @param data The provided rivers. | |
66 * | |
67 * @return the module selection combined with the river selection. | |
68 */ | |
69 @Override | |
70 public Canvas create(DataList data) { | |
71 GWT.log("ModuleSelection - create()"); | |
72 VLayout newLayout = new VLayout(); | |
73 newLayout.setMembersMargin(10); | |
74 newLayout.setAlign(VerticalAlignment.TOP); | |
75 Canvas moduleSelection = createWidget(); | |
76 | |
77 moduleSelection.setHeight(100); | |
78 newLayout.setHeight(70); | |
79 newLayout.addMember(moduleSelection); | |
80 | |
81 return newLayout; | |
82 } | |
83 | |
84 private void readModules() { | |
85 Config config = Config.getInstance(); | |
86 String locale = config.getLocale(); | |
87 | |
88 moduleService.list(locale, new AsyncCallback<Module[]>() { | |
89 @Override | |
90 public void onFailure(Throwable caught) { | |
91 GWT.log("Could not recieve a list of modules."); | |
92 SC.warn(MSG.getString(caught.getMessage())); | |
93 } | |
94 | |
95 @Override | |
96 public void onSuccess(Module[] newmodules) { | |
97 GWT.log("Retrieved " + newmodules.length + " modules."); | |
98 modules = newmodules; | |
99 setModules(); | |
100 } | |
101 }); | |
102 } | |
103 | |
104 private void setModules() { | |
105 LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); | |
106 | |
107 if (this.modules!= null) { | |
108 for(Module module : this.modules) { | |
109 values.put(module.getName(), module.getLocalizedName()); | |
110 if (module.isSelected()) { | |
111 GWT.log("Module " + module.getName() + " is selected."); | |
112 if (radio != null) { | |
113 radio.setDefaultValue(module.getName()); | |
114 GWT.log("Setting " + module.getName() + " as selected."); | |
115 } | |
116 } | |
117 } | |
118 } | |
119 if (radio != null) { | |
120 radio.setValueMap(values); | |
121 } | |
122 } | |
123 | |
124 /** | |
125 * Creates a widget that displays a checkbox for each module. | |
126 * | |
127 * @return a widget with checkboxes. | |
128 */ | |
129 protected Canvas createWidget() { | |
130 HLayout layout = new HLayout(); | |
131 | |
132 Label label = new Label(MESSAGES.module_selection()); | |
133 DynamicForm form = new DynamicForm(); | |
134 | |
135 radio = new RadioGroupItem("plugin"); | |
136 | |
137 label.setWidth(50); | |
138 label.setHeight(25); | |
139 | |
140 | |
141 radio.setShowTitle(false); | |
142 radio.setVertical(true); | |
143 | |
144 setModules(); | |
145 | |
146 form.setFields(radio); | |
147 | |
148 layout.addMember(label); | |
149 layout.addMember(form); | |
150 | |
151 return layout; | |
152 } | |
153 | |
154 | |
155 /** | |
156 * This method prepares the data of two widgets - the module selection and | |
157 * the river selection. The returning field will contain the Data that | |
158 * represents the module selection at first position, the second position | |
159 * stores the Data object that represents the river selection. | |
160 * | |
161 * @return the Data that was chosen in this widget. | |
162 */ | |
163 @Override | |
164 protected Data[] getData() { | |
165 | |
166 String module = radio.getValueAsString(); | |
167 | |
168 DataItem[] items = new DefaultDataItem[1]; | |
169 items[0] = new DefaultDataItem(module, module, module); | |
170 | |
171 Data data = new DefaultData("module", null, null, items); | |
172 | |
173 return new Data[] {data}; | |
174 } | |
175 } | |
176 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |