Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java @ 1515:298a4ce64c2e
Issue451.
Load and add all recommendations together in one async request using
the LoadArtifactService.
flys-client/trunk@3666 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 12 Jan 2012 16:06:55 +0000 |
parents | 685bce693617 |
children | 27a2a065a963 |
comparison
equal
deleted
inserted
replaced
1514:b6af10d5f3da | 1515:298a4ce64c2e |
---|---|
47 import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; | 47 import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; |
48 import de.intevation.flys.client.client.services.CreateCollectionService; | 48 import de.intevation.flys.client.client.services.CreateCollectionService; |
49 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; | 49 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; |
50 import de.intevation.flys.client.client.services.DescribeCollectionService; | 50 import de.intevation.flys.client.client.services.DescribeCollectionService; |
51 import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; | 51 import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; |
52 import de.intevation.flys.client.client.services.LoadArtifactService; | |
53 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; | |
52 | 54 |
53 | 55 |
54 /** | 56 /** |
55 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 57 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
56 */ | 58 */ |
77 GWT.create(DescribeCollectionService.class); | 79 GWT.create(DescribeCollectionService.class); |
78 | 80 |
79 protected CollectionAttributeServiceAsync updater = | 81 protected CollectionAttributeServiceAsync updater = |
80 GWT.create(CollectionAttributeService.class); | 82 GWT.create(CollectionAttributeService.class); |
81 | 83 |
84 /** The LoadArtifactService used to load recommendations*/ | |
85 protected LoadArtifactServiceAsync loadArtifactService = | |
86 GWT.create(LoadArtifactService.class); | |
87 | |
82 /** The message class that provides i18n strings. */ | 88 /** The message class that provides i18n strings. */ |
83 protected FLYSConstants messages = GWT.create(FLYSConstants.class); | 89 protected FLYSConstants messages = GWT.create(FLYSConstants.class); |
84 | 90 |
85 /** The FLYS instance used to call services. */ | 91 /** The FLYS instance used to call services. */ |
86 protected FLYS flys; | 92 protected FLYS flys; |
359 | 365 |
360 | 366 |
361 protected void artifactChanged() { | 367 protected void artifactChanged() { |
362 ArtifactDescription desc = getArtifact().getArtifactDescription(); | 368 ArtifactDescription desc = getArtifact().getArtifactDescription(); |
363 OutputMode[] outs = desc.getOutputModes(); | 369 OutputMode[] outs = desc.getOutputModes(); |
364 Recommendation[] recom = desc.getRecommendations(); | 370 final Recommendation[] recom = desc.getRecommendations(); |
365 | 371 |
366 Collection c = getCollection(); | 372 Collection c = getCollection(); |
367 | |
368 if (recom != null && collection != null) { | |
369 loadRecommendedArtifacts(recom); | |
370 } | |
371 | 373 |
372 if (c != null) { | 374 if (c != null) { |
373 Config config = Config.getInstance(); | 375 Config config = Config.getInstance(); |
374 String locale = config.getLocale(); | 376 String locale = config.getLocale(); |
375 | 377 |
381 } | 383 } |
382 | 384 |
383 | 385 |
384 public void onSuccess(Collection newCollection) { | 386 public void onSuccess(Collection newCollection) { |
385 GWT.log("Successfully DESCRIBED collection."); | 387 GWT.log("Successfully DESCRIBED collection."); |
386 boolean loaded = false; | 388 boolean loaded = true; |
387 List<Recommendation> r = newCollection.getRecommendations(); | 389 for (Recommendation r: recom) { |
388 for (Recommendation rec: r) { | 390 if(!newCollection.loadedRecommendation(r)) { |
389 loaded = newCollection.loadedRecommendation(rec); | 391 loaded = false; |
392 } | |
390 } | 393 } |
391 if (loaded) { | 394 if (!loaded) { |
392 setCollection(newCollection); | 395 loadRecommendedArtifacts(recom); |
393 } | 396 } |
394 } | 397 } |
395 } | 398 } |
396 ); | 399 ); |
397 } | 400 } |
573 destroy(); | 576 destroy(); |
574 } | 577 } |
575 } | 578 } |
576 | 579 |
577 | 580 |
578 public void addArtifactToCollection(final Artifact artifact) { | 581 public void addArtifactToCollection(Artifact artifact) { |
579 Config config = Config.getInstance(); | 582 Config config = Config.getInstance(); |
580 final String locale = config.getLocale(); | 583 final String locale = config.getLocale(); |
581 final Collection collection = getCollection(); | 584 final Collection collection = getCollection(); |
582 | |
583 artifactsQueue++; | |
584 | 585 |
585 addArtifactService.add( | 586 addArtifactService.add( |
586 collection, artifact, locale, | 587 collection, artifact, locale, |
587 new AsyncCallback<Collection>() { | 588 new AsyncCallback<Collection>() { |
588 public void onFailure(Throwable caught) { | 589 public void onFailure(Throwable caught) { |
589 GWT.log("An error occured while adding artifact."); | 590 GWT.log("An error occured while adding artifact."); |
590 artifactsQueue--; | |
591 SC.warn(messages.getString(caught.getMessage())); | 591 SC.warn(messages.getString(caught.getMessage())); |
592 } | 592 } |
593 | 593 |
594 public void onSuccess(Collection newCollection) { | 594 public void onSuccess(Collection newCollection) { |
595 GWT.log("Successfully added artifact."); | 595 GWT.log("Successfully added artifacts."); |
596 setCollection(newCollection); | 596 setCollection(newCollection); |
597 | |
598 artifactsQueue--; | |
599 addRecommendationsToCollection(); | |
600 recommendationQueue++; | |
601 } | 597 } |
602 } | 598 } |
603 ); | 599 ); |
604 } | 600 } |
605 | 601 |
622 } | 618 } |
623 | 619 |
624 public void onSuccess(Collection newCol) { | 620 public void onSuccess(Collection newCol) { |
625 GWT.log("Successfully saved recommendations."); | 621 GWT.log("Successfully saved recommendations."); |
626 newRecommendations.removeAllElements(); | 622 newRecommendations.removeAllElements(); |
627 recommendationQueue--; | 623 setCollection(newCol); |
628 if(recommendationQueue == 0) { | |
629 setCollection(newCol); | |
630 } | |
631 } | 624 } |
632 } | 625 } |
633 ); | 626 ); |
634 } | 627 } |
635 | 628 |
637 protected void loadRecommendedArtifacts(Recommendation[] recommendations) { | 630 protected void loadRecommendedArtifacts(Recommendation[] recommendations) { |
638 Config config = Config.getInstance(); | 631 Config config = Config.getInstance(); |
639 final String locale = config.getLocale(); | 632 final String locale = config.getLocale(); |
640 final Collection collection = getCollection(); | 633 final Collection collection = getCollection(); |
641 | 634 |
642 | |
643 Artifact masterArtifact = getArtifact(); | 635 Artifact masterArtifact = getArtifact(); |
644 | |
645 | 636 |
646 if (recommendations == null) { | 637 if (recommendations == null) { |
647 GWT.log("WARNING: Currently no recommendations."); | 638 GWT.log("WARNING: Currently no recommendations."); |
648 return; | 639 return; |
649 } | 640 } |
650 | 641 |
651 for (final Recommendation recommendation: recommendations) { | 642 for (final Recommendation recommendation: recommendations) { |
652 if (collection.loadedRecommendation(recommendation)) { | 643 if (collection.loadedRecommendation(recommendation)) { |
653 continue; | 644 continue; |
654 } | 645 } |
646 newRecommendations.push(recommendation); | |
655 | 647 |
656 // XXX: UGLY! If no reference artifact given use uuid of | 648 // XXX: UGLY! If no reference artifact given use uuid of |
657 // current artifact as reference. | 649 // current artifact as reference. |
658 if (recommendation.getMasterArtifact() == null) { | 650 if (recommendation.getMasterArtifact() == null) { |
659 recommendation.setMasterArtifact(masterArtifact.getUuid()); | 651 recommendation.setMasterArtifact(masterArtifact.getUuid()); |
660 } | 652 } |
661 | 653 |
662 final String factory = recommendation.getFactory(); | 654 } |
663 | 655 |
664 GWT.log("Load recommended artifact with factory: " + factory); | 656 loadArtifactService.loadMany( |
665 | 657 collection, |
666 createArtifactService.create( | 658 recommendations, |
667 locale, factory, recommendation, | 659 null, |
668 new AsyncCallback<Artifact>() { | 660 locale, |
669 public void onFailure(Throwable caught) { | 661 new AsyncCallback<Artifact[]>() { |
670 GWT.log("Error loading recommendations: " + | 662 public void onFailure(Throwable caught) { |
671 caught.getMessage()); | 663 GWT.log("Error loading recommendations: " + |
672 } | 664 caught.getMessage()); |
673 | 665 } |
674 public void onSuccess(Artifact artifact) { | 666 |
675 GWT.log("Created new artifact: " + artifact.getUuid()); | 667 public void onSuccess(Artifact[] artifacts) { |
676 addArtifactToCollection(artifact); | 668 GWT.log("Loaded artifacts: " + artifacts.length); |
677 newRecommendations.push(recommendation); | 669 addRecommendationsToCollection(); |
678 } | 670 } |
679 }); | 671 }); |
680 } | |
681 } | 672 } |
682 | 673 |
683 | 674 |
684 public void registerTabHandler(TabSelectedHandler tse) { | 675 public void registerTabHandler(TabSelectedHandler tse) { |
685 tabs.addTabSelectedHandler(tse); | 676 tabs.addTabSelectedHandler(tse); |