]> source.dussan.org Git - vaadin-framework.git/commitdiff
shadow visibility now controllable outside constructor phase
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 7 Jun 2011 13:28:22 +0000 (13:28 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 7 Jun 2011 13:28:22 +0000 (13:28 +0000)
svn changeset:19265/svn branch:6.6

src/com/vaadin/terminal/gwt/client/ui/VOverlay.java

index f9e8aa1f6b239ab13c019f62049f461a2247a68b..ae8b2dd9c35e4ff40f62ee8d891d0c0e3d067f05 100644 (file)
@@ -22,7 +22,7 @@ import com.vaadin.terminal.gwt.client.Util;
  * temporary float over other components like context menus etc. This is to deal
  * stacking order correctly with VWindow objects.
  */
-public class VOverlay extends PopupPanel {
+public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> {
 
     /*
      * The z-index value from where all overlays live. This can be overridden in
@@ -84,21 +84,36 @@ public class VOverlay extends PopupPanel {
 
     public VOverlay(boolean autoHide, boolean modal, boolean showShadow) {
         super(autoHide, modal);
-        if (showShadow) {
-            shadow = DOM.createDiv();
-            shadow.setClassName(CLASSNAME_SHADOW);
-            shadow.setInnerHTML(SHADOW_HTML);
-            DOM.setStyleAttribute(shadow, "position", "absolute");
-
-            addCloseHandler(new CloseHandler<PopupPanel>() {
-                public void onClose(CloseEvent<PopupPanel> event) {
-                    removeShadowIfPresent();
-                }
-            });
-        }
+        setShadowEnabled(showShadow);
         adjustZIndex();
     }
 
+    /**
+     * Method to controle whether DOM elements for shadow are added. With this
+     * method subclasses can control displaying of shadow also after the
+     * constructor.
+     * 
+     * @param enabled true if shadow should be displayed
+     */
+    protected void setShadowEnabled(boolean enabled) {
+        if (enabled != isShadowEnabled()) {
+            if (enabled) {
+                shadow = DOM.createDiv();
+                shadow.setClassName(CLASSNAME_SHADOW);
+                shadow.setInnerHTML(SHADOW_HTML);
+                DOM.setStyleAttribute(shadow, "position", "absolute");
+                addCloseHandler(this);
+            } else {
+                removeShadowIfPresent();
+                shadow = null;
+            }
+        }
+    }
+    
+    protected boolean isShadowEnabled() {
+        return shadow != null;
+    }
+
     private void removeShadowIfPresent() {
         if (shadow != null && shadow.getParentElement() != null) {
             shadow.getParentElement().removeChild(shadow);
@@ -354,4 +369,8 @@ public class VOverlay extends PopupPanel {
             }
         }
     }
+
+    public void onClose(CloseEvent<PopupPanel> event) {
+        removeShadowIfPresent();
+    }
 }