From: Artur Signell Date: Tue, 15 Dec 2009 16:42:50 +0000 (+0000) Subject: Test case and fix for #3133 - Window draggability disabling feature X-Git-Tag: 6.7.0.beta1~2139 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bdcccace1a888d2653df96864e4ebd5f7077161c;p=vaadin-framework.git Test case and fix for #3133 - Window draggability disabling feature svn changeset:10329/svn branch:6.2 --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VWindow.java b/src/com/vaadin/terminal/gwt/client/ui/VWindow.java index a7cf2f317a..b84b7a77f3 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VWindow.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VWindow.java @@ -118,6 +118,8 @@ public class VWindow extends VOverlay implements Container, ScrollListener { private boolean resizable = true; + private boolean draggable = true; + private Element modalityCurtain; private Element draggingCurtain; @@ -260,6 +262,8 @@ public class VWindow extends VOverlay implements Container, ScrollListener { if (uidl.getBooleanAttribute("resizable") != resizable) { setResizable(!resizable); } + + setDraggable(!uidl.hasAttribute("fixedposition")); } if (client.updateComponent(this, uidl, false)) { @@ -458,6 +462,21 @@ public class VWindow extends VOverlay implements Container, ScrollListener { } + private void setDraggable(boolean draggable) { + if (this.draggable == draggable) { + return; + } + + this.draggable = draggable; + + if (!this.draggable) { + header.getStyle().setProperty("cursor", "default"); + } else { + header.getStyle().setProperty("cursor", ""); + } + + } + private void setNaturalWidth() { /* * Use max(layout width, window width) i.e layout content width or @@ -989,14 +1008,16 @@ public class VWindow extends VOverlay implements Container, ScrollListener { if (!isActive()) { bringToFront(); } - showDraggingCurtain(true); - dragging = true; - startX = DOM.eventGetScreenX(event); - startY = DOM.eventGetScreenY(event); - origX = DOM.getAbsoluteLeft(getElement()); - origY = DOM.getAbsoluteTop(getElement()); - DOM.setCapture(getElement()); - DOM.eventPreventDefault(event); + if (draggable) { + showDraggingCurtain(true); + dragging = true; + startX = DOM.eventGetScreenX(event); + startY = DOM.eventGetScreenY(event); + origX = DOM.getAbsoluteLeft(getElement()); + origY = DOM.getAbsoluteTop(getElement()); + DOM.setCapture(getElement()); + DOM.eventPreventDefault(event); + } break; case Event.ONMOUSEUP: dragging = false; diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java index 19ca1e5141..134286ec51 100644 --- a/src/com/vaadin/ui/Window.java +++ b/src/com/vaadin/ui/Window.java @@ -116,6 +116,8 @@ public class Window extends Panel implements URIHandler, ParameterHandler { private boolean resizable = true; + private boolean draggable = true; + private boolean centerRequested = false; private Focusable pendingFocus; @@ -499,6 +501,11 @@ public class Window extends Panel implements URIHandler, ParameterHandler { target.addAttribute("resizable", true); } + if (!draggable) { + // Inverted to prevent an extra attribute for almost all sub windows + target.addAttribute("fixedposition", true); + } + if (centerRequested) { target.addAttribute("center", true); centerRequested = false; @@ -1701,7 +1708,7 @@ public class Window extends Panel implements URIHandler, ParameterHandler { * Note! For historical reasons readonly controls the closability of the sub * window and therefore readonly and closable affect each other. Setting * readonly to true will set closable to false and vice versa. - * + *

* Closable only applies to sub windows, not to browser level windows. * * @return true if the sub window can be closed by the user. @@ -1711,7 +1718,7 @@ public class Window extends Panel implements URIHandler, ParameterHandler { } /** - * Set the closable status for the sub window. If a sub window is closable + * Sets the closable status for the sub window. If a sub window is closable * it typically shows an X in the upper right corner. Clicking on the X * sends a close event to the server. Setting closable to false will remove * the X from the sub window and prevent the user from closing the window. @@ -1719,7 +1726,7 @@ public class Window extends Panel implements URIHandler, ParameterHandler { * Note! For historical reasons readonly controls the closability of the sub * window and therefore readonly and closable affect each other. Setting * readonly to true will set closable to false and vice versa. - * + *

* Closable only applies to sub windows, not to browser level windows. * * @param closable @@ -1729,4 +1736,31 @@ public class Window extends Panel implements URIHandler, ParameterHandler { setReadOnly(!closable); } + /** + * Indicates whether a sub window can be dragged or not. By default a sub + * window is draggable. + *

+ * Draggable only applies to sub windows, not to browser level windows. + * + * @param draggable + * true if the sub window can be dragged by the user + */ + public boolean isDraggable() { + return draggable; + } + + /** + * Enables or disables that a sub window can be dragged (moved) by the user. + * By default a sub window is draggable. + *

+ * Draggable only applies to sub windows, not to browser level windows. + * + * @param draggable + * true if the sub window can be dragged by the user + */ + public void setDraggable(boolean draggable) { + this.draggable = draggable; + requestRepaint(); + } + } diff --git a/tests/src/com/vaadin/tests/components/window/SubwindowDraggability.java b/tests/src/com/vaadin/tests/components/window/SubwindowDraggability.java new file mode 100644 index 0000000000..14cb5dedd0 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/window/SubwindowDraggability.java @@ -0,0 +1,46 @@ +package com.vaadin.tests.components.window; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Window; +import com.vaadin.ui.Button.ClickEvent; + +public class SubwindowDraggability extends TestBase { + + @Override + protected void setup() { + final Window draggableSubWindow = new Window("Draggable sub window"); + draggableSubWindow.setHeight("300px"); + final Window fixedSubWindow = new Window("Fixed sub window"); + fixedSubWindow.setHeight("200px"); + fixedSubWindow.setDraggable(false); + + fixedSubWindow.center(); + getMainWindow().addWindow(draggableSubWindow); + getMainWindow().addWindow(fixedSubWindow); + + Button b = new Button("Swap", new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + boolean b = draggableSubWindow.isDraggable(); + + draggableSubWindow.setDraggable(!b); + fixedSubWindow.setDraggable(b); + + } + + }); + addComponent(b); + } + + @Override + protected String getDescription() { + return "Two sub windows. One is draggable, the other one is fixed and cannot be moved by the user"; + } + + @Override + protected Integer getTicketNumber() { + return 3133; + } + +}