Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualDatePointsEditor.java @ 4568:bbd82bd8e541
flys-client: Cosmetics and warnings.
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Mon, 19 Nov 2012 00:07:53 +0100 |
parents | 51ed89b754ae |
children | e70ff0a600a3 |
comparison
equal
deleted
inserted
replaced
4567:5e6e89f19a37 | 4568:bbd82bd8e541 |
---|---|
1 package de.intevation.flys.client.client.ui.chart; | 1 package de.intevation.flys.client.client.ui.chart; |
2 | 2 |
3 import java.util.List; | 3 import com.google.gwt.core.client.GWT; |
4 import java.util.Date; | 4 import com.google.gwt.i18n.client.DateTimeFormat; |
5 | 5 import com.google.gwt.i18n.client.NumberFormat; |
6 import com.google.gwt.json.client.JSONArray; | 6 import com.google.gwt.json.client.JSONArray; |
7 import com.google.gwt.json.client.JSONBoolean; | 7 import com.google.gwt.json.client.JSONBoolean; |
8 import com.google.gwt.json.client.JSONNumber; | 8 import com.google.gwt.json.client.JSONNumber; |
9 import com.google.gwt.json.client.JSONParser; | 9 import com.google.gwt.json.client.JSONParser; |
10 import com.google.gwt.json.client.JSONString; | 10 import com.google.gwt.json.client.JSONString; |
11 import com.google.gwt.core.client.GWT; | 11 |
12 import com.google.gwt.i18n.client.DateTimeFormat; | 12 import com.smartgwt.client.types.Alignment; |
13 | 13 import com.smartgwt.client.types.ListGridFieldType; |
14 import com.smartgwt.client.util.SC; | 14 import com.smartgwt.client.util.SC; |
15 import com.smartgwt.client.widgets.layout.VLayout; | 15 import com.smartgwt.client.widgets.Button; |
16 import com.smartgwt.client.widgets.layout.HLayout; | |
17 import com.smartgwt.client.widgets.IButton; | 16 import com.smartgwt.client.widgets.IButton; |
18 import com.smartgwt.client.widgets.Button; | 17 import com.smartgwt.client.widgets.events.ClickEvent; |
18 import com.smartgwt.client.widgets.events.ClickHandler; | |
19 import com.smartgwt.client.widgets.grid.CellEditValueFormatter; | |
20 import com.smartgwt.client.widgets.grid.CellEditValueParser; | |
21 import com.smartgwt.client.widgets.grid.CellFormatter; | |
19 import com.smartgwt.client.widgets.grid.ListGrid; | 22 import com.smartgwt.client.widgets.grid.ListGrid; |
20 import com.smartgwt.client.widgets.grid.ListGridField; | 23 import com.smartgwt.client.widgets.grid.ListGridField; |
21 import com.smartgwt.client.widgets.grid.ListGridRecord; | 24 import com.smartgwt.client.widgets.grid.ListGridRecord; |
22 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | 25 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; |
23 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | 26 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; |
24 import com.smartgwt.client.types.ListGridFieldType; | 27 import com.smartgwt.client.widgets.layout.HLayout; |
25 import com.smartgwt.client.widgets.grid.CellFormatter; | 28 import com.smartgwt.client.widgets.layout.VLayout; |
26 import com.google.gwt.i18n.client.NumberFormat; | 29 |
27 | 30 import de.intevation.flys.client.client.event.RedrawRequestHandler; |
28 import com.smartgwt.client.widgets.grid.CellEditValueParser; | |
29 import com.smartgwt.client.widgets.grid.CellEditValueFormatter; | |
30 import com.smartgwt.client.widgets.events.ClickEvent; | |
31 import com.smartgwt.client.widgets.events.ClickHandler; | |
32 | |
33 import com.smartgwt.client.types.Alignment; | |
34 | |
35 import de.intevation.flys.client.client.Config; | |
36 import de.intevation.flys.client.shared.model.Collection; | 31 import de.intevation.flys.client.shared.model.Collection; |
37 import de.intevation.flys.client.shared.model.CollectionItem; | 32 import de.intevation.flys.client.shared.model.CollectionItem; |
38 | |
39 import de.intevation.flys.client.shared.model.Settings; | |
40 import de.intevation.flys.client.shared.model.Property; | 33 import de.intevation.flys.client.shared.model.Property; |
41 import de.intevation.flys.client.shared.model.PropertyGroup; | 34 import de.intevation.flys.client.shared.model.PropertyGroup; |
35 import de.intevation.flys.client.shared.model.Settings; | |
42 import de.intevation.flys.client.shared.model.StringProperty; | 36 import de.intevation.flys.client.shared.model.StringProperty; |
43 | 37 |
44 import de.intevation.flys.client.client.event.RedrawRequestHandler; | 38 import java.util.Date; |
39 import java.util.List; | |
45 | 40 |
46 /** | 41 /** |
47 * UI to enter point data and save it to an PointArtifact. | 42 * UI to enter point data and save it to an PointArtifact. |
48 */ | 43 */ |
49 public class ManualDatePointsEditor | 44 public class ManualDatePointsEditor |
56 super (collection, handler, outputModeName); | 51 super (collection, handler, outputModeName); |
57 } | 52 } |
58 | 53 |
59 | 54 |
60 /** Create and setup/add the ui. */ | 55 /** Create and setup/add the ui. */ |
56 @Override | |
61 public void createUI() { | 57 public void createUI() { |
62 Config config = Config.getInstance(); | |
63 | |
64 Button accept = new Button(MSG.label_ok()); | 58 Button accept = new Button(MSG.label_ok()); |
65 Button cancel = new Button(MSG.label_cancel()); | 59 Button cancel = new Button(MSG.label_cancel()); |
66 cancel.addClickHandler(this); | 60 cancel.addClickHandler(this); |
67 | 61 |
68 accept.addClickHandler(new ClickHandler() { | 62 accept.addClickHandler(new ClickHandler() { |
63 @Override | |
69 public void onClick(ClickEvent e) { | 64 public void onClick(ClickEvent e) { |
70 okClicked(); | 65 okClicked(); |
71 } | 66 } |
72 }); | 67 }); |
73 | 68 |
84 listGrid.setCanSort(false); | 79 listGrid.setCanSort(false); |
85 listGrid.setCanEdit(true); | 80 listGrid.setCanEdit(true); |
86 listGrid.setShowHeaderContextMenu(false); | 81 listGrid.setShowHeaderContextMenu(false); |
87 | 82 |
88 CellFormatter doubleFormat = new CellFormatter() { | 83 CellFormatter doubleFormat = new CellFormatter() { |
84 @Override | |
89 public String format(Object value, ListGridRecord record, int rowNum, int colNum) { | 85 public String format(Object value, ListGridRecord record, int rowNum, int colNum) { |
90 if(value != null) { | 86 if(value != null) { |
91 NumberFormat nf = NumberFormat.getDecimalFormat(); | 87 NumberFormat nf = NumberFormat.getDecimalFormat(); |
92 try { | 88 try { |
93 double d = Double.valueOf(value.toString()).doubleValue(); | 89 double d = Double.valueOf(value.toString()).doubleValue(); |
99 return null; | 95 return null; |
100 } | 96 } |
101 }}; | 97 }}; |
102 | 98 |
103 CellFormatter dateFormat = new CellFormatter() { | 99 CellFormatter dateFormat = new CellFormatter() { |
100 @Override | |
104 public String format(Object value, ListGridRecord record, int rowNum, int colNum) { | 101 public String format(Object value, ListGridRecord record, int rowNum, int colNum) { |
105 if(value != null && !value.toString().equals("")) { | 102 if(value != null && !value.toString().equals("")) { |
106 try { | 103 try { |
107 DateTimeFormat df = | 104 DateTimeFormat df = |
108 DateTimeFormat.getFormat("dd.MM.yyyy"); | 105 DateTimeFormat.getFormat("dd.MM.yyyy"); |
124 } | 121 } |
125 }}; | 122 }}; |
126 | 123 |
127 | 124 |
128 CellEditValueParser cevp = new CellEditValueParser() { | 125 CellEditValueParser cevp = new CellEditValueParser() { |
126 @Override | |
129 public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) { | 127 public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) { |
130 if (value == null) | 128 if (value == null) |
131 return null; | 129 return null; |
132 try { | 130 try { |
133 NumberFormat nf = NumberFormat.getDecimalFormat(); | 131 NumberFormat nf = NumberFormat.getDecimalFormat(); |
139 } | 137 } |
140 } | 138 } |
141 }; | 139 }; |
142 | 140 |
143 CellEditValueFormatter cevf = new CellEditValueFormatter() { | 141 CellEditValueFormatter cevf = new CellEditValueFormatter() { |
142 @Override | |
144 public Object format(Object value, ListGridRecord record, int rowNum, int colNum) { | 143 public Object format(Object value, ListGridRecord record, int rowNum, int colNum) { |
145 if (value != null) { | 144 if (value != null) { |
146 NumberFormat nf = NumberFormat.getDecimalFormat(); | 145 NumberFormat nf = NumberFormat.getDecimalFormat(); |
147 try { | 146 try { |
148 double d = Double.valueOf(value.toString()).doubleValue(); | 147 double d = Double.valueOf(value.toString()).doubleValue(); |
212 | 211 |
213 listGrid.setFields(new ListGridField[] {activeField, xField, yField, | 212 listGrid.setFields(new ListGridField[] {activeField, xField, yField, |
214 nameField, removeField}); | 213 nameField, removeField}); |
215 | 214 |
216 listGrid.addRecordClickHandler(new RecordClickHandler() { | 215 listGrid.addRecordClickHandler(new RecordClickHandler() { |
216 @Override | |
217 public void onRecordClick(final RecordClickEvent event) { | 217 public void onRecordClick(final RecordClickEvent event) { |
218 // Just handle remove-clicks | 218 // Just handle remove-clicks |
219 if(!event.getField().getName().equals(removeField.getName())) { | 219 if(!event.getField().getName().equals(removeField.getName())) { |
220 return; | 220 return; |
221 } | 221 } |
235 JSONArray point = (JSONArray) jsonArray.get(i); | 235 JSONArray point = (JSONArray) jsonArray.get(i); |
236 listGrid.addData(datePointRecordFromJSON(point)); | 236 listGrid.addData(datePointRecordFromJSON(point)); |
237 } | 237 } |
238 } | 238 } |
239 else { | 239 else { |
240 // TODO proper log | 240 GWT.log("No item found for " + uuid); |
241 System.out.println("No item found for " + uuid); | |
242 } | 241 } |
243 | 242 |
244 IButton button = new IButton(MSG.newpoint()); | 243 IButton button = new IButton(MSG.newpoint()); |
245 button.setTop(250); | 244 button.setTop(250); |
246 button.addClickHandler(new ClickHandler() { | 245 button.addClickHandler(new ClickHandler() { |
246 @Override | |
247 public void onClick(ClickEvent event) { | 247 public void onClick(ClickEvent event) { |
248 listGrid.startEditingNew(); | 248 listGrid.startEditingNew(); |
249 } | 249 } |
250 }); | 250 }); |
251 | 251 |
260 centerInPage(); | 260 centerInPage(); |
261 } | 261 } |
262 | 262 |
263 | 263 |
264 /** Create JSON representation of the points present in the list grid. */ | 264 /** Create JSON representation of the points present in the list grid. */ |
265 @Override | |
265 protected JSONArray jsonArrayFromListGrid() { | 266 protected JSONArray jsonArrayFromListGrid() { |
266 JSONArray list = new JSONArray(); | 267 JSONArray list = new JSONArray(); |
267 int idx = 0; | 268 int idx = 0; |
268 | 269 |
269 for(ListGridRecord record : listGrid.getRecords()) { | 270 for(ListGridRecord record : listGrid.getRecords()) { |
274 String dateString = point.getX(); | 275 String dateString = point.getX(); |
275 DateTimeFormat df = DateTimeFormat.getFormat( | 276 DateTimeFormat df = DateTimeFormat.getFormat( |
276 DateTimeFormat.PredefinedFormat.DATE_MEDIUM); | 277 DateTimeFormat.PredefinedFormat.DATE_MEDIUM); |
277 | 278 |
278 Date d = df.parse(dateString); | 279 Date d = df.parse(dateString); |
279 double dv = (double)d.getTime(); | 280 double dv = d.getTime(); |
280 | 281 |
281 data.set(0, new JSONNumber(dv)); | 282 data.set(0, new JSONNumber(dv)); |
282 data.set(1, new JSONNumber(point.getY())); | 283 data.set(1, new JSONNumber(point.getY())); |
283 data.set(2, new JSONString(point.getName())); | 284 data.set(2, new JSONString(point.getName())); |
284 data.set(3, JSONBoolean.getInstance(point.isActive())); | 285 data.set(3, JSONBoolean.getInstance(point.isActive())); |
302 String dateString = record.getAttributeAsString(PointRecord.ATTRIBUTE_X); | 303 String dateString = record.getAttributeAsString(PointRecord.ATTRIBUTE_X); |
303 DateTimeFormat df = DateTimeFormat.getFormat( | 304 DateTimeFormat df = DateTimeFormat.getFormat( |
304 DateTimeFormat.PredefinedFormat.DATE_MEDIUM); | 305 DateTimeFormat.PredefinedFormat.DATE_MEDIUM); |
305 | 306 |
306 Date d = df.parse(dateString); | 307 Date d = df.parse(dateString); |
307 double dv = (double)d.getTime(); | 308 double dv = d.getTime(); |
308 data.set(0, new JSONNumber(dv)); | 309 data.set(0, new JSONNumber(dv)); |
309 data.set(1, new JSONNumber(record. | 310 data.set(1, new JSONNumber(record. |
310 getAttributeAsDouble(PointRecord.ATTRIBUTE_Y))); | 311 getAttributeAsDouble(PointRecord.ATTRIBUTE_Y))); |
311 data.set(2, new JSONString(nameString)); | 312 data.set(2, new JSONString(nameString)); |
312 data.set(3, JSONBoolean.getInstance(record.getAttributeAsBoolean( | 313 data.set(3, JSONBoolean.getInstance(record.getAttributeAsBoolean( |