Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Thu Jul 21 16:06:29 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Fri Jul 22 12:23:36 2011 +0000 @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Stack; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -41,6 +42,8 @@ import de.intevation.flys.client.client.services.ArtifactServiceAsync; import de.intevation.flys.client.client.services.AddArtifactService; import de.intevation.flys.client.client.services.AddArtifactServiceAsync; +import de.intevation.flys.client.client.services.CollectionAttributeService; +import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; import de.intevation.flys.client.client.services.CreateCollectionService; import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; import de.intevation.flys.client.client.services.DescribeCollectionService; @@ -72,6 +75,9 @@ protected DescribeCollectionServiceAsync describeCollectionService = GWT.create(DescribeCollectionService.class); + protected CollectionAttributeServiceAsync updater = + GWT.create(CollectionAttributeService.class); + /** The message class that provides i18n strings.*/ protected FLYSConstants messages = GWT.create(FLYSConstants.class); @@ -101,6 +107,9 @@ /** The layout.*/ protected Layout layout; + protected int artifactsQueue; + protected Stack<Recommendation> newRecommendations; + /** * This constructor creates a new CollectionView that is used to display the @@ -117,6 +126,8 @@ this.layout = new VLayout(); this.parameterList = new ParameterList( flys, this, messages.new_project()); + this.artifactsQueue = 0; + this.newRecommendations = new Stack<Recommendation>(); addCollectionChangeHandler(this); addCollectionChangeHandler(parameterList); @@ -143,6 +154,8 @@ this, messages.getString(artifact.getName()), artifact); + this.artifactsQueue = 0; + this.newRecommendations = new Stack<Recommendation>(); addCollectionChangeHandler(this); addCollectionChangeHandler(parameterList); @@ -382,6 +395,11 @@ public void onCollectionChange(CollectionChangeEvent event) { + if (artifactsQueue > 0) { + GWT.log("Do not update UI because we are still loading Artifacts."); + return; + } + Collection newCol = event.getNewValue(); Map<String, OutputMode> outs = newCol.getOutputModes(); @@ -520,17 +538,51 @@ final String locale = config.getLocale(); final Collection collection = getCollection(); + artifactsQueue++; + addArtifactService.add( collection, artifact, url, locale, new AsyncCallback<Collection>() { public void onFailure(Throwable caught) { GWT.log("An error occured while adding artifact."); + artifactsQueue--; SC.warn(messages.getString(caught.getMessage())); } public void onSuccess(Collection newCollection) { GWT.log("Successfully added artifact."); setCollection(newCollection); + + artifactsQueue--; + addRecommendationsToCollection(); + } + } + ); + } + + + protected void addRecommendationsToCollection() { + Config config = Config.getInstance(); + final String url = config.getServerUrl(); + final String locale = config.getLocale(); + final Collection collection = getCollection(); + + collection.addRecommendations(newRecommendations); + + updater.update(collection, url, locale, + new AsyncCallback<Collection>() { + public void onFailure(Throwable caught) { + newRecommendations.removeAllElements(); + setCollection(collection); + + GWT.log("An error occured while saving recommendations."); + // TODO POPUP WARNING + } + + public void onSuccess(Collection newCol) { + GWT.log("Successfully saved recommendations."); + newRecommendations.removeAllElements(); + setCollection(newCol); } } ); @@ -549,16 +601,20 @@ return; } - for (Recommendation recommendation: recommendations) { + for (final Recommendation recommendation: recommendations) { + if (collection.loadedRecommendation(recommendation)) { + continue; + } + final String factory = recommendation.getFactory(); final String ids = recommendation.getIDs(); + GWT.log("Load recommended artifact with factory: " + factory); createArtifactService.create( url, locale, factory, master.getUuid(), ids, new AsyncCallback<Artifact>() { - public void onFailure(Throwable caught) { GWT.log("Error loading recommendations: " + caught.getMessage()); @@ -567,6 +623,7 @@ public void onSuccess(Artifact artifact) { GWT.log("Created new artifact: " + artifact.getUuid()); addArtifactToCollection(artifact); + newRecommendations.push(recommendation); } }); }