From: Matti Tahvonen Date: Wed, 28 Nov 2007 09:13:05 +0000 (+0000) Subject: implemented modality and fixed ModalWindow demo X-Git-Tag: 6.7.0.beta1~5416 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dcfd85a71eb515dbd68912b59b62773065c56efb;p=vaadin-framework.git implemented modality and fixed ModalWindow demo svn changeset:3010/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/demo/ModalWindow.java b/src/com/itmill/toolkit/demo/ModalWindow.java index 6ba1cf9a1f..fa0a6a44a3 100644 --- a/src/com/itmill/toolkit/demo/ModalWindow.java +++ b/src/com/itmill/toolkit/demo/ModalWindow.java @@ -1,6 +1,5 @@ package com.itmill.toolkit.demo; -import com.itmill.toolkit.event.Action; import com.itmill.toolkit.ui.Button; import com.itmill.toolkit.ui.Label; import com.itmill.toolkit.ui.TextField; @@ -19,9 +18,10 @@ import com.itmill.toolkit.ui.Button.ClickListener; * @see com.itmill.toolkit.ui.Label */ public class ModalWindow extends com.itmill.toolkit.Application implements - Action.Handler, ClickListener { + ClickListener { private Window test; + private Button reopen; public void init() { @@ -36,47 +36,44 @@ public class ModalWindow extends com.itmill.toolkit.Application implements main.addComponent(f); // Main window button - Button b = new Button("Button on main window"); + Button b = new Button("Test Button in main window"); b.addListener(this); b.setTabIndex(2); main.addComponent(b); + reopen = new Button("Open modal subwindow"); + reopen.addListener(this); + reopen.setTabIndex(3); + main.addComponent(reopen); + + } + + public void buttonClick(ClickEvent event) { + if (event.getButton() == reopen) { + openSubWindow(); + } + getMainWindow().addComponent( + new Label("Button click: " + event.getButton().getCaption())); + } + + private void openSubWindow() { // Modal window test = new Window("Modal window"); - test.setStyle("modal"); - addWindow(test); + test.setModal(true); + getMainWindow().addWindow(test); test.addComponent(new Label( "You have to close this window before accessing others.")); // Textfield for modal window - f = new TextField(); + TextField f = new TextField(); f.setTabIndex(4); test.addComponent(f); f.focus(); // Modal window button - b = new Button("Button on modal window"); - b.setTabIndex(3); + Button b = new Button("Test Button in modal window"); + b.setTabIndex(5); b.addListener(this); test.addComponent(b); - - } - - public Action[] getActions(Object target, Object sender) { - Action actionA = new Action("Action A for " + target.toString()); - Action actionB = new Action("Action B for " + target.toString()); - Action[] actions = new Action[] { actionA, actionB }; - return actions; - } - - public void handleAction(Action action, Object sender, Object target) { - test.addComponent(new Label(action.getCaption() + " clicked on " - + target)); - - } - - public void buttonClick(ClickEvent event) { - test.addComponent(new Label("Clicked " + event)); - } } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java index a4454830e5..1545dc113f 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java @@ -96,6 +96,8 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { /** Last known positiony read from UIDL or updated to application connection */ private int uidlPositionY = -1; + private boolean modal = false; + public IWindow() { super(); int order = windowOrder.size(); @@ -190,6 +192,10 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { return; } + if (uidl.getBooleanAttribute("modal") != modal) { + setModal(!modal); + } + // Initialize the width from UIDL if (uidl.hasVariable("width")) { String width = uidl.getStringVariable("width"); @@ -271,6 +277,12 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { } + private void setModal(boolean modality) { + // TODO create transparent curtain to create visual clue that window is + // modal + modal = modality; + } + public void setPopupPosition(int left, int top) { super.setPopupPosition(left, top); if (left != uidlPositionX && client != null) { @@ -411,8 +423,13 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { } else if (resizing) { onResizeEvent(event); return false; + } else if (modal) { + // return false when modal and outside window + Element target = DOM.eventGetTarget(event); + if (!DOM.isOrHasChild(getElement(), target)) { + return false; + } } - // TODO return false when modal return true; } diff --git a/src/com/itmill/toolkit/ui/Window.java b/src/com/itmill/toolkit/ui/Window.java index 237dc5c984..27f07c9291 100644 --- a/src/com/itmill/toolkit/ui/Window.java +++ b/src/com/itmill/toolkit/ui/Window.java @@ -148,6 +148,8 @@ public class Window extends Panel implements URIHandler, ParameterHandler { private LinkedList notifications; + private boolean modal; + /* ********************************************************************* */ /** @@ -482,6 +484,10 @@ public class Window extends Panel implements URIHandler, ParameterHandler { String theme = getTheme(); target.addAttribute("theme", theme == null ? "" : theme); + if (modal) { + target.addAttribute("modal", true); + } + // Marks the main window if (getApplication() != null && this == getApplication().getMainWindow()) { @@ -1315,4 +1321,14 @@ public class Window extends Panel implements URIHandler, ParameterHandler { return styleName; } } + + /** + * Sets sub-window modal, so that widgets behind it cannot be accessed. + * + * @param modality + * true if modality is to be turned on + */ + public void setModal(boolean modality) { + modal = modality; + } }