summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-10-23 13:09:10 +0000
committerVaadin Code Review <review@vaadin.com>2012-10-23 13:09:10 +0000
commitd8145ff765f88205210ee57f89b0445e1934cd56 (patch)
tree6b5d00cfe2f3583cafb9df68108ff4b2506aa1b1 /client
parent439b88b09de669189d71279e9a42588b5ee1a753 (diff)
parent055563a7166f4e3891929e3c8be5799789d68ae1 (diff)
downloadvaadin-framework-d8145ff765f88205210ee57f89b0445e1934cd56.tar.gz
vaadin-framework-d8145ff765f88205210ee57f89b0445e1934cd56.zip
Merge "FileDownloader for starting downloads with any component (#9524)"
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/extensions/FileDownloaderConnector.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/extensions/FileDownloaderConnector.java b/client/src/com/vaadin/client/extensions/FileDownloaderConnector.java
new file mode 100644
index 0000000000..d76efcc046
--- /dev/null
+++ b/client/src/com/vaadin/client/extensions/FileDownloaderConnector.java
@@ -0,0 +1,61 @@
+package com.vaadin.client.extensions;
+
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.IFrameElement;
+import com.google.gwt.dom.client.Style;
+import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.dom.client.Style.Visibility;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.ui.RootPanel;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.client.ComponentConnector;
+import com.vaadin.client.ServerConnector;
+import com.vaadin.server.FileDownloader;
+import com.vaadin.shared.ui.Connect;
+
+@Connect(FileDownloader.class)
+public class FileDownloaderConnector extends AbstractExtensionConnector
+ implements ClickHandler {
+
+ private IFrameElement iframe;
+
+ @Override
+ protected void extend(ServerConnector target) {
+ final Widget downloadWidget = ((ComponentConnector) target).getWidget();
+
+ downloadWidget.addDomHandler(this, ClickEvent.getType());
+ }
+
+ @Override
+ public void onClick(ClickEvent event) {
+ final String url = getResourceUrl("dl");
+ if (url != null && !url.isEmpty()) {
+ if (iframe != null) {
+ // make sure it is not on dom tree already, might start
+ // multiple downloads at once
+ iframe.removeFromParent();
+ }
+ iframe = Document.get().createIFrameElement();
+
+ Style style = iframe.getStyle();
+ style.setVisibility(Visibility.HIDDEN);
+ style.setHeight(0, Unit.PX);
+ style.setWidth(0, Unit.PX);
+
+ iframe.setFrameBorder(0);
+ iframe.setTabIndex(-1);
+ iframe.setSrc(url);
+ RootPanel.getBodyElement().appendChild(iframe);
+ }
+ }
+
+ @Override
+ public void setParent(ServerConnector parent) {
+ super.setParent(parent);
+ if (parent == null) {
+ iframe.removeFromParent();
+ }
+ }
+
+}