Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java @ 1561:3cf3cd8dd92d
Made manual points edit- and removable.
flys-client/trunk@3807 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 27 Jan 2012 15:24:04 +0000 |
parents | 9ad19e31d149 |
children | af29d43cf4da |
comparison
equal
deleted
inserted
replaced
1560:1c47de6ccfb1 | 1561:3cf3cd8dd92d |
---|---|
16 import com.smartgwt.client.widgets.Label; | 16 import com.smartgwt.client.widgets.Label; |
17 import com.smartgwt.client.widgets.Canvas; | 17 import com.smartgwt.client.widgets.Canvas; |
18 import com.smartgwt.client.widgets.grid.ListGrid; | 18 import com.smartgwt.client.widgets.grid.ListGrid; |
19 import com.smartgwt.client.widgets.grid.ListGridField; | 19 import com.smartgwt.client.widgets.grid.ListGridField; |
20 import com.smartgwt.client.widgets.grid.ListGridRecord; | 20 import com.smartgwt.client.widgets.grid.ListGridRecord; |
21 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | |
22 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | |
21 import com.smartgwt.client.types.ListGridFieldType; | 23 import com.smartgwt.client.types.ListGridFieldType; |
22 | 24 |
23 import com.smartgwt.client.widgets.form.DynamicForm; | 25 import com.smartgwt.client.widgets.form.DynamicForm; |
24 | 26 |
25 import com.smartgwt.client.widgets.events.ClickEvent; | 27 import com.smartgwt.client.widgets.events.ClickEvent; |
141 Config config = Config.getInstance(); | 143 Config config = Config.getInstance(); |
142 | 144 |
143 Button accept = new Button(MSG.label_ok()); | 145 Button accept = new Button(MSG.label_ok()); |
144 Button cancel = new Button(MSG.label_cancel()); | 146 Button cancel = new Button(MSG.label_cancel()); |
145 cancel.addClickHandler(this); | 147 cancel.addClickHandler(this); |
148 | |
149 // TODO refactor. | |
146 accept.addClickHandler(new ClickHandler() { | 150 accept.addClickHandler(new ClickHandler() { |
147 public void onClick(ClickEvent e) { | 151 public void onClick(ClickEvent e) { |
148 if(isDialogValid()) { | 152 if(isDialogValid()) { |
149 // Feed JSON-encoded content of listgrid. | 153 // Feed JSON-encoded content of listgrid. |
150 String jsonString = ""; | 154 String jsonString = ""; |
165 } | 169 } |
166 else { | 170 else { |
167 JSONArray data = new JSONArray(); | 171 JSONArray data = new JSONArray(); |
168 | 172 |
169 // TODO better get double directly (via cell-formatter etc) | 173 // TODO better get double directly (via cell-formatter etc) |
174 // TODO finalize the X, Y etc. | |
170 String xString = record.getAttributeAsString("X"); | 175 String xString = record.getAttributeAsString("X"); |
171 String yString = record.getAttributeAsString("Y"); | 176 String yString = record.getAttributeAsString("Y"); |
172 String nameString = record.getAttributeAsString("name"); | 177 String nameString = record.getAttributeAsString("name"); |
173 if (nameString == null || nameString.equals("")) { | 178 if (nameString == null || nameString.equals("")) { |
174 nameString = xString + "/" + yString; | 179 nameString = xString + "/" + yString; |
198 SC.warn(MSG.getString(caught.getMessage())); | 203 SC.warn(MSG.getString(caught.getMessage())); |
199 enable(); | 204 enable(); |
200 } | 205 } |
201 public void onSuccess(Artifact fartifact) { | 206 public void onSuccess(Artifact fartifact) { |
202 GWT.log("Successfully set points "); | 207 GWT.log("Successfully set points "); |
203 // TODO refresh collection such that next time | |
204 // the new points are shown. | |
205 //requestRedraw(); | |
206 //updateCollection(); | |
207 //updateGrid(); | |
208 //enable(); | |
209 redrawRequestHandler.onRedrawRequest( | 208 redrawRequestHandler.onRedrawRequest( |
210 new RedrawRequestEvent(Type.DEFAULT)); | 209 new RedrawRequestEvent()); |
211 destroy(); | 210 destroy(); |
212 } | 211 } |
213 }); | 212 }); |
214 } | 213 } |
215 else { | 214 else { |
227 | 226 |
228 VLayout layout = new VLayout(); | 227 VLayout layout = new VLayout(); |
229 listGrid = new ListGrid(); | 228 listGrid = new ListGrid(); |
230 listGrid.setWidth100(); | 229 listGrid.setWidth100(); |
231 listGrid.setHeight(200); | 230 listGrid.setHeight(200); |
231 listGrid.setCanSort(false); | |
232 listGrid.setCanEdit(true); | |
233 listGrid.setShowHeaderContextMenu(false); | |
234 | |
232 // TODO X and Y Header depend on the current chart and axis (e.g. W[nn+m]) | 235 // TODO X and Y Header depend on the current chart and axis (e.g. W[nn+m]) |
236 // collection.getSettings(outputName).getSettings -> Propertie -> "axis" -> "label" | |
233 ListGridField xField = new ListGridField("X", "X"); | 237 ListGridField xField = new ListGridField("X", "X"); |
234 xField.setType(ListGridFieldType.FLOAT); | 238 xField.setType(ListGridFieldType.FLOAT); |
235 ListGridField yField = new ListGridField("Y", "Y"); | 239 ListGridField yField = new ListGridField("Y", "Y"); |
236 yField.setType(ListGridFieldType.FLOAT); | 240 yField.setType(ListGridFieldType.FLOAT); |
237 ListGridField nameField = new ListGridField("name", | 241 ListGridField nameField = new ListGridField("name", |
238 MSG.pointname()); | 242 MSG.pointname()); |
239 ListGridField removeField = new ListGridField("remove", | 243 final ListGridField removeField = |
240 MSG.removepoint()); | 244 new ListGridField("_removeRecord", MSG.removepoint()){{ |
245 setType(ListGridFieldType.ICON); | |
246 setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); | |
247 setCanEdit(false); | |
248 setCanFilter(false); | |
249 setCanSort(false); | |
250 setCanGroupBy(false); | |
251 setCanFreeze(false); | |
252 setWidth(25); | |
253 }}; | |
254 | |
241 listGrid.setFields(new ListGridField[] {xField, yField, | 255 listGrid.setFields(new ListGridField[] {xField, yField, |
242 nameField, removeField}); | 256 nameField, removeField}); |
257 | |
258 listGrid.addRecordClickHandler(new RecordClickHandler() { | |
259 public void onRecordClick(final RecordClickEvent event) { | |
260 // Just handle remove-clicks | |
261 if(!event.getField().getName().equals(removeField.getName())) { | |
262 return; | |
263 } | |
264 event.getViewer().removeData(event.getRecord()); | |
265 } | |
266 }); | |
243 | 267 |
244 // Find the artifacts uuid. | 268 // Find the artifacts uuid. |
245 findManualPointsUUID(); | 269 findManualPointsUUID(); |
246 CollectionItem item = collection.getItem(uuid); | 270 CollectionItem item = collection.getItem(uuid); |
247 | 271 |
331 /** Simple record to store points. */ | 355 /** Simple record to store points. */ |
332 public class PointRecord extends ListGridRecord { | 356 public class PointRecord extends ListGridRecord { |
333 protected static final String ATTRIBUTE_X = "X"; | 357 protected static final String ATTRIBUTE_X = "X"; |
334 protected static final String ATTRIBUTE_Y = "Y"; | 358 protected static final String ATTRIBUTE_Y = "Y"; |
335 protected static final String ATTRIBUTE_NAME = "name"; | 359 protected static final String ATTRIBUTE_NAME = "name"; |
336 | 360 protected static final String ATTRIBUTE_ACTIVE = "active"; |
337 String name; | |
338 double x; | |
339 double y; | |
340 | 361 |
341 private PointRecord() {;} | 362 private PointRecord() {;} |
342 | 363 |
343 public PointRecord(double x, double y, String name) { | 364 public PointRecord(double x, double y, String name) { |
344 setName(name); | 365 setName(name); |
345 setX(x); | 366 setX(x); |
346 setY(y); | 367 setY(y); |
347 } | 368 } |
348 | 369 |
370 public void setActive(boolean b) { | |
371 setAttribute(ATTRIBUTE_ACTIVE, b); | |
372 } | |
373 | |
374 public boolean isActive() { | |
375 return getAttributeAsBoolean(ATTRIBUTE_ACTIVE); | |
376 } | |
377 | |
349 public void setName(String name) { | 378 public void setName(String name) { |
350 this.name = name; | 379 setAttribute(ATTRIBUTE_NAME, name); |
351 setAttribute(ATTRIBUTE_NAME, getName()); | |
352 } | 380 } |
353 | 381 |
354 public String getName() { | 382 public String getName() { |
355 return this.name; | 383 return getAttributeAsString(ATTRIBUTE_NAME); |
356 } | 384 } |
357 | 385 |
358 public void setX(double x) { | 386 public void setX(double x) { |
359 this.x = x; | 387 setAttribute(ATTRIBUTE_X, x); |
360 setAttribute(ATTRIBUTE_X, getX()); | |
361 } | 388 } |
362 | 389 |
363 public void setY(double y) { | 390 public void setY(double y) { |
364 this.y = y; | 391 setAttribute(ATTRIBUTE_Y, y); |
365 setAttribute(ATTRIBUTE_Y, getY()); | |
366 } | 392 } |
367 | 393 |
368 public double getX() { | 394 public double getX() { |
369 return this.x; | 395 return getAttributeAsDouble(ATTRIBUTE_X); |
370 } | 396 } |
371 | 397 |
372 public double getY() { | 398 public double getY() { |
373 return this.y; | 399 return getAttributeAsDouble(ATTRIBUTE_Y); |
374 } | 400 } |
375 } | 401 } |
376 | 402 |
377 | 403 |
378 // TODO validate entered values (CellFormatter). | 404 // TODO validate entered values (CellFormatter). |