Mercurial > dive4elements > river
changeset 19:f48b2cb2e219
The CollectionView implements the HasCollectionChangeHandlers interface now.
flys-client/trunk@1332 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 21 Feb 2011 07:03:13 +0000 |
parents | 3c85259bd92a |
children | c128d675386b |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java |
diffstat | 2 files changed, 65 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Fri Feb 18 15:42:29 2011 +0000 +++ b/flys-client/ChangeLog Mon Feb 21 07:03:13 2011 +0000 @@ -1,3 +1,10 @@ +2011-02-21 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/client/client/ui/CollectionView.java: + This view implements the HasCollectionChangeHandlers interface - + CollectionChangeHandler can register to this class and retrieve + notifications when the collection of this view changes. + 2011-02-18 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/client/client/event/CollectionChangeHandler.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Fri Feb 18 15:42:29 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Mon Feb 21 07:03:13 2011 +0000 @@ -1,5 +1,8 @@ package de.intevation.flys.client.client.ui; +import java.util.ArrayList; +import java.util.List; + import com.google.gwt.core.client.GWT; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -16,10 +19,14 @@ import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.DefaultCollection; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYS; import de.intevation.flys.client.client.FLYSMessages; +import de.intevation.flys.client.client.event.HasCollectionChangeHandlers; +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; @@ -27,7 +34,9 @@ /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ -public class CollectionView extends Window { +public class CollectionView +extends Window +implements CollectionChangeHandler, HasCollectionChangeHandlers { /** The ArtifactService used to communicate with the Artifact server. */ protected ArtifactServiceAsync artifactService = @@ -39,13 +48,12 @@ /** The FLYS instance used to call services.*/ protected FLYS flys; + /** The list of ValueChangeHandlers.*/ + protected List<CollectionChangeHandler> handlers; + /** The collection to be displayed.*/ protected Collection collection; - /** TODO The artifact needs to be removed here after the Collection stuff in - * the server has been finished! */ - protected Artifact artifact; - /** The parameter tab.*/ protected Tab parameterTab; @@ -63,6 +71,10 @@ this.flys = flys; this.collection = collection; + this.handlers = new ArrayList<CollectionChangeHandler>(); + + addCollectionChangeHandler(this); + init(); } @@ -90,13 +102,38 @@ /** + * This method registers a new ValueChangeHandler. + * + * @param handler The new ValueChangeHandler. + */ + public void addCollectionChangeHandler(CollectionChangeHandler handler) { + if (handler != null) { + handlers.add(handler); + } + } + + + /** + * This method calls the <code>onValueChange()</code> method of all + * registered ValueChangeHanders. + */ + protected void fireCollectionChangeEvent( + Collection old, Collection newCol) + { + for (CollectionChangeHandler handler: handlers) { + handler.onCollectionChange(new CollectionChangeEvent(old, newCol)); + } + } + + + /** * This method returns true, if the Collection is new and no plugins has * been chosen. * * @return true, if the Collection is new. */ public boolean isNew() { - return true; + return collection.getArtifactLength() == 0 ? true : false; } @@ -137,7 +174,10 @@ public void onSuccess(Artifact artifact) { GWT.log("Successfully created a new artifact."); - setArtifact(artifact); + Collection c = new DefaultCollection("TODO"); + c.addArtifact(artifact); + + setCollection(c); } }); } @@ -151,19 +191,25 @@ /** - * Set the current artifact. + * Set the current collection. * - * @param artifact The new artifact. + * @param collection The new collection. */ - protected void setArtifact(Artifact artifact) { - this.artifact = artifact; + protected void setCollection(Collection collection) { + Collection tmp = this.collection; + this.collection = collection; + fireCollectionChangeEvent(tmp, this.collection); + } + + + public void onCollectionChange(CollectionChangeEvent event) { updateView(); } protected void updateView() { - GWT.log("Update the view of the artifact: " + artifact.getUuid()); + GWT.log("Update view of the collection: " + collection.identifier()); // TODO display the artifact information / data } }