Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java @ 911:4668357b255e
#259 Refresh charts after loading new Themes / Artifacts from Datacage.
flys-client/trunk@2768 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 15 Sep 2011 17:01:12 +0000 |
parents | 7f72239e56c8 |
children | 07aa1f504491 |
comparison
equal
deleted
inserted
replaced
910:7f72239e56c8 | 911:4668357b255e |
---|---|
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.user.client.rpc.AsyncCallback; | 7 import com.google.gwt.user.client.rpc.AsyncCallback; |
5 | 8 |
6 import com.smartgwt.client.util.SC; | 9 import com.smartgwt.client.util.SC; |
8 | 11 |
9 import de.intevation.flys.client.client.Config; | 12 import de.intevation.flys.client.client.Config; |
10 import de.intevation.flys.client.client.FLYSConstants; | 13 import de.intevation.flys.client.client.FLYSConstants; |
11 | 14 |
12 import de.intevation.flys.client.client.event.DatacageHandler; | 15 import de.intevation.flys.client.client.event.DatacageHandler; |
16 import de.intevation.flys.client.client.event.HasRedrawRequestHandlers; | |
17 import de.intevation.flys.client.client.event.RedrawRequestHandler; | |
18 import de.intevation.flys.client.client.event.RedrawRequestEvent; | |
19 import de.intevation.flys.client.client.event.RedrawRequestEvent.Type; | |
13 | 20 |
14 import de.intevation.flys.client.client.services.LoadArtifactService; | 21 import de.intevation.flys.client.client.services.LoadArtifactService; |
15 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; | 22 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; |
16 | 23 |
17 import de.intevation.flys.client.shared.model.Artifact; | 24 import de.intevation.flys.client.shared.model.Artifact; |
22 import de.intevation.flys.client.shared.model.DataList; | 29 import de.intevation.flys.client.shared.model.DataList; |
23 import de.intevation.flys.client.shared.model.ToLoad; | 30 import de.intevation.flys.client.shared.model.ToLoad; |
24 import de.intevation.flys.client.shared.model.User; | 31 import de.intevation.flys.client.shared.model.User; |
25 import de.intevation.flys.client.shared.model.Recommendation; | 32 import de.intevation.flys.client.shared.model.Recommendation; |
26 | 33 |
27 import java.util.List; | |
28 | |
29 | 34 |
30 public class DatacageWindow | 35 public class DatacageWindow |
31 extends Window | 36 extends Window |
32 implements DatacageHandler | 37 implements DatacageHandler, HasRedrawRequestHandlers |
33 { | 38 { |
34 protected FLYSConstants messages = | 39 protected FLYSConstants messages = |
35 GWT.create(FLYSConstants.class); | 40 GWT.create(FLYSConstants.class); |
36 | 41 |
37 protected LoadArtifactServiceAsync loadService = | 42 protected LoadArtifactServiceAsync loadService = |
38 GWT.create(LoadArtifactService.class); | 43 GWT.create(LoadArtifactService.class); |
39 | 44 |
40 protected CollectionView view; | 45 protected CollectionView view; |
41 | 46 |
47 protected List<RedrawRequestHandler> handlers; | |
48 | |
49 protected int inProgress; | |
50 | |
51 | |
42 public DatacageWindow( | 52 public DatacageWindow( |
43 Artifact artifact, | 53 Artifact artifact, |
44 User user, | 54 User user, |
45 String outs, | 55 String outs, |
46 CollectionView view | 56 CollectionView view |
47 ) { | 57 ) { |
48 this.view = view; | 58 this.view = view; |
59 this.handlers = new ArrayList<RedrawRequestHandler>(); | |
60 this.inProgress = 0; | |
61 | |
49 setWidth(400); | 62 setWidth(400); |
50 setHeight(500); | 63 setHeight(500); |
51 | 64 |
52 DatacageWidget dw = new DatacageWidget(artifact, user, outs); | 65 DatacageWidget dw = new DatacageWidget(artifact, user, outs); |
53 dw.addDatacageHandler(this); | 66 dw.addDatacageHandler(this); |
72 List<Recommendation> recs = toLoad.toRecommendations(); | 85 List<Recommendation> recs = toLoad.toRecommendations(); |
73 loadArtifacts(recs.toArray(new Recommendation[recs.size()])); | 86 loadArtifacts(recs.toArray(new Recommendation[recs.size()])); |
74 } | 87 } |
75 | 88 |
76 | 89 |
90 @Override | |
91 public void addRedrawRequestHandler(RedrawRequestHandler handler) { | |
92 if (handler != null) { | |
93 handlers.add(handler); | |
94 } | |
95 } | |
96 | |
97 | |
77 protected String findRiver(Artifact artifact) { | 98 protected String findRiver(Artifact artifact) { |
78 ArtifactDescription adescr = artifact.getArtifactDescription(); | 99 ArtifactDescription adescr = artifact.getArtifactDescription(); |
79 DataList [] data = adescr.getOldData(); | 100 DataList [] data = adescr.getOldData(); |
80 | 101 |
81 if (data != null && data.length > 0) { | 102 if (data != null && data.length > 0) { |
95 | 116 |
96 return ""; | 117 return ""; |
97 } | 118 } |
98 | 119 |
99 | 120 |
121 protected void decreateInProgress() { | |
122 if (this.inProgress > 0) { | |
123 this.inProgress--; | |
124 } | |
125 | |
126 if (this.inProgress == 0) { | |
127 fireRedrawRequest(); | |
128 } | |
129 } | |
130 | |
131 | |
132 protected void fireRedrawRequest() { | |
133 RedrawRequestEvent evt = new RedrawRequestEvent(Type.DEFAULT); | |
134 | |
135 for (RedrawRequestHandler handler: handlers) { | |
136 handler.onRedrawRequest(evt); | |
137 } | |
138 } | |
139 | |
140 | |
100 protected void loadArtifacts(Recommendation[] recommendations) { | 141 protected void loadArtifacts(Recommendation[] recommendations) { |
101 Config cfg = Config.getInstance(); | 142 Config cfg = Config.getInstance(); |
102 | 143 |
103 final Collection collection = view.getCollection(); | 144 final Collection collection = view.getCollection(); |
104 final Artifact masterArtifact = view.getArtifact(); | 145 final Artifact masterArtifact = view.getArtifact(); |
105 final String serverUrl = cfg.getServerUrl(); | 146 final String serverUrl = cfg.getServerUrl(); |
106 final String locale = cfg.getLocale(); | 147 final String locale = cfg.getLocale(); |
148 | |
149 this.inProgress = recommendations.length; | |
107 | 150 |
108 for (final Recommendation recommendation: recommendations) { | 151 for (final Recommendation recommendation: recommendations) { |
109 // XXX: UGLY! If no reference artifact given use uuid of | 152 // XXX: UGLY! If no reference artifact given use uuid of |
110 // current artifact as reference. | 153 // current artifact as reference. |
111 if (recommendation.getMasterArtifact() == null) { | 154 if (recommendation.getMasterArtifact() == null) { |
122 factory, | 165 factory, |
123 serverUrl, | 166 serverUrl, |
124 locale, | 167 locale, |
125 new AsyncCallback<Artifact>() { | 168 new AsyncCallback<Artifact>() { |
126 public void onFailure(Throwable caught) { | 169 public void onFailure(Throwable caught) { |
170 decreateInProgress(); | |
127 SC.warn(caught.getMessage()); | 171 SC.warn(caught.getMessage()); |
128 } | 172 } |
129 | 173 |
130 public void onSuccess(Artifact artifact) { | 174 public void onSuccess(Artifact artifact) { |
175 decreateInProgress(); | |
131 GWT.log("Created new artifact: " + artifact.getUuid()); | 176 GWT.log("Created new artifact: " + artifact.getUuid()); |
132 } | 177 } |
133 }); | 178 }); |
134 } | 179 } |
135 } | 180 } |