diff src/econnect/wp3_3/client/core/ApplicationGrid.java @ 32:f635bbdc6a03

local KML display (beta)
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Fri, 30 Nov 2012 15:17:25 +0100
parents fef6080e83ad
children 18fc3a30e993
line wrap: on
line diff
--- a/src/econnect/wp3_3/client/core/ApplicationGrid.java	Thu Nov 29 11:33:12 2012 +0100
+++ b/src/econnect/wp3_3/client/core/ApplicationGrid.java	Fri Nov 30 15:17:25 2012 +0100
@@ -4,6 +4,7 @@
 import java.util.Date;
 import java.util.List;
 
+import com.google.gwt.user.client.ui.FileUpload;
 import com.google.gwt.user.client.ui.Grid;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
@@ -179,6 +180,10 @@
 			final ListBox datasource = new ListBox(false);		
 			final List<ListBox> staticListBoxes = new ArrayList<ListBox>();		
 			final ArrayList<ArrayList<int[]>> entries = new ArrayList<ArrayList<int[]>>();
+			final FileUpload uploadKML = 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
+			uploadKML.getElement().setId("localKMLFileChooser");
 			for( int i=0; i<sources; i++ ){
 				try {
 					if( core.hasItems(i) ){
@@ -247,10 +252,18 @@
 			    datasource.addChangeHandler(new ChangeHandler() {
 				      public void onChange(ChangeEvent event) {
 							int ds = datasource.getSelectedIndex();
+							String label = datasource.getItemText(ds);
+							
 							if( ds == -1 ){
 								return;
 							}
-						    if( staticListBoxes.get(ds) == null ){
+							//skruse: test for local KML loading (e.g. useful for the downloaded KMLs)
+							//TODO: if this remains in the code, the check below has
+							//to be improved (some constant somewhere)
+							if( label.equals("local KML") ){
+								openPanel.setWidget(0, 1, uploadKML);
+							}
+							else if( staticListBoxes.get(ds) == null ){
 					    		  openPanel.setWidget(0, 1, searchField);
 						    }
 						    else {
@@ -272,6 +285,8 @@
 					}
 					private void loadData() {
 						int ds = datasource.getSelectedIndex();
+						String label = datasource.getItemText(ds);
+
 						if( core.isMaximumReached() ){
 							core.alert(textConstants.maxDatasources());
 						}
@@ -281,6 +296,13 @@
 								core.openStaticKml(ds,pair[0],pair[1]);							
 							}
 						}
+						//skruse: test for local KML loading (e.g. useful for the downloaded KMLs)
+						//TODO: if this remains in the code, the check below has
+						//to be improved (some constant somewhere)
+						else if( (label.equals("local KML")) && (uploadKML.getFilename() != "") ){
+							String fileName = uploadKML.getFilename();
+							core.openLocalKml( ds, fileName );
+						}
 						else if( !searchField.getText().equals("") ){
 							core.openDynamicKml( ds, searchField.getText() );
 						}