comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java @ 803:653ae84533e7

Read/create recommended Artifacts and add them to the current Collection. flys-client/trunk@2350 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 18 Jul 2011 09:52:16 +0000
parents cd8603aaa730
children 6f65e70fa11d
comparison
equal deleted inserted replaced
802:d45ad7fd3027 803:653ae84533e7
34 import de.intevation.flys.client.client.event.CollectionChangeHandler; 34 import de.intevation.flys.client.client.event.CollectionChangeHandler;
35 import de.intevation.flys.client.client.event.OutputModesChangeEvent; 35 import de.intevation.flys.client.client.event.OutputModesChangeEvent;
36 import de.intevation.flys.client.client.event.OutputModesChangeHandler; 36 import de.intevation.flys.client.client.event.OutputModesChangeHandler;
37 import de.intevation.flys.client.client.event.ParameterChangeEvent; 37 import de.intevation.flys.client.client.event.ParameterChangeEvent;
38 import de.intevation.flys.client.client.event.ParameterChangeHandler; 38 import de.intevation.flys.client.client.event.ParameterChangeHandler;
39 import de.intevation.flys.client.client.services.ArtifactService;
40 import de.intevation.flys.client.client.services.ArtifactServiceAsync;
39 import de.intevation.flys.client.client.services.AddArtifactService; 41 import de.intevation.flys.client.client.services.AddArtifactService;
40 import de.intevation.flys.client.client.services.AddArtifactServiceAsync; 42 import de.intevation.flys.client.client.services.AddArtifactServiceAsync;
41 import de.intevation.flys.client.client.services.CreateCollectionService; 43 import de.intevation.flys.client.client.services.CreateCollectionService;
42 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; 44 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync;
43 import de.intevation.flys.client.client.services.DescribeCollectionService; 45 import de.intevation.flys.client.client.services.DescribeCollectionService;
55 { 57 {
56 /** The ArtifactService used to communicate with the Artifact server. */ 58 /** The ArtifactService used to communicate with the Artifact server. */
57 protected CreateCollectionServiceAsync createCollectionService = 59 protected CreateCollectionServiceAsync createCollectionService =
58 GWT.create(CreateCollectionService.class); 60 GWT.create(CreateCollectionService.class);
59 61
62 /** The ArtifactService used to communicate with the Artifact server. */
63 protected ArtifactServiceAsync createArtifactService =
64 GWT.create(ArtifactService.class);
65
60 /** The AddArtifactService used to add an artifact to a collection. */ 66 /** The AddArtifactService used to add an artifact to a collection. */
61 protected AddArtifactServiceAsync addArtifactService = 67 protected AddArtifactServiceAsync addArtifactService =
62 GWT.create(AddArtifactService.class); 68 GWT.create(AddArtifactService.class);
63 69
64 /** The DescribeCollectionService used to update the existing collection. */ 70 /** The DescribeCollectionService used to update the existing collection. */
198 } 204 }
199 205
200 public void onSuccess(Collection collection) { 206 public void onSuccess(Collection collection) {
201 GWT.log("Successfully created a new collection."); 207 GWT.log("Successfully created a new collection.");
202 208
209 setCollection(collection);
210
203 Artifact artifact = getArtifact(); 211 Artifact artifact = getArtifact();
204 addArtifactService.add(collection, artifact, url, locale, 212 addArtifactToCollection(artifact);
205 new AsyncCallback<Collection>() {
206
207 public void onFailure(Throwable caught) {
208 GWT.log("An error occured while adding artifact.");
209 SC.warn(messages.getString(caught.getMessage()));
210 }
211
212 public void onSuccess(Collection newCollection) {
213 GWT.log("Successfully added artifact.");
214 setCollection(newCollection);
215 }
216 }
217 );
218 } 213 }
219 }); 214 });
220 } 215 }
221 216
222 217
316 GWT.log("CollectionView.onParameterChange"); 311 GWT.log("CollectionView.onParameterChange");
317 312
318 Artifact art = event.getNewValue(); 313 Artifact art = event.getNewValue();
319 ArtifactDescription desc = art.getArtifactDescription(); 314 ArtifactDescription desc = art.getArtifactDescription();
320 OutputMode[] outs = desc.getOutputModes(); 315 OutputMode[] outs = desc.getOutputModes();
316 String[] recommended = desc.getRecommendedArtifacts();
317
318 if (recommended != null) {
319 loadRecommendedArtifacts(recommended);
320 }
321 321
322 setArtifact(art); 322 setArtifact(art);
323 323
324 Collection c = getCollection(); 324 Collection c = getCollection();
325 325
509 else { 509 else {
510 hide(); 510 hide();
511 destroy(); 511 destroy();
512 } 512 }
513 } 513 }
514
515
516 protected void addArtifactToCollection(final Artifact artifact) {
517 Config config = Config.getInstance();
518 final String url = config.getServerUrl();
519 final String locale = config.getLocale();
520 final Collection collection = getCollection();
521
522 addArtifactService.add(
523 collection, artifact, url, locale,
524 new AsyncCallback<Collection>() {
525 public void onFailure(Throwable caught) {
526 GWT.log("An error occured while adding artifact.");
527 SC.warn(messages.getString(caught.getMessage()));
528 }
529
530 public void onSuccess(Collection newCollection) {
531 GWT.log("Successfully added artifact.");
532 setCollection(newCollection);
533 }
534 }
535 );
536 }
537
538
539 protected void loadRecommendedArtifacts(String[] factories) {
540 Config config = Config.getInstance();
541 final String url = config.getServerUrl();
542 final String locale = config.getLocale();
543 final Collection collection = getCollection();
544 final Artifact master = getArtifact();
545
546 for (String factory: factories) {
547 GWT.log("Load recommended artifact: " + factory);
548
549 createArtifactService.create(url, locale, factory, master.getUuid(),
550 new AsyncCallback<Artifact>() {
551
552 public void onFailure(Throwable caught) {
553 GWT.log("Error loading recommendations: " +
554 caught.getMessage());
555 }
556
557 public void onSuccess(Artifact artifact) {
558 GWT.log("Created new artifact: " + artifact.getUuid());
559 addArtifactToCollection(artifact);
560 }
561 });
562 }
563 }
514 } 564 }
515 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 565 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org