Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java @ 1562:af29d43cf4da
Added basic validation, improved editing function, minor refac.
flys-client/trunk@3808 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 27 Jan 2012 15:43:02 +0000 |
parents | 3cf3cd8dd92d |
children | 41abc345d2f1 |
comparison
equal
deleted
inserted
replaced
1561:3cf3cd8dd92d | 1562:af29d43cf4da |
---|---|
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; | 21 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; |
22 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | 22 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; |
23 import com.smartgwt.client.types.ListGridFieldType; | 23 import com.smartgwt.client.types.ListGridFieldType; |
24 import com.smartgwt.client.widgets.grid.CellFormatter; | |
25 import com.google.gwt.i18n.client.NumberFormat; | |
24 | 26 |
25 import com.smartgwt.client.widgets.form.DynamicForm; | 27 import com.smartgwt.client.widgets.form.DynamicForm; |
26 | 28 |
27 import com.smartgwt.client.widgets.events.ClickEvent; | 29 import com.smartgwt.client.widgets.events.ClickEvent; |
28 import com.smartgwt.client.widgets.events.ClickHandler; | 30 import com.smartgwt.client.widgets.events.ClickHandler; |
168 idx++; | 170 idx++; |
169 } | 171 } |
170 else { | 172 else { |
171 JSONArray data = new JSONArray(); | 173 JSONArray data = new JSONArray(); |
172 | 174 |
173 // TODO better get double directly (via cell-formatter etc) | |
174 // TODO finalize the X, Y etc. | |
175 String xString = record.getAttributeAsString("X"); | |
176 String yString = record.getAttributeAsString("Y"); | |
177 String nameString = record.getAttributeAsString("name"); | 175 String nameString = record.getAttributeAsString("name"); |
176 // Apply default name if none set. | |
178 if (nameString == null || nameString.equals("")) { | 177 if (nameString == null || nameString.equals("")) { |
178 String xString = record.getAttributeAsString( | |
179 PointRecord.ATTRIBUTE_X); | |
180 String yString = record.getAttributeAsString( | |
181 PointRecord.ATTRIBUTE_Y); | |
179 nameString = xString + "/" + yString; | 182 nameString = xString + "/" + yString; |
180 } | 183 } |
181 | 184 |
182 data.set(0, new JSONNumber(Double.valueOf(xString))); | 185 data.set(0, new JSONNumber(record. |
183 data.set(1, new JSONNumber(Double.valueOf(yString))); | 186 getAttributeAsDouble(PointRecord.ATTRIBUTE_X))); |
187 data.set(1, new JSONNumber(record. | |
188 getAttributeAsDouble(PointRecord.ATTRIBUTE_Y))); | |
184 data.set(2, new JSONString(nameString)); | 189 data.set(2, new JSONString(nameString)); |
185 | 190 |
186 list.set(idx, data); | 191 list.set(idx, data); |
187 idx++; | 192 idx++; |
188 } | 193 } |
232 listGrid.setCanEdit(true); | 237 listGrid.setCanEdit(true); |
233 listGrid.setShowHeaderContextMenu(false); | 238 listGrid.setShowHeaderContextMenu(false); |
234 | 239 |
235 // TODO X and Y Header depend on the current chart and axis (e.g. W[nn+m]) | 240 // 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" | 241 // collection.getSettings(outputName).getSettings -> Propertie -> "axis" -> "label" |
237 ListGridField xField = new ListGridField("X", "X"); | 242 ListGridField xField = new ListGridField(PointRecord.ATTRIBUTE_X, "X"); |
238 xField.setType(ListGridFieldType.FLOAT); | 243 xField.setType(ListGridFieldType.FLOAT); |
239 ListGridField yField = new ListGridField("Y", "Y"); | 244 xField.setCellFormatter(new CellFormatter() { |
245 public String format(Object value, ListGridRecord record, int rowNum, int colNum) { | |
246 if(value != null) { | |
247 NumberFormat nf = NumberFormat.getFormat("#.##"); | |
248 try { | |
249 return nf.format(((Number) value).doubleValue()); | |
250 } catch (Exception e) { | |
251 return value.toString(); | |
252 } | |
253 } else { | |
254 return null; | |
255 } | |
256 }}); | |
257 ListGridField yField = new ListGridField(PointRecord.ATTRIBUTE_Y, "Y"); | |
240 yField.setType(ListGridFieldType.FLOAT); | 258 yField.setType(ListGridFieldType.FLOAT); |
241 ListGridField nameField = new ListGridField("name", | 259 ListGridField nameField = new ListGridField(PointRecord.ATTRIBUTE_NAME, |
242 MSG.pointname()); | 260 MSG.pointname()); |
243 final ListGridField removeField = | 261 final ListGridField removeField = |
244 new ListGridField("_removeRecord", MSG.removepoint()){{ | 262 new ListGridField("_removeRecord", MSG.removepoint()){{ |
245 setType(ListGridFieldType.ICON); | 263 setType(ListGridFieldType.ICON); |
246 setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); | 264 setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); |