From: Artur Signell Date: Sun, 2 Dec 2012 11:11:35 +0000 (+0200) Subject: Attach drag'n'drop drag image to overlay container (#10384) X-Git-Tag: 7.0.0.beta11~74^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F50%2F450%2F1;p=vaadin-framework.git Attach drag'n'drop drag image to overlay container (#10384) Change-Id: I8f47f1d7e88c3a36088e18cb72ff2c65ce65f22b --- 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 { } /** - * 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 *