changeset 27:3184e8faa5c0

Anchor for KML download. This is a preliminiary work-around.
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Tue, 27 Nov 2012 11:57:47 +0100
parents 3a91c0718dd3
children 6ec1ab4f897a
files src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java
diffstat 1 files changed, 33 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java	Mon Nov 26 14:49:29 2012 +0100
+++ b/src/econnect/wp3_3/client/widgets/table/DynamicStiTable.java	Tue Nov 27 11:57:47 2012 +0100
@@ -3,6 +3,7 @@
 import java.util.ArrayList;
 
 import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Anchor;
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.FormPanel;
 import com.google.gwt.user.client.ui.Grid;
@@ -19,6 +20,7 @@
 import com.google.gwt.event.dom.client.MouseOverEvent;
 import com.google.gwt.event.dom.client.MouseOverHandler; 
 import com.google.gwt.event.dom.client.MouseOutHandler; 
+import com.google.gwt.http.client.URL;
 
 import econnect.wp3_3.client.core.ApplicationConstants;
 import econnect.wp3_3.client.core.DataObject;
@@ -118,11 +120,16 @@
     */	
 	private ArrayList<DataObject> actualObjectSet;
 	
+	/**
+     * Anchor that holds the URL for the KML download
+    */	
+	private Anchor aDownloadKML;
+	
+	/**
+     * RPC Interface for writing the KML file
+    */	
 	private ExportWriterInterfaceAsync exportWriter;
 	
-	final FormPanel exportFormPanel = new FormPanel();
-	final Hidden hiddenVal = new Hidden();
-
 	/**
      * Constructor for initialization of the dynamic table
      * 
@@ -270,12 +277,16 @@
 		footer.setWidget(0, 3, next);
 		footer.addStyleName("center");
 		
-		//This Panel will hold the name of the export-file
+		
+		//This anchor will hold the URL of the export-file
 		//for download from the ExportServlet
-		final FormPanel exportFormPanel = new FormPanel("_sel");
-		final Hidden hiddenVal = new Hidden();
-		hiddenVal.setName("ExportedFilename");
-		exportFormPanel.add(hiddenVal);
+		aDownloadKML = new Anchor("download KML");
+		aDownloadKML.setVisible(false);
+		aDownloadKML.addClickHandler(new ClickHandler() {
+			public void onClick(ClickEvent event) {
+				aDownloadKML.setVisible(false);
+			}
+		});
 		
 		Image export = new Image(constants.exportImage());
 		export.addClickHandler(new ClickHandler() {
@@ -297,18 +308,18 @@
 		delete.setTitle(textConstants.deleteDataSet());
 		
 		Grid func = new Grid(1,3);
-		//the FormPanel is invisible, see above
-		func.setWidget(0, 0, exportFormPanel);
+
+		func.setWidget(0, 0, aDownloadKML);
 		func.setWidget(0, 1, export);
 		func.setWidget(0, 2, delete);
 		func.addStyleName("center");
 		
-		Grid tableControls = new Grid(1,4);
+		Grid tableControls = new Grid(1,5);
 		tableControls.setWidget(0,0,showOptions);
-//		tableControls.setWidget(0,1,refine);
-		tableControls.setWidget(0,1,this.results);
-		tableControls.setWidget(0,2,footer);
-		tableControls.setWidget(0,3,func);
+		tableControls.setWidget(0,1,refine);
+		tableControls.setWidget(0,2,this.results);
+		tableControls.setWidget(0,3,footer);
+		tableControls.setWidget(0,4,func);
 		tableControls.setStyleName("tableControls");
 		
 		this.setWidget(0, 0, tableControls);
@@ -519,7 +530,6 @@
 			} else {
 				kmlEntry += "<TimeSpan><begin>" + timeSpanStart + "</begin><end>" + timeSpanEnd + "</end></TimeSpan>";				
 			}
-			
 
 			kmlEntry += "</Placemark>";
 			
@@ -533,16 +543,18 @@
 		exportWriter.writeKMLFile(kmlContent, 
 									new AsyncCallback<String>() {
             							public void onFailure(Throwable caught) {
+            								//TODO: error message in layover?
+            								//there needs to be an error-window for KML parser failures anyway
+            								//this one should be used
             								int i = 1;
             							}
             							public void onSuccess(String exportFileName) {
-            				                hiddenVal.setValue(exportFileName);
 
             				                String url = GWT.getModuleBaseURL();
-            				                url = url + "ExportServlet";
-
-            				                exportFormPanel.setAction(url);
-            				                exportFormPanel.submit();
+            				                url = url + "ExportServlet?ExportedFilename=" + URL.encode(exportFileName);
+            				                
+            				                aDownloadKML.setHref(url);
+            				                aDownloadKML.setVisible(true);
             							}
 									}
             					);