|
35 | 35 | import org.apache.wicket.request.resource.IResource; |
36 | 36 | import org.apache.wicket.request.resource.ResourceReference; |
37 | 37 | import org.apache.wicket.util.lang.Bytes; |
| 38 | +import org.apache.wicket.util.upload.FileItem; |
38 | 39 | import org.dgfoundation.amp.onepager.OnePagerUtil; |
39 | 40 | import org.dgfoundation.amp.onepager.components.ListEditorRemoveButton; |
40 | 41 | import org.dgfoundation.amp.onepager.components.ListItem; |
|
46 | 47 | import org.dgfoundation.amp.onepager.components.fields.AmpTextAreaFieldPanel; |
47 | 48 | import org.dgfoundation.amp.onepager.components.fields.AmpTextFieldPanel; |
48 | 49 | import org.dgfoundation.amp.onepager.components.fields.LatAndLongValidator; |
| 50 | +import org.dgfoundation.amp.onepager.components.upload.FileUploadPanel; |
49 | 51 | import org.dgfoundation.amp.onepager.helper.structure.ColorData; |
50 | 52 | import org.dgfoundation.amp.onepager.helper.structure.CoordinateData; |
51 | 53 | import org.dgfoundation.amp.onepager.helper.structure.MapData; |
@@ -334,49 +336,54 @@ public void onClick(AjaxRequestTarget target) { |
334 | 336 |
|
335 | 337 | // final FileUploadField fileUploadField = new FileUploadField("fileUpload"); |
336 | 338 | // fileUploadField.setOutputMarkupId(true); |
| 339 | + final Model<FileItem> fileItemModel = new Model<FileItem>(); |
| 340 | + |
| 341 | + FileUploadPanel fileUpload = new FileUploadPanel("fileUpload",String.valueOf(am.getObject().getAmpActivityId()), fileItemModel); |
| 342 | + |
| 343 | + |
337 | 344 |
|
338 | 345 | final Form<?> form = new Form<Void>("structuresImportForm") { |
339 | 346 | private static final long serialVersionUID = 1L; |
340 | 347 |
|
341 | 348 | @Override |
342 | 349 | protected void onSubmit() { |
343 | | -// FileUpload upload = new FileUploadField("fileUpload").getFileUpload(); |
344 | | -// if (upload == null) { |
345 | | -// logger.info("No file uploaded"); |
346 | | -// } else { |
347 | | -// logger.info("File-Name: " + upload.getClientFileName() + " File-Size: " + |
348 | | -// Bytes.bytes(upload.getSize())); |
349 | | -// try { |
350 | | -// XSSFWorkbook workbook = new XSSFWorkbook(upload.getInputStream()); |
351 | | -// XSSFSheet sheet = workbook.getSheetAt(0); |
352 | | -// Iterator<Row> rowIterator = sheet.iterator(); |
353 | | -// rowIterator.next(); |
354 | | -// |
355 | | -// while (rowIterator.hasNext()) { |
356 | | -// XSSFRow row = (XSSFRow) rowIterator.next(); |
357 | | -// String title = getStringValueFromCell(row.getCell(0)); |
358 | | -// String description = getStringValueFromCell(row.getCell(1)); |
359 | | -// String latitude = getStringValueFromCell(row.getCell(2)); |
360 | | -// String longitude = getStringValueFromCell(row.getCell(3)); |
361 | | -// |
362 | | -// AmpStructure stru = new AmpStructure(); |
363 | | -// stru.setTitle(title); |
364 | | -// stru.setDescription(description); |
365 | | -// stru.setLatitude(latitude); |
366 | | -// stru.setLongitude(longitude); |
367 | | -// list.addItem(stru); |
368 | | -// list.goToLastPage(); |
369 | | -// } |
370 | | -// } catch (IOException e) { |
371 | | -// throw new RuntimeException(e); |
372 | | -// } |
373 | | -// } |
| 350 | + FileUpload upload = new FileUpload(fileItemModel.getObject()); |
| 351 | + if (upload == null) { |
| 352 | + logger.info("No file uploaded"); |
| 353 | + } else { |
| 354 | + logger.info("File-Name: " + upload.getClientFileName() + " File-Size: " + |
| 355 | + Bytes.bytes(upload.getSize())); |
| 356 | + try { |
| 357 | + XSSFWorkbook workbook = new XSSFWorkbook(upload.getInputStream()); |
| 358 | + XSSFSheet sheet = workbook.getSheetAt(0); |
| 359 | + Iterator<Row> rowIterator = sheet.iterator(); |
| 360 | + rowIterator.next(); |
| 361 | + |
| 362 | + while (rowIterator.hasNext()) { |
| 363 | + XSSFRow row = (XSSFRow) rowIterator.next(); |
| 364 | + String title = getStringValueFromCell(row.getCell(0)); |
| 365 | + String description = getStringValueFromCell(row.getCell(1)); |
| 366 | + String latitude = getStringValueFromCell(row.getCell(2)); |
| 367 | + String longitude = getStringValueFromCell(row.getCell(3)); |
| 368 | + |
| 369 | + AmpStructure stru = new AmpStructure(); |
| 370 | + stru.setTitle(title); |
| 371 | + stru.setDescription(description); |
| 372 | + stru.setLatitude(latitude); |
| 373 | + stru.setLongitude(longitude); |
| 374 | + list.addItem(stru); |
| 375 | + list.goToLastPage(); |
| 376 | + } |
| 377 | + } catch (IOException e) { |
| 378 | + throw new RuntimeException(e); |
| 379 | + } |
| 380 | + } |
374 | 381 | } |
375 | 382 | }; |
376 | 383 |
|
377 | | -// form.setMultiPart(true); |
378 | | -// form.setMaxSize(Bytes.megabytes(10)); |
379 | | -// form.add(fileUploadField); |
| 384 | + form.setMultiPart(true); |
| 385 | + form.setMaxSize(Bytes.megabytes(10)); |
| 386 | + form.add(fileUpload); |
380 | 387 |
|
381 | 388 | Button importStructures = new Button("importStructures"); |
382 | 389 | importStructures.setOutputMarkupId(true); |
|
0 commit comments