]> source.dussan.org Git - vaadin-framework.git/commitdiff
#6716 Support for resizeLazy for sub window
authorArtur Signell <artur.signell@itmill.com>
Tue, 26 Apr 2011 15:37:03 +0000 (15:37 +0000)
committerArtur Signell <artur.signell@itmill.com>
Tue, 26 Apr 2011 15:37:03 +0000 (15:37 +0000)
svn changeset:18479/svn branch:6.6

src/com/vaadin/terminal/gwt/client/ui/VWindow.java
tests/src/com/vaadin/tests/components/window/LazyWindowResize.java

index dd0955907829049e1b5af4569c5a7351e917fe05..aae6cf0049a7c8e6201ab7dba1044b2d4e361e1e 100644 (file)
@@ -11,6 +11,7 @@ import java.util.Iterator;
 import java.util.Set;
 
 import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
 import com.google.gwt.event.dom.client.BlurEvent;
 import com.google.gwt.event.dom.client.BlurHandler;
 import com.google.gwt.event.dom.client.DomEvent.Type;
@@ -136,6 +137,8 @@ public class VWindow extends VOverlay implements Container,
 
     private boolean draggable = true;
 
+    private boolean resizeLazy = false;
+
     private Element modalityCurtain;
     private Element draggingCurtain;
 
@@ -178,6 +181,14 @@ public class VWindow extends VOverlay implements Container,
 
     private int bringToFrontSequence = -1;
 
+    private VLazyExecutor delayedContentsSizeUpdater = new VLazyExecutor(200,
+            new ScheduledCommand() {
+
+                public void execute() {
+                    updateContentsSize();
+                }
+            });
+
     public VWindow() {
         super(false, false, true); // no autohide, not modal, shadow
         // Different style of shadow for windows
@@ -297,6 +308,7 @@ public class VWindow extends VOverlay implements Container,
             if (uidl.getBooleanAttribute("resizable") != resizable) {
                 setResizable(!resizable);
             }
+            resizeLazy = uidl.hasAttribute(VView.RESIZE_LAZY);
 
             setDraggable(!uidl.hasAttribute("fixedposition"));
         }
@@ -1020,6 +1032,16 @@ public class VWindow extends VOverlay implements Container,
             client.updateVariable(id, "height", h, immediate);
         }
 
+        if (updateVariables || !resizeLazy) {
+            // Resize has finished or is not lazy
+            updateContentsSize();
+        } else {
+            // Lazy resize - wait for a while before re-rendering contents
+            delayedContentsSizeUpdater.trigger();
+        }
+    }
+
+    private void updateContentsSize() {
         // Update child widget dimensions
         if (client != null) {
             client.handleComponentRelativeSize((Widget) layout);
index 072343a604542aecc5435705dd2433de8fb0f38c..6c051f4b1e7bef6a0fdaf475128559375e8a80a4 100644 (file)
@@ -1,6 +1,7 @@
 package com.vaadin.tests.components.window;
 
 import com.vaadin.tests.components.AbstractTestCase;
+import com.vaadin.tests.util.Log;
 import com.vaadin.tests.util.LoremIpsum;
 import com.vaadin.ui.Button;
 import com.vaadin.ui.Button.ClickEvent;
@@ -8,12 +9,29 @@ import com.vaadin.ui.Button.ClickListener;
 import com.vaadin.ui.CheckBox;
 import com.vaadin.ui.Label;
 import com.vaadin.ui.Window;
+import com.vaadin.ui.Window.ResizeEvent;
+import com.vaadin.ui.Window.ResizeListener;
 
 public class LazyWindowResize extends AbstractTestCase {
 
     private Window mainWindow;
     private Window subWindow;
     private Button lazyMode;
+    private Log log = new Log(5);
+    private CheckBox resizeListenerCheckBox;
+
+    protected ResizeListener resizeListener = new ResizeListener() {
+
+        public void windowResized(ResizeEvent e) {
+            if (e.getWindow() == mainWindow) {
+                log.log("Main window resized");
+            } else {
+                log.log("Sub window resized");
+            }
+
+        }
+    };
+    private CheckBox immediateCheckBox;;;
 
     @Override
     protected String getDescription() {
@@ -44,7 +62,38 @@ public class LazyWindowResize extends AbstractTestCase {
                 setLazy(lazyMode.booleanValue());
             }
         });
+
+        resizeListenerCheckBox = new CheckBox("Resize listener");
+        resizeListenerCheckBox.setImmediate(true);
+        resizeListenerCheckBox.addListener(new ClickListener() {
+
+            public void buttonClick(ClickEvent event) {
+                if (resizeListenerCheckBox.booleanValue()) {
+                    subWindow.addListener(resizeListener);
+                    mainWindow.addListener(resizeListener);
+                } else {
+                    subWindow.removeListener(resizeListener);
+                    mainWindow.removeListener(resizeListener);
+                }
+
+            }
+
+        });
+        immediateCheckBox = new CheckBox("Windows immediate");
+        immediateCheckBox.setImmediate(true);
+        immediateCheckBox.addListener(new ClickListener() {
+
+            public void buttonClick(ClickEvent event) {
+                mainWindow.setImmediate(immediateCheckBox.booleanValue());
+                subWindow.setImmediate(immediateCheckBox.booleanValue());
+
+            }
+
+        });
         mainWindow.addComponent(lazyMode);
+        mainWindow.addComponent(resizeListenerCheckBox);
+        mainWindow.addComponent(immediateCheckBox);
+        mainWindow.addComponent(log);
         mainWindow.addComponent(new Label("<br/><br/>", Label.CONTENT_XHTML));
         mainWindow.addComponent(new Label(LoremIpsum.get(10000)));