summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-01-31 09:59:01 +0200
committerArtur Signell <artur@vaadin.com>2012-01-31 10:00:16 +0200
commitf714fead66711f3eada1b6f69bd0faaaee5c9c31 (patch)
tree5eab60dec521fa6de2dc0d8b9df4467421039f40 /src
parent5eb53fb96405a615516279457f38ce8c84945a96 (diff)
downloadvaadin-framework-f714fead66711f3eada1b6f69bd0faaaee5c9c31.tar.gz
vaadin-framework-f714fead66711f3eada1b6f69bd0faaaee5c9c31.zip
Split DragAndDropWrapper into widget + paintable
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java73
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapperPaintable.java71
-rw-r--r--src/com/vaadin/ui/DragAndDropWrapper.java3
3 files changed, 88 insertions, 59 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java
index 3251a03d6a..0297e8df3f 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java
@@ -4,10 +4,8 @@
package com.vaadin.terminal.gwt.client.ui;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArrayString;
@@ -28,7 +26,6 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.RenderInformation;
import com.vaadin.terminal.gwt.client.RenderInformation.Size;
-import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VConsole;
import com.vaadin.terminal.gwt.client.VPaintable;
@@ -97,7 +94,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements
super.onBrowserEvent(event);
if (client != null) {
- client.handleTooltipEvent(event, this);
+ client.handleWidgetTooltipEvent(event, this);
}
}
@@ -111,7 +108,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements
private boolean startDrag(NativeEvent event) {
if (dragStartMode == WRAPPER || dragStartMode == COMPONENT) {
VTransferable transferable = new VTransferable();
- transferable.setDragSource(VDragAndDropWrapper.this);
+ transferable.setDragSource(VPaintableMap.get(client).getPaintable(
+ VDragAndDropWrapper.this));
VPaintableWidget paintable = Util.findPaintable(client,
(Element) event.getEventTarget().cast());
@@ -140,58 +138,15 @@ public class VDragAndDropWrapper extends VCustomComponent implements
protected int dragStartMode;
- private ApplicationConnection client;
- private VAbstractDropHandler dropHandler;
+ ApplicationConnection client;
+ VAbstractDropHandler dropHandler;
private VDragEvent vaadinDragEvent;
- private int filecounter = 0;
- private Map<String, String> fileIdToReceiver;
- private ValueMap html5DataFlavors;
+ int filecounter = 0;
+ Map<String, String> fileIdToReceiver;
+ ValueMap html5DataFlavors;
private Element dragStartElement;
- @Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- this.client = client;
- super.updateFromUIDL(uidl, client);
- if (!uidl.hasAttribute("cached") && !uidl.hasAttribute("hidden")) {
- UIDL acceptCrit = uidl.getChildByTagName("-ac");
- if (acceptCrit == null) {
- dropHandler = null;
- } else {
- if (dropHandler == null) {
- dropHandler = new CustomDropHandler();
- }
- dropHandler.updateAcceptRules(acceptCrit);
- }
-
- Set<String> variableNames = uidl.getVariableNames();
- for (String fileId : variableNames) {
- if (fileId.startsWith("rec-")) {
- String receiverUrl = uidl.getStringVariable(fileId);
- fileId = fileId.substring(4);
- if (fileIdToReceiver == null) {
- fileIdToReceiver = new HashMap<String, String>();
- }
- if ("".equals(receiverUrl)) {
- Integer id = Integer.parseInt(fileId);
- int indexOf = fileIds.indexOf(id);
- if (indexOf != -1) {
- files.remove(indexOf);
- fileIds.remove(indexOf);
- }
- } else {
- fileIdToReceiver.put(fileId, receiverUrl);
- }
- }
- }
- startNextUpload();
-
- dragStartMode = uidl.getIntAttribute(DRAG_START_MODE);
- initDragStartMode();
- html5DataFlavors = uidl.getMapAttribute(HTML5_DATA_FLAVORS);
- }
- }
-
protected void initDragStartMode() {
Element div = getElement();
if (dragStartMode == HTML5) {
@@ -231,7 +186,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements
};
private Timer dragleavetimer;
- private void startNextUpload() {
+ void startNextUpload() {
Scheduler.get().scheduleDeferred(new Command() {
public void execute() {
@@ -287,7 +242,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements
}
if (VDragAndDropManager.get().getCurrentDropHandler() != getDropHandler()) {
VTransferable transferable = new VTransferable();
- transferable.setDragSource(this);
+ transferable.setDragSource(VPaintableMap.get(client)
+ .getPaintable(this));
vaadinDragEvent = VDragAndDropManager.get().startDrag(
transferable, event, false);
@@ -455,8 +411,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements
* @param fileId
* @param data
*/
- private List<Integer> fileIds = new ArrayList<Integer>();
- private List<VHtml5File> files = new ArrayList<VHtml5File>();
+ List<Integer> fileIds = new ArrayList<Integer>();
+ List<VHtml5File> files = new ArrayList<VHtml5File>();
private void queueFilePost(final int fileId, final VHtml5File file) {
fileIds.add(fileId);
@@ -544,7 +500,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements
@Override
public VPaintableWidget getPaintable() {
- return VDragAndDropWrapper.this;
+ return VPaintableMap.get(client).getPaintable(
+ VDragAndDropWrapper.this);
}
public ApplicationConnection getApplicationConnection() {
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapperPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapperPaintable.java
new file mode 100644
index 0000000000..1deb155001
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapperPaintable.java
@@ -0,0 +1,71 @@
+package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.HashMap;
+import java.util.Set;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+
+public class VDragAndDropWrapperPaintable extends VCustomComponentPaintable {
+
+ @Override
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().client = client;
+ super.updateFromUIDL(uidl, client);
+ if (!uidl.hasAttribute("cached") && !uidl.hasAttribute("hidden")) {
+ UIDL acceptCrit = uidl.getChildByTagName("-ac");
+ if (acceptCrit == null) {
+ getWidgetForPaintable().dropHandler = null;
+ } else {
+ if (getWidgetForPaintable().dropHandler == null) {
+ getWidgetForPaintable().dropHandler = getWidgetForPaintable().new CustomDropHandler();
+ }
+ getWidgetForPaintable().dropHandler
+ .updateAcceptRules(acceptCrit);
+ }
+
+ Set<String> variableNames = uidl.getVariableNames();
+ for (String fileId : variableNames) {
+ if (fileId.startsWith("rec-")) {
+ String receiverUrl = uidl.getStringVariable(fileId);
+ fileId = fileId.substring(4);
+ if (getWidgetForPaintable().fileIdToReceiver == null) {
+ getWidgetForPaintable().fileIdToReceiver = new HashMap<String, String>();
+ }
+ if ("".equals(receiverUrl)) {
+ Integer id = Integer.parseInt(fileId);
+ int indexOf = getWidgetForPaintable().fileIds
+ .indexOf(id);
+ if (indexOf != -1) {
+ getWidgetForPaintable().files.remove(indexOf);
+ getWidgetForPaintable().fileIds.remove(indexOf);
+ }
+ } else {
+ getWidgetForPaintable().fileIdToReceiver.put(fileId,
+ receiverUrl);
+ }
+ }
+ }
+ getWidgetForPaintable().startNextUpload();
+
+ getWidgetForPaintable().dragStartMode = uidl
+ .getIntAttribute(VDragAndDropWrapper.DRAG_START_MODE);
+ getWidgetForPaintable().initDragStartMode();
+ getWidgetForPaintable().html5DataFlavors = uidl
+ .getMapAttribute(VDragAndDropWrapper.HTML5_DATA_FLAVORS);
+ }
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VDragAndDropWrapper.class);
+ }
+
+ @Override
+ public VDragAndDropWrapper getWidgetForPaintable() {
+ return (VDragAndDropWrapper) super.getWidgetForPaintable();
+ }
+
+}
diff --git a/src/com/vaadin/ui/DragAndDropWrapper.java b/src/com/vaadin/ui/DragAndDropWrapper.java
index c6522f15c7..512b70e118 100644
--- a/src/com/vaadin/ui/DragAndDropWrapper.java
+++ b/src/com/vaadin/ui/DragAndDropWrapper.java
@@ -22,11 +22,12 @@ import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.StreamVariable;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.VDragAndDropWrapper;
+import com.vaadin.terminal.gwt.client.ui.VDragAndDropWrapperPaintable;
import com.vaadin.terminal.gwt.client.ui.dd.HorizontalDropLocation;
import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation;
@SuppressWarnings("serial")
-@ClientWidget(VDragAndDropWrapper.class)
+@ClientWidget(VDragAndDropWrapperPaintable.class)
public class DragAndDropWrapper extends CustomComponent implements DropTarget,
DragSource {