]> source.dussan.org Git - vaadin-framework.git/commitdiff
SplitPanel working with the MeasureManager (#8313)
authorLeif Åstrand <leif@vaadin.com>
Tue, 14 Feb 2012 08:34:16 +0000 (10:34 +0200)
committerLeif Åstrand <leif@vaadin.com>
Tue, 14 Feb 2012 08:34:16 +0000 (10:34 +0200)
src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanel.java
src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java

index f1a932b3a31cae613cf39ace00f4a348a3ba8974..9a24384f1e3bc86c1a9bcffe7c2109591dc7447b 100644 (file)
@@ -4,9 +4,8 @@
 
 package com.vaadin.terminal.gwt.client.ui;
 
-import java.util.Set;
-
 import com.google.gwt.dom.client.Node;
+import com.google.gwt.dom.client.Style;
 import com.google.gwt.event.dom.client.TouchCancelEvent;
 import com.google.gwt.event.dom.client.TouchCancelHandler;
 import com.google.gwt.event.dom.client.TouchEndEvent;
@@ -22,15 +21,10 @@ import com.google.gwt.user.client.ui.ComplexPanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.BrowserInfo;
-import com.vaadin.terminal.gwt.client.Container;
-import com.vaadin.terminal.gwt.client.ContainerResizedListener;
-import com.vaadin.terminal.gwt.client.RenderInformation;
-import com.vaadin.terminal.gwt.client.RenderSpace;
 import com.vaadin.terminal.gwt.client.Util;
 import com.vaadin.terminal.gwt.client.VConsole;
 
-public class VAbstractSplitPanel extends ComplexPanel implements Container,
-        ContainerResizedListener {
+public class VAbstractSplitPanel extends ComplexPanel {
 
     private boolean enabled = false;
 
@@ -78,21 +72,10 @@ public class VAbstractSplitPanel extends ComplexPanel implements Container,
 
     ApplicationConnection client;
 
-    private String width = "";
-
-    private String height = "";
-
-    private RenderSpace firstRenderSpace = new RenderSpace(0, 0, true);
-    private RenderSpace secondRenderSpace = new RenderSpace(0, 0, true);
-
-    RenderInformation renderInformation = new RenderInformation();
-
     String id;
 
     boolean immediate;
 
-    boolean rendering = false;
-
     /* The current position of the split handle in either percentages or pixels */
     String position;
 
@@ -254,36 +237,33 @@ public class VAbstractSplitPanel extends ComplexPanel implements Container,
                             : getOffsetHeight()) + "px";
         }
 
+        String attributeName;
         if (orientation == ORIENTATION_HORIZONTAL) {
             if (positionReversed) {
-                DOM.setStyleAttribute(splitter, "right", pos);
+                attributeName = "right";
             } else {
-                DOM.setStyleAttribute(splitter, "left", pos);
+                attributeName = "left";
             }
         } else {
             if (positionReversed) {
-                DOM.setStyleAttribute(splitter, "bottom", pos);
+                attributeName = "bottom";
             } else {
-                DOM.setStyleAttribute(splitter, "top", pos);
+                attributeName = "top";
             }
         }
 
-        iLayout();
-        client.runDescendentsLayout(this);
+        Style style = splitter.getStyle();
+        if (!pos.equals(style.getProperty(attributeName))) {
+            style.setProperty(attributeName, pos);
+            updateSizes();
+        }
     }
 
-    /*
-     * Calculates absolutely positioned container places/sizes (non-Javadoc)
-     * 
-     * @see com.vaadin.terminal.gwt.client.NeedsLayout#layout()
-     */
-    public void iLayout() {
+    void updateSizes() {
         if (!isAttached()) {
             return;
         }
 
-        renderInformation.updateSize(getElement());
-
         int wholeSize;
         int pixelPosition;
 
@@ -313,12 +293,6 @@ public class VAbstractSplitPanel extends ComplexPanel implements Container,
             DOM.setStyleAttribute(secondContainer, "left",
                     (pixelPosition + getSplitterSize()) + "px");
 
-            int contentHeight = renderInformation.getRenderedSize().getHeight();
-            firstRenderSpace.setHeight(contentHeight);
-            firstRenderSpace.setWidth(pixelPosition);
-            secondRenderSpace.setHeight(contentHeight);
-            secondRenderSpace.setWidth(secondContainerWidth);
-
             break;
         case ORIENTATION_VERTICAL:
             wholeSize = DOM.getElementPropertyInt(wrapper, "clientHeight");
@@ -346,12 +320,6 @@ public class VAbstractSplitPanel extends ComplexPanel implements Container,
             DOM.setStyleAttribute(secondContainer, "top",
                     (pixelPosition + getSplitterSize()) + "px");
 
-            int contentWidth = renderInformation.getRenderedSize().getWidth();
-            firstRenderSpace.setHeight(pixelPosition);
-            firstRenderSpace.setWidth(contentWidth);
-            secondRenderSpace.setHeight(secondContainerHeight);
-            secondRenderSpace.setWidth(contentWidth);
-
             break;
         }
 
@@ -606,79 +574,6 @@ public class VAbstractSplitPanel extends ComplexPanel implements Container,
         return splitterSize;
     }
 
-    @Override
-    public void setHeight(String height) {
-        if (this.height.equals(height)) {
-            return;
-        }
-
-        this.height = height;
-        super.setHeight(height);
-
-        if (!rendering && client != null) {
-            setSplitPosition(position);
-        }
-    }
-
-    @Override
-    public void setWidth(String width) {
-        if (this.width.equals(width)) {
-            return;
-        }
-
-        this.width = width;
-        super.setWidth(width);
-
-        if (!rendering && client != null) {
-            setSplitPosition(position);
-        }
-    }
-
-    public RenderSpace getAllocatedSpace(Widget child) {
-        if (child == firstChild) {
-            return firstRenderSpace;
-        } else if (child == secondChild) {
-            return secondRenderSpace;
-        }
-
-        return null;
-    }
-
-    public boolean hasChildComponent(Widget component) {
-        return (component != null && (component == firstChild || component == secondChild));
-    }
-
-    public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
-        if (oldComponent == firstChild) {
-            setFirstWidget(newComponent);
-        } else if (oldComponent == secondChild) {
-            setSecondWidget(newComponent);
-        }
-    }
-
-    public boolean requestLayout(Set<Widget> children) {
-        // content size change might cause change to its available space
-        // (scrollbars)
-        for (Widget widget : children) {
-            client.handleComponentRelativeSize(widget);
-        }
-        if (height != null && width != null) {
-            /*
-             * If the height and width has been specified the child components
-             * cannot make the size of the layout change
-             */
-
-            return true;
-        }
-
-        if (renderInformation.updateSize(getElement())) {
-            return false;
-        } else {
-            return true;
-        }
-
-    }
-
     /**
      * Updates the new split position back to server.
      */
index ccf3119d132cc3fe2e6b9468184530498fc996ce..8b21c26960a80548be2f22aefb13b3fb4d2a5cb4 100644 (file)
@@ -16,7 +16,7 @@ import com.vaadin.terminal.gwt.client.VPaintableMap;
 import com.vaadin.terminal.gwt.client.VPaintableWidget;
 
 public abstract class VAbstractSplitPanelPaintable extends
-        VAbstractPaintableWidgetContainer {
+        VAbstractPaintableWidgetContainer implements ResizeRequired {
 
     public static final String SPLITTER_CLICK_EVENT_IDENTIFIER = "sp_click";
 
@@ -68,13 +68,11 @@ public abstract class VAbstractSplitPanelPaintable extends
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
         getWidgetForPaintable().client = client;
         getWidgetForPaintable().id = uidl.getId();
-        getWidgetForPaintable().rendering = true;
 
         getWidgetForPaintable().immediate = uidl.hasAttribute("immediate");
 
         super.updateFromUIDL(uidl, client);
         if (!isRealUpdate(uidl)) {
-            getWidgetForPaintable().rendering = false;
             return;
         }
         getWidgetForPaintable().setEnabled(
@@ -123,15 +121,15 @@ public abstract class VAbstractSplitPanelPaintable extends
         newFirstChildPaintable.updateFromUIDL(uidl.getChildUIDL(0), client);
         newSecondChildPaintable.updateFromUIDL(uidl.getChildUIDL(1), client);
 
-        getWidgetForPaintable().renderInformation
-                .updateSize(getWidgetForPaintable().getElement());
-
         // This is needed at least for cases like #3458 to take
         // appearing/disappearing scrollbars into account.
         client.runDescendentsLayout(getWidgetForPaintable());
+    }
 
-        getWidgetForPaintable().rendering = false;
-
+    public void onResize() {
+        VAbstractSplitPanel splitPanel = getWidgetForPaintable();
+        splitPanel.setSplitPosition(splitPanel.position);
+        splitPanel.updateSizes();
     }
 
     @Override