Mercurial > dive4elements > river
changeset 4659:518d60dfe6bf
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.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Tue, 11 Dec 2012 16:23:29 +0100 |
parents | bea519b46919 |
children | bb9ce9aece70 |
files | flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java |
diffstat | 1 files changed, 53 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- 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<Collection>() { - @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<Collection>() { + @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<Collection>() { + @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<Collection>() { + @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); + } + } + ); + } } - } - ); + ); + } }