comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java @ 809:e9337488bac3

The Collection now knows its already loaded recommendations - the CollectionView will not load recommendations that have already been loaded before. flys-client/trunk@2397 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 22 Jul 2011 12:23:36 +0000
parents 6f65e70fa11d
children 8fa303586f14
comparison
equal deleted inserted replaced
808:3187b268b311 809:e9337488bac3
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.HashMap; 4 import java.util.HashMap;
5 import java.util.List; 5 import java.util.List;
6 import java.util.Map; 6 import java.util.Map;
7 import java.util.Set; 7 import java.util.Set;
8 import java.util.Stack;
8 9
9 import com.google.gwt.core.client.GWT; 10 import com.google.gwt.core.client.GWT;
10 import com.google.gwt.user.client.rpc.AsyncCallback; 11 import com.google.gwt.user.client.rpc.AsyncCallback;
11 12
12 import com.smartgwt.client.util.SC; 13 import com.smartgwt.client.util.SC;
39 import de.intevation.flys.client.client.event.ParameterChangeHandler; 40 import de.intevation.flys.client.client.event.ParameterChangeHandler;
40 import de.intevation.flys.client.client.services.ArtifactService; 41 import de.intevation.flys.client.client.services.ArtifactService;
41 import de.intevation.flys.client.client.services.ArtifactServiceAsync; 42 import de.intevation.flys.client.client.services.ArtifactServiceAsync;
42 import de.intevation.flys.client.client.services.AddArtifactService; 43 import de.intevation.flys.client.client.services.AddArtifactService;
43 import de.intevation.flys.client.client.services.AddArtifactServiceAsync; 44 import de.intevation.flys.client.client.services.AddArtifactServiceAsync;
45 import de.intevation.flys.client.client.services.CollectionAttributeService;
46 import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync;
44 import de.intevation.flys.client.client.services.CreateCollectionService; 47 import de.intevation.flys.client.client.services.CreateCollectionService;
45 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; 48 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync;
46 import de.intevation.flys.client.client.services.DescribeCollectionService; 49 import de.intevation.flys.client.client.services.DescribeCollectionService;
47 import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; 50 import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync;
48 51
70 73
71 /** The DescribeCollectionService used to update the existing collection. */ 74 /** The DescribeCollectionService used to update the existing collection. */
72 protected DescribeCollectionServiceAsync describeCollectionService = 75 protected DescribeCollectionServiceAsync describeCollectionService =
73 GWT.create(DescribeCollectionService.class); 76 GWT.create(DescribeCollectionService.class);
74 77
78 protected CollectionAttributeServiceAsync updater =
79 GWT.create(CollectionAttributeService.class);
80
75 /** The message class that provides i18n strings.*/ 81 /** The message class that provides i18n strings.*/
76 protected FLYSConstants messages = GWT.create(FLYSConstants.class); 82 protected FLYSConstants messages = GWT.create(FLYSConstants.class);
77 83
78 /** The FLYS instance used to call services.*/ 84 /** The FLYS instance used to call services.*/
79 protected FLYS flys; 85 protected FLYS flys;
98 /** The output tab.*/ 104 /** The output tab.*/
99 protected Map<String, OutputTab> outputTabs; 105 protected Map<String, OutputTab> outputTabs;
100 106
101 /** The layout.*/ 107 /** The layout.*/
102 protected Layout layout; 108 protected Layout layout;
109
110 protected int artifactsQueue;
111 protected Stack<Recommendation> newRecommendations;
103 112
104 113
105 /** 114 /**
106 * This constructor creates a new CollectionView that is used to display the 115 * This constructor creates a new CollectionView that is used to display the
107 * <i>collection</i>. 116 * <i>collection</i>.
115 this.handlers = new ArrayList<CollectionChangeHandler>(); 124 this.handlers = new ArrayList<CollectionChangeHandler>();
116 this.outHandlers = new ArrayList<OutputModesChangeHandler>(); 125 this.outHandlers = new ArrayList<OutputModesChangeHandler>();
117 this.layout = new VLayout(); 126 this.layout = new VLayout();
118 this.parameterList = new ParameterList( 127 this.parameterList = new ParameterList(
119 flys, this, messages.new_project()); 128 flys, this, messages.new_project());
129 this.artifactsQueue = 0;
130 this.newRecommendations = new Stack<Recommendation>();
120 131
121 addCollectionChangeHandler(this); 132 addCollectionChangeHandler(this);
122 addCollectionChangeHandler(parameterList); 133 addCollectionChangeHandler(parameterList);
123 addCollectionChangeHandler(flys); 134 addCollectionChangeHandler(flys);
124 addOutputModesChangeHandler(this); 135 addOutputModesChangeHandler(this);
141 this.parameterList = new ParameterList( 152 this.parameterList = new ParameterList(
142 flys, 153 flys,
143 this, 154 this,
144 messages.getString(artifact.getName()), 155 messages.getString(artifact.getName()),
145 artifact); 156 artifact);
157 this.artifactsQueue = 0;
158 this.newRecommendations = new Stack<Recommendation>();
146 159
147 addCollectionChangeHandler(this); 160 addCollectionChangeHandler(this);
148 addCollectionChangeHandler(parameterList); 161 addCollectionChangeHandler(parameterList);
149 addCollectionChangeHandler(flys); 162 addCollectionChangeHandler(flys);
150 addOutputModesChangeHandler(this); 163 addOutputModesChangeHandler(this);
380 fireCollectionChangeEvent(tmp, this.collection); 393 fireCollectionChangeEvent(tmp, this.collection);
381 } 394 }
382 395
383 396
384 public void onCollectionChange(CollectionChangeEvent event) { 397 public void onCollectionChange(CollectionChangeEvent event) {
398 if (artifactsQueue > 0) {
399 GWT.log("Do not update UI because we are still loading Artifacts.");
400 return;
401 }
402
385 Collection newCol = event.getNewValue(); 403 Collection newCol = event.getNewValue();
386 404
387 Map<String, OutputMode> outs = newCol.getOutputModes(); 405 Map<String, OutputMode> outs = newCol.getOutputModes();
388 406
389 Set<String> keys = outs.keySet(); 407 Set<String> keys = outs.keySet();
518 Config config = Config.getInstance(); 536 Config config = Config.getInstance();
519 final String url = config.getServerUrl(); 537 final String url = config.getServerUrl();
520 final String locale = config.getLocale(); 538 final String locale = config.getLocale();
521 final Collection collection = getCollection(); 539 final Collection collection = getCollection();
522 540
541 artifactsQueue++;
542
523 addArtifactService.add( 543 addArtifactService.add(
524 collection, artifact, url, locale, 544 collection, artifact, url, locale,
525 new AsyncCallback<Collection>() { 545 new AsyncCallback<Collection>() {
526 public void onFailure(Throwable caught) { 546 public void onFailure(Throwable caught) {
527 GWT.log("An error occured while adding artifact."); 547 GWT.log("An error occured while adding artifact.");
548 artifactsQueue--;
528 SC.warn(messages.getString(caught.getMessage())); 549 SC.warn(messages.getString(caught.getMessage()));
529 } 550 }
530 551
531 public void onSuccess(Collection newCollection) { 552 public void onSuccess(Collection newCollection) {
532 GWT.log("Successfully added artifact."); 553 GWT.log("Successfully added artifact.");
533 setCollection(newCollection); 554 setCollection(newCollection);
555
556 artifactsQueue--;
557 addRecommendationsToCollection();
558 }
559 }
560 );
561 }
562
563
564 protected void addRecommendationsToCollection() {
565 Config config = Config.getInstance();
566 final String url = config.getServerUrl();
567 final String locale = config.getLocale();
568 final Collection collection = getCollection();
569
570 collection.addRecommendations(newRecommendations);
571
572 updater.update(collection, url, locale,
573 new AsyncCallback<Collection>() {
574 public void onFailure(Throwable caught) {
575 newRecommendations.removeAllElements();
576 setCollection(collection);
577
578 GWT.log("An error occured while saving recommendations.");
579 // TODO POPUP WARNING
580 }
581
582 public void onSuccess(Collection newCol) {
583 GWT.log("Successfully saved recommendations.");
584 newRecommendations.removeAllElements();
585 setCollection(newCol);
534 } 586 }
535 } 587 }
536 ); 588 );
537 } 589 }
538 590
547 if (master == null || recommendations == null) { 599 if (master == null || recommendations == null) {
548 GWT.log("WARNING: Currently no master artifact set or no recom."); 600 GWT.log("WARNING: Currently no master artifact set or no recom.");
549 return; 601 return;
550 } 602 }
551 603
552 for (Recommendation recommendation: recommendations) { 604 for (final Recommendation recommendation: recommendations) {
605 if (collection.loadedRecommendation(recommendation)) {
606 continue;
607 }
608
553 final String factory = recommendation.getFactory(); 609 final String factory = recommendation.getFactory();
554 final String ids = recommendation.getIDs(); 610 final String ids = recommendation.getIDs();
611
555 612
556 GWT.log("Load recommended artifact with factory: " + factory); 613 GWT.log("Load recommended artifact with factory: " + factory);
557 614
558 createArtifactService.create( 615 createArtifactService.create(
559 url, locale, factory, master.getUuid(), ids, 616 url, locale, factory, master.getUuid(), ids,
560 new AsyncCallback<Artifact>() { 617 new AsyncCallback<Artifact>() {
561
562 public void onFailure(Throwable caught) { 618 public void onFailure(Throwable caught) {
563 GWT.log("Error loading recommendations: " + 619 GWT.log("Error loading recommendations: " +
564 caught.getMessage()); 620 caught.getMessage());
565 } 621 }
566 622
567 public void onSuccess(Artifact artifact) { 623 public void onSuccess(Artifact artifact) {
568 GWT.log("Created new artifact: " + artifact.getUuid()); 624 GWT.log("Created new artifact: " + artifact.getUuid());
569 addArtifactToCollection(artifact); 625 addArtifactToCollection(artifact);
626 newRecommendations.push(recommendation);
570 } 627 }
571 }); 628 });
572 } 629 }
573 } 630 }
574 } 631 }

http://dive4elements.wald.intevation.org