# HG changeset patch # User Björn Ricks # Date 1355239409 -3600 # Node ID 518d60dfe6bf2af06a50e3443381ff2a87140f85 # Parent bea519b46919a11662bd5157787b23f885992b96 Create a Collection if an artifact is added to the CollectionView If an artifact will be added to a Collection create the collection on demand if it doesn't exist yet. diff -r bea519b46919 -r 518d60dfe6bf flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Tue Dec 11 16:11:20 2012 +0100 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Tue Dec 11 16:23:29 2012 +0100 @@ -624,22 +624,62 @@ final String locale = config.getLocale(); final Collection collection = getCollection(); - addArtifactService.add( - collection, artifact, locale, - new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { - GWT.log("An error occured while adding artifact."); - SC.warn(FLYS.getExceptionString(messages, caught)); + GWT.log("CollectionView.addArtifactToCollection " + collection); + + if (collection != null) { + addArtifactService.add( + collection, artifact, locale, + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + GWT.log("An error occured while adding artifact."); + SC.warn(FLYS.getExceptionString(messages, caught)); + } + + @Override + public void onSuccess(Collection newCollection) { + GWT.log("Successfully added artifacts."); + setCollection(newCollection, true); + } } + ); + } + else { + // Create new collection and add artifact + final Artifact art = artifact; + createCollectionService.create( + locale, + flys.getCurrentUser().identifier(), + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not create the new collection."); + SC.warn(FLYS.getExceptionString(messages, caught)); + } - @Override - public void onSuccess(Collection newCollection) { - GWT.log("Successfully added artifacts."); - setCollection(newCollection, true); + @Override + public void onSuccess(Collection collection) { + GWT.log("Successfully created a new collection."); + addArtifactService.add( + collection, art, locale, + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + GWT.log("An error occured while adding artifact."); + SC.warn(FLYS.getExceptionString(messages, caught)); + } + + @Override + public void onSuccess(Collection newCollection) { + GWT.log("Successfully added artifacts."); + setCollection(newCollection); + } + } + ); + } } - } - ); + ); + } }