# HG changeset patch # User Raimund Renkert # Date 1315932686 0 # Node ID 6a27949c70228c1451c410bc431ca2abebc703b9 # Parent 2161d3acc83fcd10c23e4938c64393a8496eec82 Issue234/266: Added feature for duplicating projects. flys-client/trunk@2721 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 2161d3acc83f -r 6a27949c7022 flys-client/ChangeLog --- a/flys-client/ChangeLog Tue Sep 13 12:47:54 2011 +0000 +++ b/flys-client/ChangeLog Tue Sep 13 16:51:26 2011 +0000 @@ -1,3 +1,16 @@ +2011-09-13 Raimund Renkert + + Issue234/266 + + * src/main/java/de/intevation/flys/client/client/ui/ProjectList.java: + Added feature for duplicating projects. + + * src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants.java, + src/main/java/de/intevation/flys/client/client/FLYSConstants.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties: + Added i18n string for context menu and project name. + 2011-09-13 Raimund Renkert Issue239 diff -r 2161d3acc83f -r 6a27949c7022 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Tue Sep 13 12:47:54 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Tue Sep 13 16:51:26 2011 +0000 @@ -26,6 +26,10 @@ String rename_project(); + String clone_project(); + + String copy_of (); + String manage_projects(); String favorite_tooltip(); diff -r 2161d3acc83f -r 6a27949c7022 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Tue Sep 13 12:47:54 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Tue Sep 13 16:51:26 2011 +0000 @@ -7,6 +7,8 @@ open_project = Open Project delete_project = Delete Project rename_project = Rename Project +clone_project = Clone Project +copy_of = Copy manage_projects = Manage Projects favorite_tooltip = Permanently store? favorite_tooltip_meaning = Golden star: stored diff -r 2161d3acc83f -r 6a27949c7022 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Tue Sep 13 12:47:54 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Tue Sep 13 16:51:26 2011 +0000 @@ -7,6 +7,8 @@ open_project = Projekt \u00f6ffnen delete_project = Projekt l\u00f6schen rename_project = Projekt umbenennen +clone_project = Projekt duplizieren +copy_of = Kopie manage_projects = Projekte verwalten favorite_tooltip = Dauerhaft speichern? favorite_tooltip_meaning = Goldener Stern: gespeichert diff -r 2161d3acc83f -r 6a27949c7022 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Tue Sep 13 12:47:54 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Tue Sep 13 16:51:26 2011 +0000 @@ -7,6 +7,8 @@ open_project = Open Project delete_project = Delete Project rename_project = Rename Project +clone_project = Copy Project +copy_of = Copy manage_projects = Manage Projects favorite_tooltip = Permanently store? favorite_tooltip_meaning = Golden star: stored diff -r 2161d3acc83f -r 6a27949c7022 flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java Tue Sep 13 12:47:54 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java Tue Sep 13 16:51:26 2011 +0000 @@ -12,8 +12,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.data.Criteria; -import de.intevation.flys.client.client.event.FilterHandler; -import de.intevation.flys.client.client.event.StringFilterEvent; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.ListGridEditEvent; import com.smartgwt.client.types.ListGridFieldType; @@ -48,12 +46,19 @@ import de.intevation.flys.client.shared.model.Collection; 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.Recommendation; + +import de.intevation.flys.client.client.event.FilterHandler; +import de.intevation.flys.client.client.event.StringFilterEvent; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYS; 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.ArtifactService; +import de.intevation.flys.client.client.services.ArtifactServiceAsync; import de.intevation.flys.client.client.services.DeleteCollectionService; import de.intevation.flys.client.client.services.DeleteCollectionServiceAsync; import de.intevation.flys.client.client.services.SetCollectionNameService; @@ -62,6 +67,12 @@ 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; /** @@ -110,6 +121,22 @@ protected DeleteCollectionServiceAsync deleteService = GWT.create(DeleteCollectionService.class); + /** The DescribeCollectionService used to update the existing collection. */ + protected DescribeCollectionServiceAsync describeCollectionService = + GWT.create(DescribeCollectionService.class); + + /** The ArtifactService used to communicate with the Artifact server. */ + protected ArtifactServiceAsync createArtifactService = + GWT.create(ArtifactService.class); + + /** The ArtifactService used to communicate with the Artifact server. */ + protected CreateCollectionServiceAsync createCollectionService = + GWT.create(CreateCollectionService.class); + + /** The AddArtifactService used to add an artifact to a collection. */ + protected AddArtifactServiceAsync addArtifactService = + GWT.create(AddArtifactService.class); + /** A pointer to the FLYS instance.*/ protected FLYS flys; @@ -125,6 +152,9 @@ /** The collections visible in the grid.*/ protected List filteredCollections; + /** The collection to clone*/ + protected Collection cloneCollection; + /** * The default constructor that creates a new ProjectList for a specific * user. @@ -277,8 +307,16 @@ } }); + MenuItem clone = new MenuItem(messages.clone_project()); + clone.addClickHandler(new ClickHandler() { + public void onClick(MenuItemClickEvent evt) { + cloneProject(record.getCollection()); + } + }); + menu.addItem(open); menu.addItem(rename); + menu.addItem(clone); menu.addItem(new MenuItemSeparator()); menu.addItem(del); @@ -680,5 +718,122 @@ return fav; } + + + protected void cloneProject(Collection c) { + Config config = Config.getInstance(); + String url = config.getServerUrl(); + String locale = config.getLocale(); + + cloneCollection = c; + + describeCollectionService.describe(c.identifier(), url, locale, + new AsyncCallback() { + public void onFailure(Throwable caught) { + GWT.log("Could not DESCRIBE collection."); + SC.warn(messages.getString(caught.getMessage())); + } + + + public void onSuccess(Collection newCollection) { + GWT.log("Successfully DESCRIBED collection."); + String uuid = getMasterArtifact(newCollection); + cloneArtifact(uuid); + } + } + ); + } + + + protected String getMasterArtifact(Collection newCollection) { + String uuid = newCollection.getItem(0).identifier(); + // The master artifact uuid. + return uuid; + } + + + protected void cloneArtifact(String uuid) { + Config config = Config.getInstance(); + final String url = config.getServerUrl(); + final String locale = config.getLocale(); + + Recommendation recommendation = new Recommendation( + "winfo", + null, + uuid, + null); + + String factory = recommendation.getFactory(); + createArtifactService.create( + url, locale, factory, recommendation, + new AsyncCallback() { + public void onFailure(Throwable caught) { + GWT.log("Error loading recommendations: " + + caught.getMessage()); + } + + public void onSuccess(Artifact artifact) { + GWT.log("Created new artifact: " + artifact.getUuid()); + createCollection(artifact); + } + } + ); + } + + + protected void createCollection(final Artifact artifact) { + Config config = Config.getInstance(); + final String url = config.getServerUrl(); + final String locale = config.getLocale(); + final String ownerid = user.identifier(); + + createCollectionService.create( + url, locale, ownerid, + new AsyncCallback() { + public void onFailure(Throwable caught) { + GWT.log("Could not create the new collection."); + SC.warn(messages.getString(caught.getMessage())); + } + + public void onSuccess(Collection collection) { + GWT.log("Successfully created a new collection."); + addArtifactToCollection(artifact, collection); + } + } + ); + } + + + protected void addArtifactToCollection(Artifact a, Collection c) { + Config config = Config.getInstance(); + final String url = config.getServerUrl(); + final String locale = config.getLocale(); + + addArtifactService.add( + c, a, url, locale, + new AsyncCallback() { + public void onFailure(Throwable caught) { + GWT.log("An error occured while adding artifact."); + SC.warn(messages.getString(caught.getMessage())); + } + + public void onSuccess(Collection newColl) { + String name = cloneCollection.getName(); + if(name == null || name.equals("")) { + name = cloneCollection.identifier(); + } + + newColl.setName("(" + messages.copy_of() + ")" + name); + + updateCollectionName(newColl); + if(cloneCollection.getTTL() == 0) { + newColl.setTTL(0); + updateCollectionTTL(newColl); + } + updateUserCollections(); + } + } + ); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :