summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2010-03-11 15:56:57 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2010-03-11 15:56:57 +0000
commit41c7fbb6f5e9ebf8526ab0cbba7d12ab15aeee97 (patch)
tree9647ea2e6bf4b71409298c9bd4662582151c1a5d /src/com/vaadin
parent7da4b810a4445b3bd14d26aa89ae0547d056b5e8 (diff)
downloadvaadin-framework-41c7fbb6f5e9ebf8526ab0cbba7d12ab15aeee97.tar.gz
vaadin-framework-41c7fbb6f5e9ebf8526ab0cbba7d12ab15aeee97.zip
Skeletons for html5 File API in DD
svn changeset:11801/svn branch:6.3
Diffstat (limited to 'src/com/vaadin')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java43
1 files changed, 41 insertions, 2 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java
index be86089b38..2beef216f2 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java
@@ -5,6 +5,7 @@ package com.vaadin.terminal.gwt.client.ui;
import java.util.Map;
+import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
@@ -28,8 +29,10 @@ import com.vaadin.terminal.gwt.client.ui.dd.VDragEvent;
import com.vaadin.terminal.gwt.client.ui.dd.VDropHandler;
import com.vaadin.terminal.gwt.client.ui.dd.VHasDropHandler;
import com.vaadin.terminal.gwt.client.ui.dd.VHtml5DragEvent;
+import com.vaadin.terminal.gwt.client.ui.dd.VHtml5File;
import com.vaadin.terminal.gwt.client.ui.dd.VTransferable;
import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation;
+import com.vaadin.terminal.gwt.client.ui.dd.VHtml5File.Callback;
/**
*
@@ -50,8 +53,6 @@ public class VDragAndDropWrapper extends VCustomComponent implements
addDomHandler(new MouseDownHandler() {
public void onMouseDown(MouseDownEvent event) {
if (dragStarMode > 0) {
- // TODO should support drag mode WRAPPER too, now works for
- // COMPONENT
VTransferable transferable = new VTransferable();
transferable.setDragSource(VDragAndDropWrapper.this);
@@ -87,6 +88,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements
private final static int COMPONENT = 1;
private final static int WRAPPER = 2;
private int dragStarMode;
+ private int filecounter = 0;
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
@@ -186,6 +188,43 @@ public class VDragAndDropWrapper extends VCustomComponent implements
}
}
+ int fileCount = event.getFileCount();
+ if (fileCount > 0) {
+ transferable.setData("filecount", fileCount);
+ for (int i = 0; i < fileCount; i++) {
+ final int fileId = filecounter++;
+ final VHtml5File file = event.getFile(fileCount);
+ transferable.setData("fn" + fileId, file.getName());
+ transferable.setData("ft" + fileId, file.getType());
+ transferable.setData("fs" + fileId, file.getSize());
+ DeferredCommand.addCommand(new Command() {
+ public void execute() {
+ /*
+ * File contents is sent deferred to allow quick
+ * reaction on GUI although file upload may last long.
+ * TODO make this use apache file upload instead of our
+ * variable post like in upload. Currently stalls the
+ * GUI during upload. Also need to use dataurl to
+ * support all possible bytes in file content
+ */
+ file.readAsDataUrl(new Callback() {
+ public void handleFile(JavaScriptObject object) {
+ client.updateVariable(client
+ .getPid(VDragAndDropWrapper.this),
+ "file" + fileId, object.toString(),
+ true);
+
+ }
+ });
+
+ }
+ });
+ }
+
+ }
+
+ // TODO remove this when above cleaner and more standard compliance
+ // system works
String fileAsString = event.getFileAsString(0);
if (fileAsString != null) {
ApplicationConnection.getConsole().log(fileAsString);