summaryrefslogtreecommitdiffstats
path: root/client/src/com
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-12-02 13:11:35 +0200
committerArtur Signell <artur@vaadin.com>2012-12-02 15:16:37 +0200
commit2ba840711a1f482c48c4c97879123fecf988faba (patch)
treeb1d15952cc753cadec5dc9a110db2fad8ea9fe7d /client/src/com
parent1c4890ea52a3e5b7a4b47bef4cb4499b095fe77d (diff)
downloadvaadin-framework-2ba840711a1f482c48c4c97879123fecf988faba.tar.gz
vaadin-framework-2ba840711a1f482c48c4c97879123fecf988faba.zip
Attach drag'n'drop drag image to overlay container (#10384)
Change-Id: I8f47f1d7e88c3a36088e18cb72ff2c65ce65f22b
Diffstat (limited to 'client/src/com')
-rw-r--r--client/src/com/vaadin/client/ui/VOverlay.java55
-rw-r--r--client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java27
2 files changed, 61 insertions, 21 deletions
diff --git a/client/src/com/vaadin/client/ui/VOverlay.java b/client/src/com/vaadin/client/ui/VOverlay.java
index dc6c7e4dff..ec09fbab69 100644
--- a/client/src/com/vaadin/client/ui/VOverlay.java
+++ b/client/src/com/vaadin/client/ui/VOverlay.java
@@ -34,6 +34,7 @@ import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.BrowserInfo;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.Util;
+import com.vaadin.client.VConsole;
/**
* In Vaadin UI this Overlay should always be used for all elements that
@@ -637,32 +638,48 @@ public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> {
}
/**
- * Gets the 'overlay container' element pertaining to the given
- * {@link ApplicationConnection}. Each overlay should be created in a
- * overlay container element, so that the correct theme and styles can be
- * applied.
+ * Gets the 'overlay container' element. Tries to find the current
+ * {@link ApplicationConnection} using {@link #getApplicationConnection()}.
*
- * @param ac
- * @return
+ * @return the overlay container element for the current
+ * {@link ApplicationConnection} or another element if the current
+ * {@link ApplicationConnection} cannot be determined.
*/
public Element getOverlayContainer() {
ApplicationConnection ac = getApplicationConnection();
if (ac == null) {
- // could not figure out which one we belong to, styling might fail
+ // could not figure out which one we belong to, styling will
+ // probably fail
+ VConsole.error("Could not determin ApplicationConnection for Overlay. Overlay will be attached directly to the root panel");
return RootPanel.get().getElement();
} else {
- String id = ac.getConfiguration().getRootPanelId();
- id = id += "-overlays";
- Element container = DOM.getElementById(id);
- if (container == null) {
- container = DOM.createDiv();
- container.setId(id);
- String styles = ac.getUIConnector().getWidget().getParent()
- .getStyleName();
- container.setClassName(styles);
- RootPanel.get().getElement().appendChild(container);
- }
- return container;
+ return getOverlayContainer(ac);
}
}
+
+ /**
+ * Gets the 'overlay container' element pertaining to the given
+ * {@link ApplicationConnection}. Each overlay should be created in a
+ * overlay container element, so that the correct theme and styles can be
+ * applied.
+ *
+ * @param ac
+ * A reference to {@link ApplicationConnection}
+ * @return The overlay container
+ */
+ public static Element getOverlayContainer(ApplicationConnection ac) {
+ String id = ac.getConfiguration().getRootPanelId();
+ id = id += "-overlays";
+ Element container = DOM.getElementById(id);
+ if (container == null) {
+ container = DOM.createDiv();
+ container.setId(id);
+ String styles = ac.getUIConnector().getWidget().getParent()
+ .getStyleName();
+ container.setClassName(styles);
+ RootPanel.get().getElement().appendChild(container);
+ }
+ return container;
+ }
+
}
diff --git a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java
index 6667dc7438..ae14218fff 100644
--- a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java
+++ b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java
@@ -39,7 +39,9 @@ import com.vaadin.client.ComponentConnector;
import com.vaadin.client.MouseEventDetailsBuilder;
import com.vaadin.client.UIDL;
import com.vaadin.client.Util;
+import com.vaadin.client.VConsole;
import com.vaadin.client.ValueMap;
+import com.vaadin.client.ui.VOverlay;
import com.vaadin.shared.ApplicationConstants;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.dd.DragEventType;
@@ -567,7 +569,7 @@ public class VDragAndDropManager {
private void clearDragElement() {
if (dragElement != null) {
if (dragElement.getParentElement() != null) {
- RootPanel.getBodyElement().removeChild(dragElement);
+ dragElement.removeFromParent();
}
dragElement = null;
}
@@ -708,7 +710,15 @@ public class VDragAndDropManager {
@Override
public void run() {
if (dragElement != null && dragElement.getParentElement() == null) {
- RootPanel.getBodyElement().appendChild(dragElement);
+ ApplicationConnection connection = getCurrentDragApplicationConnection();
+ Element dragImageParent;
+ if (connection == null) {
+ VConsole.error("Could not determine ApplicationConnection for current drag operation. The drag image will likely look broken");
+ dragImageParent = RootPanel.getBodyElement();
+ } else {
+ dragImageParent = VOverlay.getOverlayContainer(connection);
+ }
+ dragImageParent.appendChild(dragElement);
}
}
@@ -720,6 +730,19 @@ public class VDragAndDropManager {
return serverCallback != null;
}
+ protected ApplicationConnection getCurrentDragApplicationConnection() {
+ if (currentDrag == null) {
+ return null;
+ }
+
+ final ComponentConnector dragSource = currentDrag.getTransferable()
+ .getDragSource();
+ if (dragSource == null) {
+ return null;
+ }
+ return dragSource.getConnection();
+ }
+
/**
* Method to que tasks until all dd related server visits are done
*