Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java @ 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 | fe2f4d1dd784 |
children | dc086030e6a3 |
comparison
equal
deleted
inserted
replaced
18:3c85259bd92a | 19:f48b2cb2e219 |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
2 | 5 |
3 import com.google.gwt.core.client.GWT; | 6 import com.google.gwt.core.client.GWT; |
4 import com.google.gwt.i18n.client.DateTimeFormat; | 7 import com.google.gwt.i18n.client.DateTimeFormat; |
5 import com.google.gwt.user.client.rpc.AsyncCallback; | 8 import com.google.gwt.user.client.rpc.AsyncCallback; |
6 | 9 |
14 import com.smartgwt.client.widgets.layout.VLayout; | 17 import com.smartgwt.client.widgets.layout.VLayout; |
15 import com.smartgwt.client.widgets.tab.Tab; | 18 import com.smartgwt.client.widgets.tab.Tab; |
16 | 19 |
17 import de.intevation.flys.client.shared.model.Artifact; | 20 import de.intevation.flys.client.shared.model.Artifact; |
18 import de.intevation.flys.client.shared.model.Collection; | 21 import de.intevation.flys.client.shared.model.Collection; |
22 import de.intevation.flys.client.shared.model.DefaultCollection; | |
19 | 23 |
20 import de.intevation.flys.client.client.Config; | 24 import de.intevation.flys.client.client.Config; |
21 import de.intevation.flys.client.client.FLYS; | 25 import de.intevation.flys.client.client.FLYS; |
22 import de.intevation.flys.client.client.FLYSMessages; | 26 import de.intevation.flys.client.client.FLYSMessages; |
27 import de.intevation.flys.client.client.event.HasCollectionChangeHandlers; | |
28 import de.intevation.flys.client.client.event.CollectionChangeEvent; | |
29 import de.intevation.flys.client.client.event.CollectionChangeHandler; | |
23 import de.intevation.flys.client.client.services.ArtifactService; | 30 import de.intevation.flys.client.client.services.ArtifactService; |
24 import de.intevation.flys.client.client.services.ArtifactServiceAsync; | 31 import de.intevation.flys.client.client.services.ArtifactServiceAsync; |
25 | 32 |
26 | 33 |
27 /** | 34 /** |
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 35 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
29 */ | 36 */ |
30 public class CollectionView extends Window { | 37 public class CollectionView |
38 extends Window | |
39 implements CollectionChangeHandler, HasCollectionChangeHandlers { | |
31 | 40 |
32 /** The ArtifactService used to communicate with the Artifact server. */ | 41 /** The ArtifactService used to communicate with the Artifact server. */ |
33 protected ArtifactServiceAsync artifactService = | 42 protected ArtifactServiceAsync artifactService = |
34 GWT.create(ArtifactService.class); | 43 GWT.create(ArtifactService.class); |
35 | 44 |
37 FLYSMessages messages = GWT.create(FLYSMessages.class); | 46 FLYSMessages messages = GWT.create(FLYSMessages.class); |
38 | 47 |
39 /** The FLYS instance used to call services.*/ | 48 /** The FLYS instance used to call services.*/ |
40 protected FLYS flys; | 49 protected FLYS flys; |
41 | 50 |
51 /** The list of ValueChangeHandlers.*/ | |
52 protected List<CollectionChangeHandler> handlers; | |
53 | |
42 /** The collection to be displayed.*/ | 54 /** The collection to be displayed.*/ |
43 protected Collection collection; | 55 protected Collection collection; |
44 | |
45 /** TODO The artifact needs to be removed here after the Collection stuff in | |
46 * the server has been finished! */ | |
47 protected Artifact artifact; | |
48 | 56 |
49 /** The parameter tab.*/ | 57 /** The parameter tab.*/ |
50 protected Tab parameterTab; | 58 protected Tab parameterTab; |
51 | 59 |
52 /** The output tab.*/ | 60 /** The output tab.*/ |
61 */ | 69 */ |
62 public CollectionView(FLYS flys, Collection collection) { | 70 public CollectionView(FLYS flys, Collection collection) { |
63 this.flys = flys; | 71 this.flys = flys; |
64 this.collection = collection; | 72 this.collection = collection; |
65 | 73 |
74 this.handlers = new ArrayList<CollectionChangeHandler>(); | |
75 | |
76 addCollectionChangeHandler(this); | |
77 | |
66 init(); | 78 init(); |
67 } | 79 } |
68 | 80 |
69 | 81 |
70 /** | 82 /** |
88 } | 100 } |
89 } | 101 } |
90 | 102 |
91 | 103 |
92 /** | 104 /** |
105 * This method registers a new ValueChangeHandler. | |
106 * | |
107 * @param handler The new ValueChangeHandler. | |
108 */ | |
109 public void addCollectionChangeHandler(CollectionChangeHandler handler) { | |
110 if (handler != null) { | |
111 handlers.add(handler); | |
112 } | |
113 } | |
114 | |
115 | |
116 /** | |
117 * This method calls the <code>onValueChange()</code> method of all | |
118 * registered ValueChangeHanders. | |
119 */ | |
120 protected void fireCollectionChangeEvent( | |
121 Collection old, Collection newCol) | |
122 { | |
123 for (CollectionChangeHandler handler: handlers) { | |
124 handler.onCollectionChange(new CollectionChangeEvent(old, newCol)); | |
125 } | |
126 } | |
127 | |
128 | |
129 /** | |
93 * This method returns true, if the Collection is new and no plugins has | 130 * This method returns true, if the Collection is new and no plugins has |
94 * been chosen. | 131 * been chosen. |
95 * | 132 * |
96 * @return true, if the Collection is new. | 133 * @return true, if the Collection is new. |
97 */ | 134 */ |
98 public boolean isNew() { | 135 public boolean isNew() { |
99 return true; | 136 return collection.getArtifactLength() == 0 ? true : false; |
100 } | 137 } |
101 | 138 |
102 | 139 |
103 /** | 140 /** |
104 * This method creates a Canvas displaying the plugins of FLYS. | 141 * This method creates a Canvas displaying the plugins of FLYS. |
135 GWT.log(caught.getMessage()); | 172 GWT.log(caught.getMessage()); |
136 } | 173 } |
137 | 174 |
138 public void onSuccess(Artifact artifact) { | 175 public void onSuccess(Artifact artifact) { |
139 GWT.log("Successfully created a new artifact."); | 176 GWT.log("Successfully created a new artifact."); |
140 setArtifact(artifact); | 177 Collection c = new DefaultCollection("TODO"); |
178 c.addArtifact(artifact); | |
179 | |
180 setCollection(c); | |
141 } | 181 } |
142 }); | 182 }); |
143 } | 183 } |
144 }); | 184 }); |
145 | 185 |
149 return layout; | 189 return layout; |
150 } | 190 } |
151 | 191 |
152 | 192 |
153 /** | 193 /** |
154 * Set the current artifact. | 194 * Set the current collection. |
155 * | 195 * |
156 * @param artifact The new artifact. | 196 * @param collection The new collection. |
157 */ | 197 */ |
158 protected void setArtifact(Artifact artifact) { | 198 protected void setCollection(Collection collection) { |
159 this.artifact = artifact; | 199 Collection tmp = this.collection; |
160 | 200 this.collection = collection; |
201 | |
202 fireCollectionChangeEvent(tmp, this.collection); | |
203 } | |
204 | |
205 | |
206 public void onCollectionChange(CollectionChangeEvent event) { | |
161 updateView(); | 207 updateView(); |
162 } | 208 } |
163 | 209 |
164 | 210 |
165 protected void updateView() { | 211 protected void updateView() { |
166 GWT.log("Update the view of the artifact: " + artifact.getUuid()); | 212 GWT.log("Update view of the collection: " + collection.identifier()); |
167 // TODO display the artifact information / data | 213 // TODO display the artifact information / data |
168 } | 214 } |
169 } | 215 } |
170 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 216 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |