Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java @ 526:96e60e0a4345
Added a service stub to update/modify the attribute of a collection (used in the theme control panel).
flys-client/trunk@2005 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 25 May 2011 14:58:42 +0000 |
parents | ba238f917b94 |
children | 902609b5cc79 |
comparison
equal
deleted
inserted
replaced
525:fc994da131f9 | 526:96e60e0a4345 |
---|---|
1 package de.intevation.flys.client.client.ui.chart; | 1 package de.intevation.flys.client.client.ui.chart; |
2 | 2 |
3 import java.util.List; | |
4 | |
5 import com.google.gwt.core.client.GWT; | 3 import com.google.gwt.core.client.GWT; |
4 import com.google.gwt.user.client.rpc.AsyncCallback; | |
6 | 5 |
7 import com.smartgwt.client.types.ListGridFieldType; | 6 import com.smartgwt.client.types.ListGridFieldType; |
7 import com.smartgwt.client.util.SC; | |
8 import com.smartgwt.client.widgets.Canvas; | 8 import com.smartgwt.client.widgets.Canvas; |
9 import com.smartgwt.client.widgets.grid.events.EditCompleteEvent; | 9 import com.smartgwt.client.widgets.grid.events.EditCompleteEvent; |
10 import com.smartgwt.client.widgets.grid.events.EditCompleteHandler; | 10 import com.smartgwt.client.widgets.grid.events.EditCompleteHandler; |
11 import com.smartgwt.client.widgets.grid.ListGrid; | 11 import com.smartgwt.client.widgets.grid.ListGrid; |
12 import com.smartgwt.client.widgets.grid.ListGridField; | 12 import com.smartgwt.client.widgets.grid.ListGridField; |
13 import com.smartgwt.client.widgets.grid.ListGridRecord; | 13 import com.smartgwt.client.widgets.grid.ListGridRecord; |
14 import com.smartgwt.client.widgets.layout.VLayout; | 14 import com.smartgwt.client.widgets.layout.VLayout; |
15 | 15 |
16 import de.intevation.flys.client.shared.model.Collection; | 16 import de.intevation.flys.client.shared.model.Collection; |
17 import de.intevation.flys.client.shared.model.Facet; | |
18 import de.intevation.flys.client.shared.model.FacetRecord; | 17 import de.intevation.flys.client.shared.model.FacetRecord; |
19 import de.intevation.flys.client.shared.model.OutputMode; | 18 import de.intevation.flys.client.shared.model.OutputMode; |
20 import de.intevation.flys.client.shared.model.Theme; | 19 import de.intevation.flys.client.shared.model.Theme; |
21 import de.intevation.flys.client.shared.model.ThemeList; | 20 import de.intevation.flys.client.shared.model.ThemeList; |
22 | 21 |
22 import de.intevation.flys.client.client.Config; | |
23 import de.intevation.flys.client.client.FLYSConstants; | 23 import de.intevation.flys.client.client.FLYSConstants; |
24 import de.intevation.flys.client.client.services.CollectionAttributeService; | |
25 import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; | |
24 | 26 |
25 | 27 |
26 /** | 28 /** |
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
28 */ | 30 */ |
29 public class ChartThemePanel extends Canvas implements EditCompleteHandler { | 31 public class ChartThemePanel extends Canvas implements EditCompleteHandler { |
30 | 32 |
31 /** The interface that provides i18n messages. */ | 33 /** The interface that provides i18n messages. */ |
32 private FLYSConstants MSG = GWT.create(FLYSConstants.class); | 34 private FLYSConstants MSG = GWT.create(FLYSConstants.class); |
35 | |
36 | |
37 /** The service that is used to modify collection attributes.*/ | |
38 protected CollectionAttributeServiceAsync updater = | |
39 GWT.create(CollectionAttributeService.class); | |
40 | |
33 | 41 |
34 public static final String GRID_FIELD_ACTIVE = "active"; | 42 public static final String GRID_FIELD_ACTIVE = "active"; |
35 public static final String GRID_FIELD_NAME = "name"; | 43 public static final String GRID_FIELD_NAME = "name"; |
36 | 44 |
37 | 45 |
97 list.setFields(active, name); | 105 list.setFields(active, name); |
98 } | 106 } |
99 | 107 |
100 | 108 |
101 /** | 109 /** |
110 * Replace the current collection with a new one. <b>NOTE: this operation | |
111 * triggers updateGrid() which modifies the themes in the grid.</b> | |
112 * | |
113 * @param collection The new collection object. | |
114 */ | |
115 protected void setCollection(Collection collection) { | |
116 this.collection = collection; | |
117 | |
118 updateGrid(); | |
119 } | |
120 | |
121 | |
122 /** | |
102 * A method that removes all records from theme grid. | 123 * A method that removes all records from theme grid. |
103 */ | 124 */ |
104 protected void clearGrid() { | 125 protected void clearGrid() { |
105 ListGridRecord[] records = list.getRecords(); | 126 ListGridRecord[] records = list.getRecords(); |
106 | 127 |
117 /** | 138 /** |
118 * This method is used to clear the current theme grid and add new updated | 139 * This method is used to clear the current theme grid and add new updated |
119 * data. | 140 * data. |
120 */ | 141 */ |
121 protected void updateGrid() { | 142 protected void updateGrid() { |
143 GWT.log("ChartThemePanel.updateGrid"); | |
144 | |
122 clearGrid(); | 145 clearGrid(); |
123 | 146 |
124 ThemeList themeList = collection.getThemeList(mode.getName()); | 147 ThemeList themeList = collection.getThemeList(mode.getName()); |
125 | 148 |
126 if (themeList == null) { | 149 if (themeList == null) { |
151 GWT.log("Edited record."); | 174 GWT.log("Edited record."); |
152 | 175 |
153 int row = event.getRowNum(); | 176 int row = event.getRowNum(); |
154 FacetRecord rec = (FacetRecord) list.getRecord(row); | 177 FacetRecord rec = (FacetRecord) list.getRecord(row); |
155 | 178 |
156 // TODO Save modified facets | 179 updateThemeList(rec.getTheme()); |
180 } | |
181 | |
182 | |
183 /** | |
184 * Update the theme list of the current collection with a modified theme. If | |
185 * a theme is really modified, the CollectionAttributeService is triggered | |
186 * to save the changes to the artifact server. | |
187 * | |
188 * @param theme The modified theme. | |
189 */ | |
190 protected void updateThemeList(Theme theme) { | |
191 GWT.log("Update theme: " + theme.getFacet()); | |
192 | |
193 ThemeList themeList = collection.getThemeList(mode.getName()); | |
194 | |
195 String a = theme.getArtifact(); | |
196 String f = theme.getFacet(); | |
197 | |
198 int num = themeList != null ? themeList.getThemeCount() : 0; | |
199 | |
200 boolean updateRequired = false; | |
201 | |
202 for (int i = 1; i <= num; i++) { | |
203 Theme old = themeList.getThemeAt(i); | |
204 | |
205 if (f.equals(old.getFacet()) && a.equals(old.getArtifact())) { | |
206 themeList.removeTheme(old); | |
207 themeList.addTheme(theme); | |
208 | |
209 updateRequired = true; | |
210 | |
211 break; | |
212 } | |
213 } | |
214 | |
215 if (updateRequired) { | |
216 updateCollection(); | |
217 } | |
218 } | |
219 | |
220 | |
221 /** | |
222 * This method triggers the CollectionAttributeService. Based on the current | |
223 * collectin settings, the attribute of the collection is modified or not. | |
224 * But in every case, we will get a new collection object - which might be | |
225 * the same as the current one. | |
226 */ | |
227 public void updateCollection() { | |
228 final Config config = Config.getInstance(); | |
229 final String url = config.getServerUrl(); | |
230 final String loc = config.getLocale(); | |
231 | |
232 GWT.log("ChartThemePanel.updateCollection via RPC now"); | |
233 | |
234 updater.update(collection, url, loc, new AsyncCallback<Collection>() { | |
235 public void onFailure(Throwable caught) { | |
236 GWT.log("Could not update collection attributes."); | |
237 SC.warn(MSG.getString(caught.getMessage())); | |
238 } | |
239 | |
240 | |
241 public void onSuccess(Collection collection) { | |
242 setCollection(collection); | |
243 } | |
244 }); | |
157 } | 245 } |
158 } | 246 } |
159 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 247 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |