From: Artur Signell Date: Tue, 15 Dec 2009 15:40:59 +0000 (+0000) Subject: Fix for #3120 - Add Window.setClosable() X-Git-Tag: 6.7.0.beta1~2141 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f816ce35fc60a624f958754732f77a358b241a84;p=vaadin-framework.git Fix for #3120 - Add Window.setClosable() svn changeset:10326/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 a2a64dcf5a..a7cf2f317a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VWindow.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VWindow.java @@ -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); } diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java index ad6ff57d6c..19ca1e5141 100644 --- a/src/com/vaadin/ui/Window.java +++ b/src/com/vaadin/ui/Window.java @@ -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); + } + }