comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java @ 1553:9ad19e31d149

Improved points UI to also respect language and name of point. flys-client/trunk@3791 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 27 Jan 2012 12:03:04 +0000
parents 42f1213dfbcc
children 3cf3cd8dd92d
comparison
equal deleted inserted replaced
1552:69b38f890bb6 1553:9ad19e31d149
1 package de.intevation.flys.client.client.ui.chart; 1 package de.intevation.flys.client.client.ui.chart;
2 2
3 import com.google.gwt.json.client.JSONArray; 3 import com.google.gwt.json.client.JSONArray;
4 import com.google.gwt.json.client.JSONNumber; 4 import com.google.gwt.json.client.JSONNumber;
5 import com.google.gwt.json.client.JSONParser; 5 import com.google.gwt.json.client.JSONParser;
6 import com.google.gwt.json.client.JSONString;
6 import com.google.gwt.core.client.GWT; 7 import com.google.gwt.core.client.GWT;
7 import com.google.gwt.user.client.rpc.AsyncCallback; 8 import com.google.gwt.user.client.rpc.AsyncCallback;
8 9
9 import com.smartgwt.client.util.SC; 10 import com.smartgwt.client.util.SC;
10 import com.smartgwt.client.widgets.Window; 11 import com.smartgwt.client.widgets.Window;
15 import com.smartgwt.client.widgets.Label; 16 import com.smartgwt.client.widgets.Label;
16 import com.smartgwt.client.widgets.Canvas; 17 import com.smartgwt.client.widgets.Canvas;
17 import com.smartgwt.client.widgets.grid.ListGrid; 18 import com.smartgwt.client.widgets.grid.ListGrid;
18 import com.smartgwt.client.widgets.grid.ListGridField; 19 import com.smartgwt.client.widgets.grid.ListGridField;
19 import com.smartgwt.client.widgets.grid.ListGridRecord; 20 import com.smartgwt.client.widgets.grid.ListGridRecord;
21 import com.smartgwt.client.types.ListGridFieldType;
20 22
21 import com.smartgwt.client.widgets.form.DynamicForm; 23 import com.smartgwt.client.widgets.form.DynamicForm;
22 24
23 import com.smartgwt.client.widgets.events.ClickEvent; 25 import com.smartgwt.client.widgets.events.ClickEvent;
24 import com.smartgwt.client.widgets.events.ClickHandler; 26 import com.smartgwt.client.widgets.events.ClickHandler;
118 120
119 /** 121 /**
120 * Initialize the editor window and its components. 122 * Initialize the editor window and its components.
121 */ 123 */
122 protected void init() { 124 protected void init() {
123 setTitle("Add Points"); 125 setTitle(MSG.addpoints());
124 //TODO MSG.properties());
125 setCanDragReposition(true); 126 setCanDragReposition(true);
126 setCanDragResize(true); 127 setCanDragResize(true);
127 128
128 // If no manualpoints artifact found, create it now. 129 // If no manualpoints artifact found, create it now.
129 if(findManualPointsUUID() == null) { 130 if(findManualPointsUUID() == null) {
148 // Feed JSON-encoded content of listgrid. 149 // Feed JSON-encoded content of listgrid.
149 String jsonString = ""; 150 String jsonString = "";
150 int idx = 0; 151 int idx = 0;
151 JSONArray list = new JSONArray(); 152 JSONArray list = new JSONArray();
152 153
153 // TODO also need name attribute
154 for(ListGridRecord record : listGrid.getRecords()) { 154 for(ListGridRecord record : listGrid.getRecords()) {
155 if (record instanceof PointRecord) { 155 if (record instanceof PointRecord) {
156 JSONArray data = new JSONArray(); 156 JSONArray data = new JSONArray();
157 157
158 PointRecord point = (PointRecord) record; 158 PointRecord point = (PointRecord) record;
159 data.set(0, new JSONNumber(point.getX())); 159 data.set(0, new JSONNumber(point.getX()));
160 data.set(1, new JSONNumber(point.getY())); 160 data.set(1, new JSONNumber(point.getY()));
161 data.set(2, new JSONString(point.getName()));
161 162
162 list.set(idx, data); 163 list.set(idx, data);
163 idx++; 164 idx++;
164 } 165 }
165 else { 166 else {
166 JSONArray data = new JSONArray(); 167 JSONArray data = new JSONArray();
167 168
168 // TODO better get double directly (via cell-formatter etc) 169 // TODO better get double directly (via cell-formatter etc)
169 String xString = record.getAttributeAsString("X"); 170 String xString = record.getAttributeAsString("X");
170 String yString = record.getAttributeAsString("Y"); 171 String yString = record.getAttributeAsString("Y");
172 String nameString = record.getAttributeAsString("name");
173 if (nameString == null || nameString.equals("")) {
174 nameString = xString + "/" + yString;
175 }
171 176
172 data.set(0, new JSONNumber(Double.valueOf(xString))); 177 data.set(0, new JSONNumber(Double.valueOf(xString)));
173 data.set(1, new JSONNumber(Double.valueOf(yString))); 178 data.set(1, new JSONNumber(Double.valueOf(yString)));
179 data.set(2, new JSONString(nameString));
174 180
175 list.set(idx, data); 181 list.set(idx, data);
176 idx++; 182 idx++;
177 } 183 }
178 } 184 }
179
180 // TODO lock UI until feed succeeded/failed.
181 185
182 // Feed list.toString to respective artifact. 186 // Feed list.toString to respective artifact.
183 Data[] feedData = new Data[] { 187 Data[] feedData = new Data[] {
184 DefaultData.createSimpleStringData(POINT_DATA, 188 DefaultData.createSimpleStringData(POINT_DATA,
185 list.toString()) 189 list.toString())
223 227
224 VLayout layout = new VLayout(); 228 VLayout layout = new VLayout();
225 listGrid = new ListGrid(); 229 listGrid = new ListGrid();
226 listGrid.setWidth100(); 230 listGrid.setWidth100();
227 listGrid.setHeight(200); 231 listGrid.setHeight(200);
228 final ListGridField xField = new ListGridField("X", "X"); 232 // TODO X and Y Header depend on the current chart and axis (e.g. W[nn+m])
229 final ListGridField yField = new ListGridField("Y", "Y"); 233 ListGridField xField = new ListGridField("X", "X");
230 final ListGridField nameField = new ListGridField("name", "name"); 234 xField.setType(ListGridFieldType.FLOAT);
231 final ListGridField removeField = new ListGridField("remove", "remove"); 235 ListGridField yField = new ListGridField("Y", "Y");
232 listGrid.setFields(new ListGridField[] {xField, yField, removeField}); 236 yField.setType(ListGridFieldType.FLOAT);
237 ListGridField nameField = new ListGridField("name",
238 MSG.pointname());
239 ListGridField removeField = new ListGridField("remove",
240 MSG.removepoint());
241 listGrid.setFields(new ListGridField[] {xField, yField,
242 nameField, removeField});
233 243
234 // Find the artifacts uuid. 244 // Find the artifacts uuid.
235 findManualPointsUUID(); 245 findManualPointsUUID();
236 CollectionItem item = collection.getItem(uuid); 246 CollectionItem item = collection.getItem(uuid);
237 247
243 JSONArray point = (JSONArray) jsonArray.get(i); 253 JSONArray point = (JSONArray) jsonArray.get(i);
244 listGrid.addData(pointRecordFromJSON(point)); 254 listGrid.addData(pointRecordFromJSON(point));
245 } 255 }
246 } 256 }
247 else { 257 else {
258 // TODO proper log
248 System.out.println("No item found for " + uuid); 259 System.out.println("No item found for " + uuid);
249 } 260 }
250 261
251 layout.addMember(listGrid); 262 IButton button = new IButton(MSG.newpoint());
252
253 addItem(layout);
254 IButton button = new IButton("Edit New");
255 button.setTop(250); 263 button.setTop(250);
256 button.addClickHandler(new ClickHandler() { 264 button.addClickHandler(new ClickHandler() {
257 public void onClick(ClickEvent event) { 265 public void onClick(ClickEvent event) {
258 listGrid.startEditingNew(); 266 listGrid.startEditingNew();
259 } 267 }
260 }); 268 });
261 addItem(button); 269
270 layout.addMember(listGrid);
271 layout.addMember(button);
272
273 addItem(layout);
274
262 addItem(buttons); 275 addItem(buttons);
263 setWidth(380); 276 setWidth(380);
264 setHeight(470); 277 setHeight(470);
265 centerInPage(); 278 centerInPage();
266 } 279 }
268 281
269 /** From a JSON-encoded point, create a PointRecord. */ 282 /** From a JSON-encoded point, create a PointRecord. */
270 public PointRecord pointRecordFromJSON(JSONArray jsonArray) { 283 public PointRecord pointRecordFromJSON(JSONArray jsonArray) {
271 JSONNumber x = (JSONNumber) jsonArray.get(0); 284 JSONNumber x = (JSONNumber) jsonArray.get(0);
272 JSONNumber y = (JSONNumber) jsonArray.get(1); 285 JSONNumber y = (JSONNumber) jsonArray.get(1);
273 return new PointRecord(x.doubleValue(), y.doubleValue()); 286 JSONString s = (JSONString) jsonArray.get(2);
287 return new PointRecord(x.doubleValue(), y.doubleValue(), s.stringValue());
274 } 288 }
275 289
276 290
277 /** Add a ManualPointArtifact to Collection. */ 291 /** Add a ManualPointArtifact to Collection. */
278 public void addArtifactCreateUI() { 292 public void addArtifactCreateUI() {
279 // TODO MSG:/i18n 293 final Label standByLabel = new Label(MSG.standby());
280 final Label standByLabel = new Label("Creating artifact, these are not the droids");
281 addItem(standByLabel); 294 addItem(standByLabel);
282 295
283 setWidth(380); 296 setWidth(380);
284 setHeight(470); 297 setHeight(470);
285 centerInPage(); 298 centerInPage();
317 330
318 /** Simple record to store points. */ 331 /** Simple record to store points. */
319 public class PointRecord extends ListGridRecord { 332 public class PointRecord extends ListGridRecord {
320 protected static final String ATTRIBUTE_X = "X"; 333 protected static final String ATTRIBUTE_X = "X";
321 protected static final String ATTRIBUTE_Y = "Y"; 334 protected static final String ATTRIBUTE_Y = "Y";
322 335 protected static final String ATTRIBUTE_NAME = "name";
336
337 String name;
323 double x; 338 double x;
324 double y; 339 double y;
325 340
326 private PointRecord() {;} 341 private PointRecord() {;}
327 342
328 public PointRecord(double x, double y) { 343 public PointRecord(double x, double y, String name) {
344 setName(name);
329 setX(x); 345 setX(x);
330 setY(y); 346 setY(y);
347 }
348
349 public void setName(String name) {
350 this.name = name;
351 setAttribute(ATTRIBUTE_NAME, getName());
352 }
353
354 public String getName() {
355 return this.name;
331 } 356 }
332 357
333 public void setX(double x) { 358 public void setX(double x) {
334 this.x = x; 359 this.x = x;
335 setAttribute(ATTRIBUTE_X, getX()); 360 setAttribute(ATTRIBUTE_X, getX());
348 return this.y; 373 return this.y;
349 } 374 }
350 } 375 }
351 376
352 377
353 // TODO cleanup. We need code similar to the following. 378 // TODO validate entered values (CellFormatter).
354
355 /*
356 protected void updateCollection() {
357 final Config config = Config.getInstance();
358 final String loc = config.getLocale();
359
360 GWT.log("PropertiesEditor.updateCollection via RPC now");
361
362 Settings s = settings;
363 collection.addSettings(this.tab.getOutputName(), s);
364 updater.update(collection, loc, new AsyncCallback<Collection>() {
365 public void onFailure(Throwable caught) {
366 GWT.log("Could not update collection attributes.");
367 SC.warn(MSG.getString(caught.getMessage()));
368 }
369 public void onSuccess(Collection collection) {
370 updateChartTab();
371 }
372 });
373 }
374
375 /*
376 protected void updateChartTab() {
377 this.tab.updateChartInfo();
378 this.tab.updateChartPanel();
379 this.destroy();
380 }
381 */
382
383 protected boolean isDialogValid() { 379 protected boolean isDialogValid() {
384 boolean valid = true; 380 boolean valid = true;
385 /* 381 /*
386 for (int i = 0; i < tabs.getNumTabs(); i++) { 382 for (int i = 0; i < tabs.getNumTabs(); i++) {
387 Tab t = tabs.getTab(i); 383 Tab t = tabs.getTab(i);

http://dive4elements.wald.intevation.org