]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #3120 - Add Window.setClosable()
authorArtur Signell <artur.signell@itmill.com>
Tue, 15 Dec 2009 15:40:59 +0000 (15:40 +0000)
committerArtur Signell <artur.signell@itmill.com>
Tue, 15 Dec 2009 15:40:59 +0000 (15:40 +0000)
svn changeset:10326/svn branch:6.2

src/com/vaadin/terminal/gwt/client/ui/VWindow.java
src/com/vaadin/ui/Window.java

index a2a64dcf5a09d4d212e7c088d77ca2e96474cfd2..a7cf2f317ad9807f3fa65ab3c136f06a8414d20e 100644 (file)
@@ -123,7 +123,7 @@ public class VWindow extends VOverlay implements Container, ScrollListener {
 
     private Element headerText;
 
-    private boolean readonly;
+    private boolean closable = true;
 
     boolean dynamicWidth = false;
     boolean dynamicHeight = false;
@@ -268,9 +268,7 @@ public class VWindow extends VOverlay implements Container, ScrollListener {
 
         immediate = uidl.hasAttribute("immediate");
 
-        if (isReadOnly() != uidl.getBooleanAttribute("readonly")) {
-            setReadOnly(!isReadOnly());
-        }
+        setClosable(!uidl.getBooleanAttribute("readonly"));
 
         // Initialize the position form UIDL
         try {
@@ -530,17 +528,36 @@ public class VWindow extends VOverlay implements Container, ScrollListener {
 
     }
 
-    private void setReadOnly(boolean readonly) {
-        this.readonly = readonly;
-        if (readonly) {
-            DOM.setStyleAttribute(closeBox, "display", "none");
-        } else {
+    /**
+     * Sets the closable state of the window. Additionally hides/shows the close
+     * button according to the new state.
+     * 
+     * @param closable
+     *            true if the window can be closed by the user
+     */
+    protected void setClosable(boolean closable) {
+        if (this.closable == closable) {
+            return;
+        }
+
+        this.closable = closable;
+        if (closable) {
             DOM.setStyleAttribute(closeBox, "display", "");
+        } else {
+            DOM.setStyleAttribute(closeBox, "display", "none");
         }
+
     }
 
-    private boolean isReadOnly() {
-        return readonly;
+    /**
+     * Returns the closable state of the sub window. If the sub window is
+     * closable a decoration (typically an X) is shown to the user. By clicking
+     * on the X the user can close the window.
+     * 
+     * @return true if the sub window is closable
+     */
+    protected boolean isClosable() {
+        return closable;
     }
 
     @Override
@@ -741,7 +758,7 @@ public class VWindow extends VOverlay implements Container, ScrollListener {
                 onResizeEvent(event);
                 event.cancelBubble(true);
             } else if (target == closeBox) {
-                if (type == Event.ONCLICK) {
+                if (type == Event.ONCLICK && isClosable()) {
                     onCloseClick();
                     event.cancelBubble(true);
                 }
index ad6ff57d6cabd2514641f5e26870cc1a2cc19dd6..19ca1e51416619c68d90726564d2496219ad8a52 100644 (file)
@@ -914,7 +914,7 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
             setPositionY(y < 0 ? -1 : y);
         }
 
-        if (!isReadOnly()) {
+        if (isClosable()) {
             // Closing
             final Boolean close = (Boolean) variables.get("close");
             if (close != null && close.booleanValue()) {
@@ -1690,4 +1690,43 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
 
         requestRepaint();
     }
+
+    /**
+     * Returns the closable status of 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.
+     * 
+     * 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.
+     */
+    public boolean isClosable() {
+        return !isReadOnly();
+    }
+
+    /**
+     * Set 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.
+     * 
+     * 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
+     *            determines if the sub window can be closed by the user.
+     */
+    public void setClosable(boolean closable) {
+        setReadOnly(!closable);
+    }
+
 }