diff flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java @ 71:987567f31200

Adjusted the return type of the CreateCollectionService and added code to react on Collection changes (like output modes). flys-client/trunk@1573 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 25 Mar 2011 11:51:54 +0000
parents f793d35bfb08
children 9b726350ab07
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Fri Mar 25 11:41:55 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Fri Mar 25 11:51:54 2011 +0000
@@ -22,7 +22,9 @@
 import de.intevation.flys.client.shared.model.DataList;
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
+import de.intevation.flys.client.shared.model.OutputMode;
 import de.intevation.flys.client.shared.model.River;
+import de.intevation.flys.client.shared.model.User;
 
 import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYS;
@@ -39,6 +41,8 @@
 import de.intevation.flys.client.client.event.StepBackHandler;
 import de.intevation.flys.client.client.event.StepForwardEvent;
 import de.intevation.flys.client.client.event.StepForwardHandler;
+import de.intevation.flys.client.client.services.AddArtifactService;
+import de.intevation.flys.client.client.services.AddArtifactServiceAsync;
 import de.intevation.flys.client.client.services.AdvanceService;
 import de.intevation.flys.client.client.services.AdvanceServiceAsync;
 import de.intevation.flys.client.client.services.ArtifactService;
@@ -75,6 +79,10 @@
     protected CreateCollectionServiceAsync createCollectionService =
         GWT.create(CreateCollectionService.class);
 
+    /** The AddArtifactService used to add an artifact to a collection. */
+    protected AddArtifactServiceAsync addArtifactService =
+        GWT.create(AddArtifactService.class);
+
     /** The message class that provides i18n strings.*/
     FLYSMessages messages = GWT.create(FLYSMessages.class);
 
@@ -166,20 +174,34 @@
      * @param ownerId The uuid of the user that should own the new collection.
      */
     protected void createNewCollection(String ownerId) {
-        Config config    = Config.getInstance();
-        String serverUrl = config.getServerUrl();
+        Config config          = Config.getInstance();
+        final String serverUrl = config.getServerUrl();
 
         createCollectionService.create(
             serverUrl, ownerId,
-            new AsyncCallback<String>() {
+            new AsyncCallback<Collection>() {
                 public void onFailure(Throwable caught) {
                     GWT.log("Could not create the new collection.");
                     GWT.log(caught.getMessage());
                 }
 
-                public void onSuccess(String uuid) {
+                public void onSuccess(Collection collection) {
                     GWT.log("Successfully created a new collection.");
-                    GWT.log("NEW collection uuid: " + uuid);
+
+                    Artifact artifact = getArtifact();
+                    addArtifactService.add(collection, artifact, serverUrl,
+                        new AsyncCallback<Collection>() {
+
+                            public void onFailure(Throwable caught) {
+                                GWT.log("An error occured while adding artifact.");
+                            }
+
+                            public void onSuccess(Collection newCollection) {
+                                GWT.log("Successfully added artifact.");
+                                setCollection(newCollection);
+                            }
+                        }
+                    );
                 }
             });
     }
@@ -246,7 +268,7 @@
      * @return true, if the Collection is new.
      */
     public boolean isNew() {
-        return collection.getArtifactLength() == 0 ? true : false;
+        return collection.getItemLength() == 0 ? true : false;
     }
 
 
@@ -323,6 +345,16 @@
 
 
     /**
+     * Returns the artifact that is used for the parameterization.
+     *
+     * @return the artifact that is used for the parameterization.
+     */
+    protected Artifact getArtifact() {
+        return artifact;
+    }
+
+
+    /**
      * Set the current artifact that is the master of the parameterization.
      *
      * @param artifact The new artifact.
@@ -342,8 +374,17 @@
      * @param event The ParameterChangeEvent.
      */
     public void onParameterChange(ParameterChangeEvent event) {
+        Artifact art             = event.getNewValue();
+        ArtifactDescription desc = art.getArtifactDescription();
+        OutputMode[] outs        = desc.getOutputModes();
 
-        updateView();
+        if (outs != null) {
+            User user = getFlys().getCurrentUser();
+            createNewCollection(user.identifier());
+        }
+        else {
+            updateView();
+        }
     }
 
 

http://dive4elements.wald.intevation.org