diff flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java @ 3865:436eec3be6ff

Allow to create a discharge curve from a gauge info This is only a draft yet. flys-client/trunk@5639 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 28 Sep 2012 08:57:48 +0000
parents 8e69aca69074
children 6cc5186b9b48
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Fri Sep 28 08:52:53 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Fri Sep 28 08:57:48 2012 +0000
@@ -17,6 +17,8 @@
 import de.intevation.flys.client.client.event.CollectionChangeHandler;
 import de.intevation.flys.client.client.services.ArtifactService;
 import de.intevation.flys.client.client.services.ArtifactServiceAsync;
+import de.intevation.flys.client.client.services.CreateCollectionService;
+import de.intevation.flys.client.client.services.CreateCollectionServiceAsync;
 import de.intevation.flys.client.client.services.DescribeCollectionService;
 import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync;
 import de.intevation.flys.client.client.services.GetArtifactService;
@@ -72,6 +74,9 @@
     protected GetArtifactServiceAsync getArtifactService =
         GWT.create(GetArtifactService.class);
 
+    /** The CreateCollectionServiceAsync used to create a new collection */
+    protected CreateCollectionServiceAsync collectionService =
+        GWT.create(CreateCollectionService.class);
 
     /** The menu bar at the top of the application. */
     protected MainMenu menu;
@@ -440,6 +445,55 @@
         });
     }
 
+    public void newGaugeDischargeCurve(String river, Long gaugeref) {
+        Config config = Config.getInstance();
+
+        final String locale = config.getLocale();
+        final String riv = river;
+        final Long ref = gaugeref;
+        final FLYS   flys = this;
+
+        User user = getCurrentUser();
+
+        if (user == null) {
+            SC.warn(MSG.error_not_logged_in());
+            return;
+        }
+
+        collectionService.create(locale, user.identifier(),
+            new AsyncCallback<Collection>() {
+                @Override
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not create new collection.");
+                    SC.warn(MSG.getString(caught.getMessage()));
+                }
+
+                @Override
+                public void onSuccess(Collection collection) {
+                    GWT.log("Successfully created a new collection.");
+                    final Collection col = collection;
+                    artifactService.createGaugeDischargeCurverArtifact(
+                        col, locale, riv, ref,
+                        new AsyncCallback<Artifact>() {
+                            @Override
+                            public void onFailure(Throwable caught) {
+                                GWT.log("Could not create the new artifact.");
+                                SC.warn(MSG.getString(caught.getMessage()));
+                            }
+
+                            @Override
+                            public void onSuccess(Artifact artifact) {
+                                GWT.log("Successfully created a new artifact.");
+                                CollectionView view = new CollectionView(flys,
+                                    col, artifact);
+                                workspace.addView("new-project", view);
+
+                                view.addCollectionChangeHandler(getProjectList());
+                            }
+                    });
+                }
+            });
+    }
 
     @Override
     public void onCollectionChange(CollectionChangeEvent event) {

http://dive4elements.wald.intevation.org