]> source.dussan.org Git - vaadin-framework.git/commitdiff
Test case and fix for #3133 - Window draggability disabling feature
authorArtur Signell <artur.signell@itmill.com>
Tue, 15 Dec 2009 16:42:50 +0000 (16:42 +0000)
committerArtur Signell <artur.signell@itmill.com>
Tue, 15 Dec 2009 16:42:50 +0000 (16:42 +0000)
svn changeset:10329/svn branch:6.2

src/com/vaadin/terminal/gwt/client/ui/VWindow.java
src/com/vaadin/ui/Window.java
tests/src/com/vaadin/tests/components/window/SubwindowDraggability.java [new file with mode: 0644]

index a7cf2f317ad9807f3fa65ab3c136f06a8414d20e..b84b7a77f38ec60a6dda23a3cdf2f5273214539b 100644 (file)
@@ -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;
index 19ca1e51416619c68d90726564d2496219ad8a52..134286ec51db31b4b2aa784676b5025a20d70559 100644 (file)
@@ -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.
-     * 
+     * <p/>
      * 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.
-     * 
+     * <p/>
      * 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.
+     * <p/>
+     * 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.
+     * <p/>
+     * 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 (file)
index 0000000..14cb5de
--- /dev/null
@@ -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;
+    }
+
+}