Mercurial > hg > STI-GWT
changeset 86:ed444173aef0 trimmed_data
local CSV loading
author | Sebastian Kruse <skruse@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 07 Mar 2013 14:47:36 +0100 |
parents | 108c853e0900 |
children | 593cfbd58c3e |
files | src/econnect/wp3_3/client/core/ApplicationGrid.java src/econnect/wp3_3/client/core/StiCore.java war/datasources.json war/scripts/sti/STICore.js |
diffstat | 4 files changed, 84 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/econnect/wp3_3/client/core/ApplicationGrid.java Thu Mar 07 14:35:30 2013 +0100 +++ b/src/econnect/wp3_3/client/core/ApplicationGrid.java Thu Mar 07 14:47:36 2013 +0100 @@ -182,6 +182,10 @@ //skruse: The element will be accessed by its ID in the JS code //either don't change this name, or change it also in STICore.js uploadKML.getElement().setId("localKMLFileChooser"); + final FileUpload uploadCSV = new FileUpload(); + //skruse: The element will be accessed by its ID in the JS code + //either don't change this name, or change it also in STICore.js + uploadCSV.getElement().setId("localCSVFileChooser"); for( int i=0; i<sources; i++ ){ try { if( core.hasItems(i) ){ @@ -261,6 +265,12 @@ if( label.equals("local KML") ){ openPanel.setWidget(0, 1, uploadKML); } + //skruse: test for local CSV loading + //TODO: if this remains in the code, the check below has + //to be improved (some constant somewhere) + if( label.equals("local CSV") ){ + openPanel.setWidget(0, 1, uploadCSV); + } else if( staticListBoxes.get(ds) == null ){ openPanel.setWidget(0, 1, searchField); } @@ -301,6 +311,13 @@ String fileName = uploadKML.getFilename(); core.openLocalKml( ds, fileName ); } + //skruse: test for local CSV loading + //TODO: if this remains in the code, the check below has + //to be improved (some constant somewhere) + else if( (label.equals("local CSV")) && (uploadCSV.getFilename() != "") ){ + String fileName = uploadCSV.getFilename(); + core.openLocalCsv( ds, fileName ); + } else if( !searchField.getText().equals("") ){ core.openDynamicKml( ds, searchField.getText() ); }
--- a/src/econnect/wp3_3/client/core/StiCore.java Thu Mar 07 14:35:30 2013 +0100 +++ b/src/econnect/wp3_3/client/core/StiCore.java Thu Mar 07 14:47:36 2013 +0100 @@ -452,6 +452,16 @@ }-*/; /** + * Opens a local KML file via HTML5 FileAPI + * + * @param ds the index of the datasource + * @param input the user input text + */ + public final native void openLocalCsv(int ds, String fileName) /*-{ + this.retrieveLocalCsv( ds, fileName ); + }-*/; + + /** * places a configured time refinement */ public final native void refineByTime(String minTime, String maxTime) /*-{
--- a/war/datasources.json Thu Mar 07 14:35:30 2013 +0100 +++ b/war/datasources.json Thu Mar 07 14:47:36 2013 +0100 @@ -32,5 +32,9 @@ { "label": "local KML", "url": "" + }, + { + "label": "local CSV", + "url": "" } ] \ No newline at end of file
--- a/war/scripts/sti/STICore.js Thu Mar 07 14:35:30 2013 +0100 +++ b/war/scripts/sti/STICore.js Thu Mar 07 14:47:36 2013 +0100 @@ -575,6 +575,59 @@ }, /** + * retrieves and loads a CSV-file from the local system + * + * @param {int} + * ds the datasource index + * @param {File} + * file the file that the user selected + */ + retrieveLocalCsv: function(ds,filename){ + + var core = this; + if( this.blocked ){ + setTimeout( function(){ core.retrieveLocalCsv(ds,filename); }, 100 ); + return; + } + core.blockUI(); + + var status = document.getElementById("statusText"); + status.innerHTML = "Retrieving Data ..."; + + var filelist = $('#localCSVFileChooser').get(0).files; + if (filelist.length > 0){ + var file = filelist[0]; + + var reader = new FileReader(); + + reader.onloadend = (function(theFile) { + return function(e) { + status.innerHTML = "Parsing Data ..."; + + var kmlText = core.convertCsv(reader.result); + + var localkmlDoc; + try { + localkmlDoc = $.parseXML(kmlText); + } catch (e) { + alert("KML file is not valid XML. Please check opening/closing tags and check the spelling."); + + core.unblockUI(); + + return; + } + + setTimeout( function(){ core.parseIt(localkmlDoc,filename,ds); }, 1 ); + }; + })(file); + + reader.readAsText(file); + } + + return; + }, + + /** * parses the kml-file which includes the results for a given search request * * @param {File}