]> source.dussan.org Git - vaadin-framework.git/commitdiff
Split DragAndDropWrapper into widget + paintable
authorArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 07:59:01 +0000 (09:59 +0200)
committerArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 08:00:16 +0000 (10:00 +0200)
src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java
src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapperPaintable.java [new file with mode: 0644]
src/com/vaadin/ui/DragAndDropWrapper.java

index 3251a03d6afad2535f57e4d2312c873b1f8d4852..0297e8df3f2b94f79e94b1557d0a173155b22cb4 100644 (file)
@@ -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 (file)
index 0000000..1deb155
--- /dev/null
@@ -0,0 +1,71 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import java.util.HashMap;\r
+import java.util.Set;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+\r
+public class VDragAndDropWrapperPaintable extends VCustomComponentPaintable {\r
+\r
+    @Override\r
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+        getWidgetForPaintable().client = client;\r
+        super.updateFromUIDL(uidl, client);\r
+        if (!uidl.hasAttribute("cached") && !uidl.hasAttribute("hidden")) {\r
+            UIDL acceptCrit = uidl.getChildByTagName("-ac");\r
+            if (acceptCrit == null) {\r
+                getWidgetForPaintable().dropHandler = null;\r
+            } else {\r
+                if (getWidgetForPaintable().dropHandler == null) {\r
+                    getWidgetForPaintable().dropHandler = getWidgetForPaintable().new CustomDropHandler();\r
+                }\r
+                getWidgetForPaintable().dropHandler\r
+                        .updateAcceptRules(acceptCrit);\r
+            }\r
+\r
+            Set<String> variableNames = uidl.getVariableNames();\r
+            for (String fileId : variableNames) {\r
+                if (fileId.startsWith("rec-")) {\r
+                    String receiverUrl = uidl.getStringVariable(fileId);\r
+                    fileId = fileId.substring(4);\r
+                    if (getWidgetForPaintable().fileIdToReceiver == null) {\r
+                        getWidgetForPaintable().fileIdToReceiver = new HashMap<String, String>();\r
+                    }\r
+                    if ("".equals(receiverUrl)) {\r
+                        Integer id = Integer.parseInt(fileId);\r
+                        int indexOf = getWidgetForPaintable().fileIds\r
+                                .indexOf(id);\r
+                        if (indexOf != -1) {\r
+                            getWidgetForPaintable().files.remove(indexOf);\r
+                            getWidgetForPaintable().fileIds.remove(indexOf);\r
+                        }\r
+                    } else {\r
+                        getWidgetForPaintable().fileIdToReceiver.put(fileId,\r
+                                receiverUrl);\r
+                    }\r
+                }\r
+            }\r
+            getWidgetForPaintable().startNextUpload();\r
+\r
+            getWidgetForPaintable().dragStartMode = uidl\r
+                    .getIntAttribute(VDragAndDropWrapper.DRAG_START_MODE);\r
+            getWidgetForPaintable().initDragStartMode();\r
+            getWidgetForPaintable().html5DataFlavors = uidl\r
+                    .getMapAttribute(VDragAndDropWrapper.HTML5_DATA_FLAVORS);\r
+        }\r
+    }\r
+\r
+    @Override\r
+    protected Widget createWidget() {\r
+        return GWT.create(VDragAndDropWrapper.class);\r
+    }\r
+\r
+    @Override\r
+    public VDragAndDropWrapper getWidgetForPaintable() {\r
+        return (VDragAndDropWrapper) super.getWidgetForPaintable();\r
+    }\r
+\r
+}\r
index c6522f15c76d5b2992b724046bdba208670ceb60..512b70e118989183d0892348ad5ed89bdea2dbd0 100644 (file)
@@ -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 {