# HG changeset patch # User Ingo Weinzierl # Date 1298271793 0 # Node ID f48b2cb2e2197086dc36a2a81ba8c5688c44edb6 # Parent 3c85259bd92a57b46a1d258b7657b71e80b6dbf0 The CollectionView implements the HasCollectionChangeHandlers interface now. flys-client/trunk@1332 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 3c85259bd92a -r f48b2cb2e219 flys-client/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/client/client/event/CollectionChangeHandler.java, diff -r 3c85259bd92a -r f48b2cb2e219 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 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 Ingo Weinzierl */ -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 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(); + + 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 onValueChange() 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 } }