comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java @ 5312:2c1045a1e3fe

Added new states and transitions to UESK calculation and adjusted states and UI. TODO: Some refactoring and code cleanup.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 14 Mar 2013 17:25:00 +0100
parents 4bf3b89b38d5
children ef32ab3c1679
comparison
equal deleted inserted replaced
5311:ff9dfc58d0cb 5312:2c1045a1e3fe
1 package de.intevation.flys.client.client.ui; 1 package de.intevation.flys.client.client.ui;
2
3 import java.util.List;
4
5 import org.gwtopenmaps.openlayers.client.Map;
6 import org.gwtopenmaps.openlayers.client.control.Attribution;
7 import org.gwtopenmaps.openlayers.client.layer.WMS;
8 import org.gwtopenmaps.openlayers.client.layer.WMSOptions;
9 import org.gwtopenmaps.openlayers.client.layer.WMSParams;
2 10
3 import com.google.gwt.core.client.GWT; 11 import com.google.gwt.core.client.GWT;
4 import com.google.gwt.user.client.rpc.AsyncCallback; 12 import com.google.gwt.user.client.rpc.AsyncCallback;
5
6 import com.smartgwt.client.types.Encoding;
7 import com.smartgwt.client.types.VerticalAlignment; 13 import com.smartgwt.client.types.VerticalAlignment;
8 import com.smartgwt.client.util.SC; 14 import com.smartgwt.client.util.SC;
9 import com.smartgwt.client.widgets.Button;
10 import com.smartgwt.client.widgets.Canvas; 15 import com.smartgwt.client.widgets.Canvas;
11 import com.smartgwt.client.widgets.HTMLPane;
12 import com.smartgwt.client.widgets.Label; 16 import com.smartgwt.client.widgets.Label;
13 import com.smartgwt.client.widgets.events.ClickEvent;
14 import com.smartgwt.client.widgets.events.ClickHandler;
15 import com.smartgwt.client.widgets.events.VisibilityChangedEvent; 17 import com.smartgwt.client.widgets.events.VisibilityChangedEvent;
16 import com.smartgwt.client.widgets.events.VisibilityChangedHandler; 18 import com.smartgwt.client.widgets.events.VisibilityChangedHandler;
17 import com.smartgwt.client.widgets.form.DynamicForm;
18 import com.smartgwt.client.widgets.form.fields.SelectItem;
19 import com.smartgwt.client.widgets.form.fields.UploadItem;
20 import com.smartgwt.client.widgets.layout.VLayout; 19 import com.smartgwt.client.widgets.layout.VLayout;
21 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; 20 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent;
22 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; 21 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler;
23 22
24 import de.intevation.flys.client.client.Config; 23 import de.intevation.flys.client.client.Config;
33 import de.intevation.flys.client.shared.model.DataList; 32 import de.intevation.flys.client.shared.model.DataList;
34 import de.intevation.flys.client.shared.model.DefaultData; 33 import de.intevation.flys.client.shared.model.DefaultData;
35 import de.intevation.flys.client.shared.model.DefaultDataItem; 34 import de.intevation.flys.client.shared.model.DefaultDataItem;
36 import de.intevation.flys.client.shared.model.MapInfo; 35 import de.intevation.flys.client.shared.model.MapInfo;
37 36
38 import java.util.LinkedHashMap;
39 import java.util.List;
40
41 import org.gwtopenmaps.openlayers.client.Map;
42 import org.gwtopenmaps.openlayers.client.control.Attribution;
43 import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
44 import org.gwtopenmaps.openlayers.client.format.GeoJSON;
45 import org.gwtopenmaps.openlayers.client.layer.WMS;
46 import org.gwtopenmaps.openlayers.client.layer.WMSOptions;
47 import org.gwtopenmaps.openlayers.client.layer.WMSParams;
48
49 37
50 public class DigitizePanel 38 public class DigitizePanel
51 extends SelectProvider 39 extends SelectProvider
52 implements TabSelectedHandler, VisibilityChangedHandler { 40 implements TabSelectedHandler, VisibilityChangedHandler {
53 41
69 57
70 58
71 @Override 59 @Override
72 public Canvas create(DataList list) { 60 public Canvas create(DataList list) {
73 List<Data> data = list.getAll(); 61 List<Data> data = list.getAll();
74
75 helperContainer.addVisibilityChangedHandler(this); 62 helperContainer.addVisibilityChangedHandler(this);
76
77 Data barriers = null;
78 for (int i = data.size()-1; i >= 0; i--) {
79 Data d = data.get(i);
80 if (d.getLabel().equals(UESK_BARRIERS)) {
81 barriers = d;
82 data.remove(d);
83 }
84 }
85 63
86 DataList clone = (DataList) list.clone(); 64 DataList clone = (DataList) list.clone();
87 List<Data> all = clone.getAll(); 65 List<Data> all = clone.getAll();
88 all.remove(UESK_BARRIERS); 66 all.remove(UESK_BARRIERS);
89 67
90 Canvas selectBox = super.create(clone); 68 Canvas widget = createWidget(list);
91 69
92 final Config cfg = Config.getInstance(); 70 final Config cfg = Config.getInstance();
93 final String locale = cfg.getLocale(); 71 final String locale = cfg.getLocale();
94
95 DataItem[] obj = barriers.getItems();
96
97 final String[] geojson = new String[1];
98 for (DataItem item: obj) {
99 if (item.getLabel().equals(UESK_BARRIERS)) {
100 geojson[0] = item.getStringValue();
101 break;
102 }
103 }
104 72
105 String river = getDataValue("state.winfo.river", "river"); 73 String river = getDataValue("state.winfo.river", "river");
106 mapInfo.getMapInfo(locale, river, new AsyncCallback<MapInfo>() { 74 mapInfo.getMapInfo(locale, river, new AsyncCallback<MapInfo>() {
107 @Override 75 @Override
108 public void onFailure(Throwable caught) { 76 public void onFailure(Throwable caught) {
112 SC.warn(FLYS.getExceptionString(MSG, caught)); 80 SC.warn(FLYS.getExceptionString(MSG, caught));
113 } 81 }
114 82
115 @Override 83 @Override
116 public void onSuccess(MapInfo info) { 84 public void onSuccess(MapInfo info) {
117 createMapWidget(info, geojson[0]); 85 createMapWidget(info);
118 } 86 }
119 }); 87 });
120 88
121 return selectBox; 89 return widget;
122 } 90 }
123 91
124 92
125 /** 93 /**
126 * This method creates the content of the widget. 94 * This method creates the content of the widget.
135 103
136 VLayout layout = new VLayout(); 104 VLayout layout = new VLayout();
137 layout.setAlign(VerticalAlignment.TOP); 105 layout.setAlign(VerticalAlignment.TOP);
138 layout.setHeight(25); 106 layout.setHeight(25);
139 107
140 LinkedHashMap<String, String> initial = new LinkedHashMap<String, String>();
141
142 form = new DynamicForm();
143
144 int size = data.size(); 108 int size = data.size();
145 109
146 for (int i = 0; i < size; i++) { 110 for (int i = 0; i < size; i++) {
147 Data d = data.get(i); 111 Data d = data.get(i);
148 112
149 Label label = new Label(d.getDescription()); 113 Label label = new Label(d.getDescription());
150 label.setValign(VerticalAlignment.TOP); 114 label.setValign(VerticalAlignment.TOP);
151 label.setHeight(20); 115 label.setHeight(20);
152 label.setWidth(400); 116 label.setWidth(400);
153 117
154 SelectItem combobox = new SelectItem(d.getLabel());
155 combobox.setWidth(250);
156
157 LinkedHashMap<String, String> it = new LinkedHashMap<String, String>();
158
159 boolean defaultSet = false;
160 boolean first = true;
161
162 DataItem def = d.getDefault();
163 String defValue = def != null ? def.getStringValue() : null;
164
165 if (defValue != null && defValue.length() > 0) {
166 initial.put(d.getLabel(), def.getStringValue());
167 defaultSet = true;
168 }
169
170 for (DataItem item: d.getItems()) {
171 if (!defaultSet && first) {
172 initial.put(d.getLabel(), item.getStringValue());
173 first = false;
174 }
175
176 it.put(item.getStringValue(), item.getLabel());
177 }
178
179 label.setWidth(50);
180 combobox.setValueMap(it);
181 combobox.setShowTitle(false);
182 form.setItems(combobox);
183
184 HTMLPane uploadTargetFrame = new HTMLPane();
185 uploadTargetFrame.setWidth("200px");
186 uploadTargetFrame.setHeight("50px");
187 uploadTargetFrame.setContents(
188 "<iframe id='uploadTarget' name='uploadTarget' scrolling='no' width=200 height=50 style='border: 0px'></iframe>");
189 uploadTargetFrame.setBorder("0px");
190 uploadTargetFrame.setScrollbarSize(0);
191
192 final DynamicForm uploadForm = new DynamicForm();
193 uploadForm.setAction("flys/fileupload?uuid=" + artifact.getUuid());
194 uploadForm.setTarget("uploadTarget");
195 uploadForm.setEncoding(Encoding.MULTIPART);
196 Label uploadLabel = new Label(MSG.shape_file_upload());
197 uploadLabel.setHeight(20);
198 UploadItem uploadItem = new UploadItem();
199 uploadItem.setShowTitle(false);
200 uploadForm.setFields(uploadItem);
201 Button submit = new Button(MSG.upload_file());
202 submit.addClickHandler(new ClickHandler() {
203 @Override
204 public void onClick(ClickEvent e) {
205 uploadForm.submitForm();
206 }
207 });
208
209 layout.addMember(label); 118 layout.addMember(label);
210 layout.addMember(form);
211 layout.addMember(uploadLabel);
212 layout.addMember(uploadForm);
213 layout.addMember(submit);
214 layout.addMember(getNextButton()); 119 layout.addMember(getNextButton());
215 120 }
216 layout.setMembersMargin(10);
217 layout.addMember(uploadTargetFrame);
218 }
219
220 form.setValues(initial);
221 121
222 layout.setAlign(VerticalAlignment.TOP); 122 layout.setAlign(VerticalAlignment.TOP);
223 123
224 return layout; 124 return layout;
225 } 125 }
226 126
227 127
228 @Override 128 @Override
229 protected Data[] getData() { 129 protected Data[] getData() {
230 Data[] data = super.getData(); 130 Data[] total = new Data[1];
231 Data[] total = new Data[2];
232 131
233 if (floodMap != null) { 132 if (floodMap != null) {
234 DataItem item = new DefaultDataItem( 133 DataItem item = new DefaultDataItem(
235 UESK_BARRIERS, UESK_BARRIERS, floodMap.getFeaturesAsGeoJSON()); 134 UESK_BARRIERS, UESK_BARRIERS, floodMap.getFeaturesAsGeoJSON());
236 total[0] = data[0]; 135 total[0] = new DefaultData(
237 total[1] = new DefaultData(
238 UESK_BARRIERS, null, null, new DataItem[] { item }); 136 UESK_BARRIERS, null, null, new DataItem[] { item });
239 } 137 }
240 else { 138 else {
241 // Happens when OpenLayers is missing 139 // Happens when OpenLayers is missing
242 GWT.log("floodMap is null -> OpenLayers missing?"); 140 GWT.log("floodMap is null -> OpenLayers missing?");
244 142
245 return total; 143 return total;
246 } 144 }
247 145
248 146
249 public void createMapWidget(MapInfo mapInfo, String geojson) { 147 public void createMapWidget(MapInfo mapInfo) {
250 mapPanel = new MapPanel(mapInfo, true); 148 mapPanel = new MapPanel(mapInfo, true);
251 149
252 floodMap = mapPanel.getFloodMap(); 150 floodMap = mapPanel.getFloodMap();
253 Map map = floodMap.getMap(); 151 Map map = floodMap.getMap();
254 152
264 mapInfo.getProjection(), false); 162 mapInfo.getProjection(), false);
265 163
266 map.addLayer(back); 164 map.addLayer(back);
267 map.addLayer(axis); 165 map.addLayer(axis);
268 166
269 if (geojson != null && geojson.length() > 0) { 167 String hws = getDataValue("state.winfo.uesk.dc-hws", "uesk.hws");
270 VectorFeature[] features = new GeoJSON().read(geojson); 168 if (hws != null && hws.length() > 0) {
271 floodMap.getBarrierLayer().addFeatures(features); 169 WMS hwsLayer = getLayer(
170 //TODO: Use Mapinfo to get hws layer infos.
171 mapInfo.getWmsUrl().replace("river", "user"),
172 "ms_layer-hws-lines" + artifact.getUuid(),
173 mapInfo.getProjection(),
174 false);
175 map.addLayer(hwsLayer);
176 }
177 String userRgd = getDataValue("state.winfo.uesk.user-rgd", "uesk.user-rgd");
178 if (userRgd != null && userRgd.length() > 0) {
179 WMS userLayer = getLayer(
180 //TODO: Use Mapinfo to get hws layer infos.
181 mapInfo.getWmsUrl().replace("river", "user"),
182 "ms_layer-user-rgd" + artifact.getUuid(),
183 mapInfo.getProjection(),
184 false);
185 map.addLayer(userLayer);
272 } 186 }
273 map.addControl(new Attribution()); 187 map.addControl(new Attribution());
274 map.zoomToMaxExtent(); 188 map.zoomToMaxExtent();
275 } 189 }
276 190

http://dive4elements.wald.intevation.org