comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java @ 73:39210a74db07

Moved parameterization specific code from CollectionView to ParameterList. flys-client/trunk@1576 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 28 Mar 2011 06:48:44 +0000
parents 9b726350ab07
children 4784ca718476
comparison
equal deleted inserted replaced
72:9b726350ab07 73:39210a74db07
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.List; 4 import java.util.List;
5 5
6 import com.google.gwt.core.client.GWT; 6 import com.google.gwt.core.client.GWT;
7 import com.google.gwt.user.client.rpc.AsyncCallback;
7 8
8 import com.smartgwt.client.types.VerticalAlignment; 9 import com.smartgwt.client.types.VerticalAlignment;
9 import com.smartgwt.client.widgets.Canvas; 10 import com.smartgwt.client.widgets.Canvas;
10 import com.smartgwt.client.widgets.layout.HLayout; 11 import com.smartgwt.client.widgets.layout.HLayout;
11 import com.smartgwt.client.widgets.layout.VLayout; 12 import com.smartgwt.client.widgets.layout.VLayout;
12 13
13 import de.intevation.flys.client.shared.model.Artifact; 14 import de.intevation.flys.client.shared.model.Artifact;
14 import de.intevation.flys.client.shared.model.ArtifactDescription; 15 import de.intevation.flys.client.shared.model.ArtifactDescription;
15 import de.intevation.flys.client.shared.model.Data; 16 import de.intevation.flys.client.shared.model.Data;
17 import de.intevation.flys.client.shared.model.DataItem;
16 import de.intevation.flys.client.shared.model.DataList; 18 import de.intevation.flys.client.shared.model.DataList;
19 import de.intevation.flys.client.shared.model.DefaultData;
20 import de.intevation.flys.client.shared.model.DefaultDataItem;
21 import de.intevation.flys.client.shared.model.River;
22 import de.intevation.flys.client.client.Config;
23 import de.intevation.flys.client.client.FLYS;
24 import de.intevation.flys.client.client.FLYSMessages;
25 import de.intevation.flys.client.client.event.HasParameterChangeHandler;
17 import de.intevation.flys.client.client.event.HasStepBackHandlers; 26 import de.intevation.flys.client.client.event.HasStepBackHandlers;
18 import de.intevation.flys.client.client.event.HasStepForwardHandlers; 27 import de.intevation.flys.client.client.event.HasStepForwardHandlers;
19 import de.intevation.flys.client.client.event.ParameterChangeEvent; 28 import de.intevation.flys.client.client.event.ParameterChangeEvent;
20 import de.intevation.flys.client.client.event.ParameterChangeHandler; 29 import de.intevation.flys.client.client.event.ParameterChangeHandler;
21 import de.intevation.flys.client.client.event.StepBackEvent; 30 import de.intevation.flys.client.client.event.StepBackEvent;
22 import de.intevation.flys.client.client.event.StepBackHandler; 31 import de.intevation.flys.client.client.event.StepBackHandler;
32 import de.intevation.flys.client.client.event.StepForwardEvent;
33 import de.intevation.flys.client.client.event.StepForwardHandler;
34 import de.intevation.flys.client.client.services.AdvanceService;
35 import de.intevation.flys.client.client.services.AdvanceServiceAsync;
36 import de.intevation.flys.client.client.services.ArtifactService;
37 import de.intevation.flys.client.client.services.ArtifactServiceAsync;
38 import de.intevation.flys.client.client.services.StepForwardService;
39 import de.intevation.flys.client.client.services.StepForwardServiceAsync;
23 40
24 41
25 public class ParameterList 42 public class ParameterList
26 extends VLayout 43 extends HLayout
27 implements StepBackHandler, ParameterChangeHandler 44 implements StepBackHandler, StepForwardHandler, ParameterChangeHandler,
45 HasParameterChangeHandler
28 { 46 {
47 /** The message class that provides i18n strings.*/
48 protected FLYSMessages MSG = GWT.create(FLYSMessages.class);
49
50 /** The ArtifactService used to communicate with the Artifact server. */
51 protected ArtifactServiceAsync artifactService =
52 GWT.create(ArtifactService.class);
53
54 /** The StepForwardService used to put data into an existing artifact. */
55 protected StepForwardServiceAsync forwardService =
56 GWT.create(StepForwardService.class);
57
58 /** The StepForwardService used to put data into an existing artifact. */
59 protected AdvanceServiceAsync advanceService =
60 GWT.create(AdvanceService.class);
61
62
63 /** The list of ParameterizationChangeHandler.*/
64 protected List<ParameterChangeHandler> parameterHandlers;
65
66 protected FLYS flys;
67
29 protected CollectionView cView; 68 protected CollectionView cView;
69
70 protected Artifact artifact;
30 71
31 protected List<DataList> old; 72 protected List<DataList> old;
32 protected DataList current; 73 protected DataList current;
33 74
34 protected UIProvider uiProvider; 75 protected UIProvider uiProvider;
35 76
36 protected VLayout oldItems; 77 protected VLayout oldItems;
37 protected VLayout currentItems; 78 protected VLayout currentItems;
38 79
39 public ParameterList(CollectionView cView) { 80 public ParameterList(FLYS flys, CollectionView cView) {
40 this.cView = cView; 81 this.cView = cView;
41 old = new ArrayList<DataList>(); 82 this.flys = flys;
42 oldItems = new VLayout(); 83
43 currentItems = new VLayout(); 84 parameterHandlers = new ArrayList<ParameterChangeHandler>();
85 old = new ArrayList<DataList>();
86 oldItems = new VLayout();
87 currentItems = new VLayout();
44 88
45 init(); 89 init();
46 } 90 }
47 91
48 92
49 protected void init() { 93 protected void init() {
50 setWidth(300); 94 setMembersMargin(20);
95
96 VLayout left = new VLayout();
51 97
52 oldItems.setHeight(20); 98 oldItems.setHeight(20);
53 oldItems.setMembersMargin(10); 99 oldItems.setMembersMargin(10);
54 currentItems.setHeight("*"); 100 currentItems.setHeight("*");
55 currentItems.setAlign(VerticalAlignment.TOP); 101 currentItems.setAlign(VerticalAlignment.TOP);
56 102
57 setMembersMargin(20); 103 left.setMembersMargin(20);
58 104 left.setWidth(300);
59 addMember(oldItems); 105
60 addMember(currentItems); 106 left.addMember(oldItems);
107 left.addMember(currentItems);
108
109 // This canvas is used to render helper widgets
110 Canvas right = new Canvas();
111
112 addMember(left);
113 addMember(right);
114
115 Canvas moduleSelection = renderNew();
116 moduleSelection.setLayoutAlign(VerticalAlignment.TOP);
117 currentItems.addMember(moduleSelection);
118 }
119
120
121 protected void setArtifact(Artifact artifact) {
122 Artifact tmp = this.artifact;
123 this.artifact = artifact;
124
125 fireParameterChangeEvent(tmp, this.artifact);
126 }
127
128
129 /**
130 * This method registers a new ParameterChangeHandler.
131 *
132 * @param handler The new ParameterChangeHandler.
133 */
134 public void addParameterChangeHandler(ParameterChangeHandler handler) {
135 if (handler != null) {
136 parameterHandlers.add(handler);
137 }
138 }
139
140
141 /**
142 * This method calls the <code>onParameterChange()</code> method of all
143 * registered ParameterChangeHandler.
144 */
145 protected void fireParameterChangeEvent(Artifact old, Artifact newArt) {
146 for (ParameterChangeHandler handler: parameterHandlers) {
147 handler.onParameterChange(new ParameterChangeEvent(old, newArt));
148 }
149 }
150
151
152 /**
153 * This method creates a Canvas displaying the plugins of FLYS combined with
154 * a widget to select a river.
155 *
156 * @return a Canvas that displays the supported plugins and rivers of FLYS.
157 */
158 protected Canvas renderNew() {
159 River[] rivers = flys.getRivers();
160 DataItem[] items = new DataItem[rivers.length];
161
162 int i = 0;
163 for (River river: rivers) {
164 String name = river.getName();
165 items[i++] = new DefaultDataItem(name, null, name);
166 }
167
168 Data data = new DefaultData(
169 "river",
170 MSG.river_selection(),
171 null,
172 items);
173
174 ModuleSelection widget = new ModuleSelection();
175 HasStepForwardHandlers handler = (HasStepForwardHandlers) widget;
176
177 handler.addStepForwardHandler(new StepForwardHandler() {
178 public void onStepForward(StepForwardEvent event) {
179 Data[] data = event.getData();
180
181 DataItem[] moduleItems = data[0].getItems();
182 DataItem[] riversItems = data[1].getItems();
183
184 String module = moduleItems[0].getStringValue();
185 String river = riversItems[0].getStringValue();
186
187 final String serverUrl = Config.getInstance().getServerUrl();
188 final Data[] feedData = new Data[] { data[1] };
189 artifactService.create(
190 serverUrl, module.toLowerCase(),
191 new AsyncCallback<Artifact>() {
192 public void onFailure(Throwable caught) {
193 GWT.log("Could not create the new artifact.");
194 GWT.log(caught.getMessage());
195 }
196
197 public void onSuccess(Artifact artifact) {
198 GWT.log("Successfully created a new artifact.");
199
200 forwardService.go(serverUrl, artifact, feedData,
201 new AsyncCallback<Artifact>() {
202 public void onFailure(Throwable caught) {
203 GWT.log("Could not feed the artifact.");
204 GWT.log(caught.getMessage());
205 }
206
207 public void onSuccess(Artifact artifact) {
208 GWT.log("Successfully feed the artifact.");
209 setArtifact(artifact);
210 }
211 });
212 }
213 });
214 }
215 });
216
217 DataList list = new DataList();
218 list.add(data);
219
220 return widget.create(list);
61 } 221 }
62 222
63 223
64 protected void clearOldData() { 224 protected void clearOldData() {
65 old.clear(); 225 old.clear();
122 h.setAlign(VerticalAlignment.TOP); 282 h.setAlign(VerticalAlignment.TOP);
123 h.setHeight(20); 283 h.setHeight(20);
124 284
125 String provider = dataList.getUIProvider(); 285 String provider = dataList.getUIProvider();
126 UIProvider uiprovider = UIProviderFactory.getProvider(provider); 286 UIProvider uiprovider = UIProviderFactory.getProvider(provider);
127 ((HasStepBackHandlers) uiprovider).addStepBackHandler(cView);
128 ((HasStepBackHandlers) uiprovider).addStepBackHandler(this); 287 ((HasStepBackHandlers) uiprovider).addStepBackHandler(this);
129 288
130 oldItems.addMember(uiprovider.createOld(dataList)); 289 oldItems.addMember(uiprovider.createOld(dataList));
131 } 290 }
132 291
155 } 314 }
156 } 315 }
157 316
158 317
159 /** 318 /**
319 * This method is called if the user clicks on the 'next' button to advance
320 * to the next state.
321 *
322 * @param event The StepForwardEvent.
323 */
324 public void onStepForward(StepForwardEvent event) {
325 GWT.log("CollectionView - onStepForward()");
326 String serverUrl = Config.getInstance().getServerUrl();
327
328 forwardService.go(serverUrl, artifact, event.getData(),
329 new AsyncCallback<Artifact>() {
330 public void onFailure(Throwable caught) {
331 GWT.log("Could not feed the artifact.");
332 GWT.log(caught.getMessage());
333 }
334
335 public void onSuccess(Artifact artifact) {
336 GWT.log("Successfully feed the artifact.");
337 setArtifact(artifact);
338 }
339 });
340 }
341
342
343 /**
160 * This method is used to remove all old items from this list after the user 344 * This method is used to remove all old items from this list after the user
161 * has clicked the step back button. 345 * has clicked the step back button.
162 * 346 *
163 * @param e The StepBackEvent. 347 * @param e The StepBackEvent that holds the identifier of the target state.
164 */ 348 */
165 public void onStepBack(StepBackEvent e) { 349 public void onStepBack(StepBackEvent e) {
166 old.clear(); 350 final String target = e.getTarget();
167 oldItems.removeMembers(oldItems.getMembers()); 351 final String serverUrl = Config.getInstance().getServerUrl();
352
353 advanceService.advance(serverUrl, artifact, target,
354 new AsyncCallback<Artifact>() {
355 public void onFailure(Throwable caught) {
356 GWT.log("Could not go back to '" + target + "'");
357 GWT.log(caught.getMessage());
358 }
359
360 public void onSuccess(Artifact artifact) {
361 GWT.log("Successfully step back to '" + target + "'");
362
363 old.clear();
364 oldItems.removeMembers(oldItems.getMembers());
365
366 setArtifact(artifact);
367 }
368 }
369 );
168 } 370 }
169 371
170 372
171 /** 373 /**
172 * Implements the onCollectionChange() method to do update the GUI after the 374 * Implements the onCollectionChange() method to do update the GUI after the
184 if (currentData != null) { 386 if (currentData != null) {
185 // the user has to enter some attributes 387 // the user has to enter some attributes
186 String uiProvider = currentData.getUIProvider(); 388 String uiProvider = currentData.getUIProvider();
187 UIProvider provider = UIProviderFactory.getProvider(uiProvider); 389 UIProvider provider = UIProviderFactory.getProvider(uiProvider);
188 390
189 ((HasStepForwardHandlers) provider).addStepForwardHandler(cView); 391 ((HasStepForwardHandlers) provider).addStepForwardHandler(this);
190 ((HasStepBackHandlers) provider).addStepBackHandler(cView); 392 ((HasStepBackHandlers) provider).addStepBackHandler(this);
191 393
192 setCurrentData(currentData, provider); 394 setCurrentData(currentData, provider);
193 } 395 }
194 else { 396 else {
195 // we have reached a final state with no more user input 397 // we have reached a final state with no more user input

http://dive4elements.wald.intevation.org