Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageWindow.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageWindow.java@821a02bbfb4e |
children | 172338b1407f |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.client.client.ui; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import com.google.gwt.core.client.GWT; | |
7 import com.google.gwt.user.client.rpc.AsyncCallback; | |
8 | |
9 import com.smartgwt.client.util.SC; | |
10 import com.smartgwt.client.widgets.Window; | |
11 | |
12 import org.dive4elements.river.client.client.Config; | |
13 import org.dive4elements.river.client.client.FLYSConstants; | |
14 | |
15 import org.dive4elements.river.client.client.event.DatacageHandler; | |
16 import org.dive4elements.river.client.client.event.DatacageDoubleClickHandler; | |
17 import org.dive4elements.river.client.client.event.HasRedrawRequestHandlers; | |
18 import org.dive4elements.river.client.client.event.RedrawRequestHandler; | |
19 import org.dive4elements.river.client.client.event.RedrawRequestEvent; | |
20 import org.dive4elements.river.client.client.event.RedrawRequestEvent.Type; | |
21 | |
22 import org.dive4elements.river.client.client.services.LoadArtifactService; | |
23 import org.dive4elements.river.client.client.services.LoadArtifactServiceAsync; | |
24 | |
25 import org.dive4elements.river.client.shared.model.Artifact; | |
26 import org.dive4elements.river.client.shared.model.ArtifactDescription; | |
27 import org.dive4elements.river.client.shared.model.Collection; | |
28 import org.dive4elements.river.client.shared.model.Data; | |
29 import org.dive4elements.river.client.shared.model.DataItem; | |
30 import org.dive4elements.river.client.shared.model.DataList; | |
31 import org.dive4elements.river.client.shared.model.ToLoad; | |
32 import org.dive4elements.river.client.shared.model.User; | |
33 import org.dive4elements.river.client.shared.model.Recommendation; | |
34 | |
35 | |
36 /** Window that access the datacageservice and shows a datacagewidget. */ | |
37 public class DatacageWindow | |
38 extends Window | |
39 implements DatacageHandler, | |
40 DatacageDoubleClickHandler, | |
41 HasRedrawRequestHandlers | |
42 { | |
43 /** i18ner. */ | |
44 protected FLYSConstants messages = | |
45 GWT.create(FLYSConstants.class); | |
46 | |
47 /** Service to create/clone artifacts. */ | |
48 protected LoadArtifactServiceAsync loadService = | |
49 GWT.create(LoadArtifactService.class); | |
50 | |
51 protected CollectionView view; | |
52 | |
53 protected List<RedrawRequestHandler> handlers; | |
54 | |
55 protected int inProgress; | |
56 | |
57 | |
58 public DatacageWindow( | |
59 Artifact artifact, | |
60 User user, | |
61 String outs, | |
62 CollectionView view | |
63 ) { | |
64 this.view = view; | |
65 this.handlers = new ArrayList<RedrawRequestHandler>(); | |
66 this.inProgress = 0; | |
67 | |
68 setWidth(400); | |
69 setHeight(500); | |
70 | |
71 DatacageWidget dw = new DatacageWidget( | |
72 artifact, | |
73 user, | |
74 outs, | |
75 "load-system:true", | |
76 true); | |
77 dw.addDatacageHandler(this); | |
78 dw.addDatacageDoubleClickHandler(this); | |
79 | |
80 addItem(dw); | |
81 | |
82 String river = findRiver(artifact); | |
83 // TODO: i18n | |
84 setTitle("Datenkorb: " + river); | |
85 setShowMinimizeButton(false); | |
86 setIsModal(true); | |
87 setShowModalMask(true); | |
88 setCanDragResize(true); | |
89 | |
90 centerInPage(); | |
91 } | |
92 | |
93 | |
94 @Override | |
95 public void toLoad(ToLoad toLoad) { | |
96 destroy(); | |
97 List<Recommendation> recs = toLoad.toRecommendations(); | |
98 loadArtifacts(recs); | |
99 } | |
100 | |
101 | |
102 @Override | |
103 public void onDoubleClick(ToLoad toLoad) { | |
104 destroy(); | |
105 List<Recommendation> recs = toLoad.toRecommendations(); | |
106 loadArtifacts(recs); | |
107 } | |
108 | |
109 | |
110 @Override | |
111 public void addRedrawRequestHandler(RedrawRequestHandler handler) { | |
112 if (handler != null) { | |
113 handlers.add(handler); | |
114 } | |
115 } | |
116 | |
117 | |
118 protected String findRiver(Artifact artifact) { | |
119 ArtifactDescription adescr = artifact.getArtifactDescription(); | |
120 DataList [] data = adescr.getOldData(); | |
121 | |
122 if (data != null && data.length > 0) { | |
123 for (int i = 0; i < data.length; i++) { | |
124 DataList dl = data[i]; | |
125 if (dl.getState().equals("state.winfo.river")) { | |
126 for (int j = dl.size()-1; j >= 0; --j) { | |
127 Data d = dl.get(j); | |
128 DataItem [] di = d.getItems(); | |
129 if (di != null && di.length == 1) { | |
130 return d.getItems()[0].getStringValue(); | |
131 } | |
132 } | |
133 } | |
134 } | |
135 } | |
136 | |
137 return ""; | |
138 } | |
139 | |
140 | |
141 protected void decreateInProgress() { | |
142 if (this.inProgress > 0) { | |
143 this.inProgress--; | |
144 } | |
145 | |
146 if (this.inProgress == 0) { | |
147 fireRedrawRequest(); | |
148 } | |
149 } | |
150 | |
151 | |
152 protected void fireRedrawRequest() { | |
153 RedrawRequestEvent evt = new RedrawRequestEvent(Type.DEFAULT); | |
154 | |
155 for (RedrawRequestHandler handler: handlers) { | |
156 handler.onRedrawRequest(evt); | |
157 } | |
158 } | |
159 | |
160 | |
161 protected void loadArtifacts(List<Recommendation> recommendations) { | |
162 Config cfg = Config.getInstance(); | |
163 | |
164 final Collection collection = view.getCollection(); | |
165 final Artifact masterArtifact = view.getArtifact(); | |
166 final String locale = cfg.getLocale(); | |
167 | |
168 this.inProgress = recommendations.size(); | |
169 | |
170 for (final Recommendation recommendation: recommendations) { | |
171 // XXX: UGLY! If no reference artifact given use uuid of | |
172 // current artifact as reference. | |
173 if (recommendation.getMasterArtifact() == null) { | |
174 recommendation.setMasterArtifact(masterArtifact.getUuid()); | |
175 } | |
176 | |
177 final String factory = recommendation.getFactory(); | |
178 | |
179 GWT.log("Load new artifact with factory: " + factory); | |
180 | |
181 loadService.load( | |
182 collection, | |
183 recommendation, | |
184 factory, | |
185 locale, | |
186 new AsyncCallback<Artifact>() { | |
187 public void onFailure(Throwable caught) { | |
188 decreateInProgress(); | |
189 GWT.log("Create-artifact failed: " + caught.getMessage()); | |
190 SC.warn(caught.getMessage()); | |
191 } | |
192 | |
193 public void onSuccess(Artifact artifact) { | |
194 decreateInProgress(); | |
195 GWT.log("Created new artifact: " + artifact.getUuid()); | |
196 } | |
197 }); | |
198 } | |
199 } | |
200 } | |
201 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |