comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationListGrid.java @ 8313:e3a63d9c5bb1

Updated the client to build a default artifact for sq relations. * Removed code for special sq relation artifact * Updated MeasurementListGrid in info panel to create a new project * Updated i18n
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 24 Sep 2014 12:02:05 +0200
parents 2c20907f8dd0
children a201d475e50d
comparison
equal deleted inserted replaced
8312:9f5059f4f01a 8313:e3a63d9c5bb1
7 */ 7 */
8 8
9 package org.dive4elements.river.client.client.ui.stationinfo; 9 package org.dive4elements.river.client.client.ui.stationinfo;
10 10
11 import com.google.gwt.core.client.GWT; 11 import com.google.gwt.core.client.GWT;
12 12 import com.google.gwt.user.client.rpc.AsyncCallback;
13
14 import com.smartgwt.client.util.SC;
13 import com.smartgwt.client.widgets.Canvas; 15 import com.smartgwt.client.widgets.Canvas;
14 import com.smartgwt.client.widgets.grid.ListGridField; 16 import com.smartgwt.client.widgets.grid.ListGridField;
15 import com.smartgwt.client.widgets.grid.ListGridRecord; 17 import com.smartgwt.client.widgets.grid.ListGridRecord;
16 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; 18 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
17 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; 19 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
18 20
21 import org.dive4elements.river.client.client.Config;
19 import org.dive4elements.river.client.client.FLYS; 22 import org.dive4elements.river.client.client.FLYS;
23 import org.dive4elements.river.client.client.services.ArtifactService;
24 import org.dive4elements.river.client.client.services.ArtifactServiceAsync;
25 import org.dive4elements.river.client.client.services.CreateCollectionService;
26 import org.dive4elements.river.client.client.services.CreateCollectionServiceAsync;
27 import org.dive4elements.river.client.client.services.StepForwardService;
28 import org.dive4elements.river.client.client.services.StepForwardServiceAsync;
29 import org.dive4elements.river.client.client.ui.CollectionView;
30 import org.dive4elements.river.client.shared.model.Artifact;
31 import org.dive4elements.river.client.shared.model.Collection;
32 import org.dive4elements.river.client.shared.model.Data;
33 import org.dive4elements.river.client.shared.model.DataItem;
34 import org.dive4elements.river.client.shared.model.DefaultData;
35 import org.dive4elements.river.client.shared.model.DefaultDataItem;
20 import org.dive4elements.river.client.shared.model.MeasurementStation; 36 import org.dive4elements.river.client.shared.model.MeasurementStation;
21 import org.dive4elements.river.client.shared.model.RiverInfo; 37 import org.dive4elements.river.client.shared.model.RiverInfo;
22 38
23 import java.util.ArrayList; 39 import java.util.ArrayList;
24 import java.util.List; 40 import java.util.List;
27 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> 43 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
28 */ 44 */
29 public class MeasurementStationListGrid 45 public class MeasurementStationListGrid
30 extends InfoListGrid 46 extends InfoListGrid
31 implements RecordClickHandler { 47 implements RecordClickHandler {
48
49 /** The ArtifactService used to communicate with the Artifact server. */
50 protected ArtifactServiceAsync artifactService =
51 GWT.create(ArtifactService.class);
52
53 /** The StepForwardService used to put data into an existing artifact. */
54 protected StepForwardServiceAsync forwardService =
55 GWT.create(StepForwardService.class);
56
57 /** The ArtifactService used to communicate with the Artifact server. */
58 protected CreateCollectionServiceAsync createCollectionService =
59 GWT.create(CreateCollectionService.class);
32 60
33 public MeasurementStationListGrid(FLYS flys) { 61 public MeasurementStationListGrid(FLYS flys) {
34 super(flys); 62 super(flys);
35 ListGridField nfield = new ListGridField("name", "Messtelle"); 63 ListGridField nfield = new ListGridField("name", "Messtelle");
36 ListGridField mfield = new ListGridField("measurementtype", "Messstellenart"); 64 ListGridField mfield = new ListGridField("measurementtype", "Messstellenart");
107 return new MeasurementStationInfoPanel(station); 135 return new MeasurementStationInfoPanel(station);
108 } 136 }
109 137
110 @Override 138 @Override
111 public void onRecordClick(RecordClickEvent event) { 139 public void onRecordClick(RecordClickEvent event) {
112 MeasurementStationRecord station = 140 final MeasurementStationRecord station =
113 (MeasurementStationRecord)event.getRecord(); 141 (MeasurementStationRecord)event.getRecord();
114 flys.newSQRelation(station.getRiverName(), station.getID()); 142 Config config = Config.getInstance();
143 final String locale = config.getLocale();
144 createCollectionService.create(
145 locale,
146 flys.getCurrentUser().identifier(),
147 new AsyncCallback<Collection>() {
148 @Override
149 public void onFailure(Throwable caught) {
150 GWT.log("Could not create the new collection.");
151 SC.warn(FLYS.getExceptionString(MSG, caught));
152 }
153
154 @Override
155 public void onSuccess(Collection collection) {
156 GWT.log("Successfully created a new collection.");
157 createArtifact(collection, locale, station);
158 }
159 }
160 );
161 }
162
163 private void createArtifact(
164 final Collection collection,
165 final String locale,
166 final MeasurementStationRecord station
167 ) {
168 artifactService.create(
169 locale, "staticsqrelation", null,
170 new AsyncCallback<Artifact>() {
171 @Override
172 public void onFailure(Throwable caught) {
173 GWT.log("Could not create the new artifact.");
174 SC.warn(FLYS.getExceptionString(MSG, caught));
175 }
176
177 @Override
178 public void onSuccess(Artifact artifact) {
179 GWT.log("Successfully created a new artifact.");
180
181 DataItem riverItem = new DefaultDataItem(
182 "river",
183 "river",
184 station.getRiverName());
185 Data river = new DefaultData(
186 "river",
187 null,
188 null,
189 new DataItem[]{riverItem});
190
191 DataItem refItem = new DefaultDataItem(
192 "station",
193 "station",
194 station.getID().toString());
195 Data ref = new DefaultData(
196 "station",
197 null,
198 null,
199 new DataItem[]{refItem});
200
201 DataItem nameItem = new DefaultDataItem(
202 "station_name",
203 "station_name",
204 station.getID().toString());
205 Data name = new DefaultData(
206 "station_name",
207 null,
208 null,
209 new DataItem[]{nameItem});
210
211 Data[] data = new Data[]{river, ref, name};
212 forwardService.go(locale, artifact, data,
213 new AsyncCallback<Artifact>() {
214 @Override
215 public void onFailure(Throwable caught) {
216 GWT.log("Could not feed the artifact.");
217 SC.warn(caught.getMessage());
218 }
219
220 @Override
221 public void onSuccess(Artifact artifact) {
222 GWT.log("Successfully feed the artifact.");
223 CollectionView view = new CollectionView(
224 flys,
225 collection,
226 artifact);
227 flys.getWorkspace().addView(
228 collection.identifier(),
229 view);
230 view.addArtifactToCollection(artifact);
231 }
232 });
233 }
234 });
115 } 235 }
116 236
117 @Override 237 @Override
118 public String getCellCSSText(ListGridRecord record, int rowNum, 238 public String getCellCSSText(ListGridRecord record, int rowNum,
119 int colNum) { 239 int colNum) {

http://dive4elements.wald.intevation.org