]> source.dussan.org Git - vaadin-framework.git/commitdiff
implemented modality and fixed ModalWindow demo
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 28 Nov 2007 09:13:05 +0000 (09:13 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 28 Nov 2007 09:13:05 +0000 (09:13 +0000)
svn changeset:3010/svn branch:trunk

src/com/itmill/toolkit/demo/ModalWindow.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java
src/com/itmill/toolkit/ui/Window.java

index 6ba1cf9a1ff30a40b1286e5128337daf716369ca..fa0a6a44a3f5da24728b0f37385a823bbaf6c7bb 100644 (file)
@@ -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));
-
     }
 }
index a4454830e54fadeb0d01d560902b64fb8180d033..1545dc113f68910cf02b8e5bf22d2a42d4e4fb22 100644 (file)
@@ -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;
     }
 
index 237dc5c984e691c77ef8b3d48ec79d0a011e2fe6..27f07c9291ed08f01ee61baea5305fd720988724 100644 (file)
@@ -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;
+    }
 }