* 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
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);
}
}
}
+
+ public void onClose(CloseEvent<PopupPanel> event) {
+ removeShadowIfPresent();
+ }
}