changeset 3380:f6519c699fca

Respect factory of cloned artifact when cloning. flys-client/trunk@5118 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 24 Jul 2012 11:49:12 +0000
parents 0de61fc9d281
children 6b5920c7ea6e
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java
diffstat 2 files changed, 65 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Jul 24 08:11:41 2012 +0000
+++ b/flys-client/ChangeLog	Tue Jul 24 11:49:12 2012 +0000
@@ -1,3 +1,8 @@
+2012-07-24	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/ProjectList.java:
+	  Respect factory of cloned artifact when cloning.
+
 2012-07-21	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/server/UserCollectionsServiceImpl.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Tue Jul 24 08:11:41 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Tue Jul 24 11:49:12 2012 +0000
@@ -45,9 +45,15 @@
 import com.smartgwt.client.types.VerticalAlignment;
 
 import de.intevation.flys.client.shared.model.Collection;
+import de.intevation.flys.client.shared.model.CollectionItem;
 import de.intevation.flys.client.shared.model.CollectionRecord;
 import de.intevation.flys.client.shared.model.User;
 import de.intevation.flys.client.shared.model.Artifact;
+import de.intevation.flys.client.shared.model.ChartArtifact;
+import de.intevation.flys.client.shared.model.FixAnalysisArtifact;
+import de.intevation.flys.client.shared.model.MapArtifact;
+import de.intevation.flys.client.shared.model.MINFOArtifact;
+import de.intevation.flys.client.shared.model.WINFOArtifact;
 import de.intevation.flys.client.shared.model.Recommendation;
 
 import de.intevation.flys.client.client.event.FilterHandler;
@@ -59,22 +65,25 @@
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.event.CollectionChangeEvent;
 import de.intevation.flys.client.client.event.CollectionChangeHandler;
+import de.intevation.flys.client.client.services.AddArtifactService;
+import de.intevation.flys.client.client.services.AddArtifactServiceAsync;
 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.DeleteCollectionService;
 import de.intevation.flys.client.client.services.DeleteCollectionServiceAsync;
+import de.intevation.flys.client.client.services.DescribeCollectionService;
+import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync;
+import de.intevation.flys.client.client.services.GetArtifactService;
+import de.intevation.flys.client.client.services.GetArtifactServiceAsync;
+import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync;
 import de.intevation.flys.client.client.services.SetCollectionNameService;
 import de.intevation.flys.client.client.services.SetCollectionNameServiceAsync;
 import de.intevation.flys.client.client.services.SetCollectionTTLService;
 import de.intevation.flys.client.client.services.SetCollectionTTLServiceAsync;
 import de.intevation.flys.client.client.services.UserCollectionsService;
 import de.intevation.flys.client.client.services.UserCollectionsServiceAsync;
-import de.intevation.flys.client.client.services.DescribeCollectionService;
-import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync;
-import de.intevation.flys.client.client.services.AddArtifactService;
-import de.intevation.flys.client.client.services.AddArtifactServiceAsync;
-import de.intevation.flys.client.client.services.CreateCollectionService;
-import de.intevation.flys.client.client.services.CreateCollectionServiceAsync;
 
 
 /**
@@ -139,6 +148,10 @@
     protected AddArtifactServiceAsync addArtifactService =
         GWT.create(AddArtifactService.class);
 
+    /** The GetArtifactService used to open an existing collection. */
+    protected GetArtifactServiceAsync getArtifactService =
+        GWT.create(GetArtifactService.class);
+
     /** A pointer to the FLYS instance.*/
     protected FLYS flys;
 
@@ -157,6 +170,10 @@
     /** The collection to clone*/
     protected Collection cloneCollection;
 
+    /** The message class that provides i18n strings.*/
+    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
+
+
     /**
      * The default constructor that creates a new ProjectList for a specific
      * user.
@@ -204,12 +221,12 @@
 
         grid.addHeaderDoubleClickHandler(new HeaderDoubleClickHandler() {
             public void onHeaderDoubleClick(HeaderDoubleClickEvent event) {
-                // cancel the event.
+                // Cancel the event.
                 return;
             }
         });
 
-        // add a handler to set / unset the favorite state of a project
+        // Add a handler to set / unset the favorite state of a project.
         grid.addCellClickHandler(new CellClickHandler() {
             public void onCellClick(CellClickEvent event) {
                 if (event.getColNum() != 2) {
@@ -224,7 +241,7 @@
             }
         });
 
-        // add a handler to open a project
+        // Add a handler to open a project.
         grid.addCellDoubleClickHandler(new CellDoubleClickHandler() {
             public void onCellDoubleClick(CellDoubleClickEvent e) {
                 CollectionRecord record = (CollectionRecord) e.getRecord();
@@ -235,7 +252,7 @@
             }
         });
 
-        // add a handler to open a context menu
+        // Add a handler to open a context menu.
         grid.addRowContextClickHandler(new RowContextClickHandler() {
             public void onRowContextClick(RowContextClickEvent event) {
                 CollectionRecord record = (CollectionRecord) event.getRecord();
@@ -565,6 +582,7 @@
         );
     }
 
+
     /**
      * Delete all entries in the ListGrid.
      */
@@ -613,6 +631,7 @@
         }
     }
 
+
     /**
      * Filter for the user collections.
      *
@@ -756,13 +775,14 @@
                 public void onSuccess(Collection newCollection) {
                     GWT.log("Successfully DESCRIBED collection.");
                     String uuid = getMasterArtifact(newCollection);
-                    cloneArtifact(uuid);
+                    cloneArtifact(uuid, newCollection);
                 }
             }
         );
     }
 
 
+    /** Get master artifacts UUID of a collection. */
     protected String getMasterArtifact(Collection newCollection) {
         String uuid = newCollection.getItem(0).identifier();
         // The master artifact uuid.
@@ -770,12 +790,11 @@
     }
 
 
-    protected void cloneArtifact(String uuid) {
-        Config config       = Config.getInstance();
-        final String locale = config.getLocale();
-
+    /** Clone artifact/create collection, using the refArtifacts factory. */
+    protected void cloneArtifact(String uuid, Artifact refArtifact,
+        final String locale) {
         Recommendation recommendation = new Recommendation(
-            "winfo",
+            refArtifact.getName(),
             null,
             uuid,
             null);
@@ -798,6 +817,31 @@
     }
 
 
+    /**
+     * Clone a project (collection).
+     */
+    protected void cloneArtifact(final String uuid, Collection newCollection) {
+        Config config       = Config.getInstance();
+        final String locale = config.getLocale();
+
+        // Find out which factory to use for cloning.
+        CollectionItem master = newCollection.getItem(0);
+        getArtifactService.getArtifact(
+            locale,
+            master.identifier(),
+            master.hash(),
+            new AsyncCallback<Artifact>() {
+                public void onFailure(Throwable caught) {
+                    SC.warn(MSG.getString(caught.getMessage()));
+                }
+
+                public void onSuccess(Artifact artifact) {
+                    cloneArtifact(uuid, artifact, locale);
+                }
+        });
+    }
+
+
     protected void createCollection(final Artifact artifact) {
         Config config        = Config.getInstance();
         final String locale  = config.getLocale();

http://dive4elements.wald.intevation.org