]> source.dussan.org Git - vaadin-framework.git/commitdiff
CustomComponent without size calculations (#8313)
authorLeif Åstrand <leif@vaadin.com>
Fri, 10 Feb 2012 12:06:32 +0000 (14:06 +0200)
committerLeif Åstrand <leif@vaadin.com>
Fri, 10 Feb 2012 12:06:32 +0000 (14:06 +0200)
src/com/vaadin/terminal/gwt/client/ui/VCustomComponent.java
src/com/vaadin/terminal/gwt/client/ui/VCustomComponentPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java

index d8181cf00c48fb6b2fc7224c2290ecc02418686c..f552870a53e9c5ca85996e35592a8dd22705312d 100644 (file)
 
 package com.vaadin.terminal.gwt.client.ui;
 
-import java.util.Set;
-
 import com.google.gwt.user.client.ui.SimplePanel;
-import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.Container;
-import com.vaadin.terminal.gwt.client.RenderSpace;
-import com.vaadin.terminal.gwt.client.Util;
 
-public class VCustomComponent extends SimplePanel implements Container {
+public class VCustomComponent extends SimplePanel {
 
     private static final String CLASSNAME = "v-customcomponent";
-    private String height;
-    ApplicationConnection client;
-    boolean rendering;
-    private String width;
-    RenderSpace renderSpace = new RenderSpace();
 
     public VCustomComponent() {
         super();
         setStyleName(CLASSNAME);
     }
 
-    boolean updateDynamicSize() {
-        boolean updated = false;
-        if (isDynamicWidth()) {
-            int childWidth = Util.getRequiredWidth(getWidget());
-            getElement().getStyle().setPropertyPx("width", childWidth);
-            updated = true;
-        }
-        if (isDynamicHeight()) {
-            int childHeight = Util.getRequiredHeight(getWidget());
-            getElement().getStyle().setPropertyPx("height", childHeight);
-            updated = true;
-        }
-
-        return updated;
-    }
-
-    protected boolean isDynamicWidth() {
-        return width == null || width.equals("");
-    }
-
-    protected boolean isDynamicHeight() {
-        return height == null || height.equals("");
-    }
-
-    public boolean hasChildComponent(Widget component) {
-        if (getWidget() == component) {
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
-        if (hasChildComponent(oldComponent)) {
-            clear();
-            setWidget(newComponent);
-        } else {
-            throw new IllegalStateException();
-        }
-    }
-
-    public boolean requestLayout(Set<Widget> children) {
-        // If a child grows in size, it will not necessarily be calculated
-        // correctly unless we remove previous size definitions
-        if (isDynamicWidth()) {
-            getElement().getStyle().setProperty("width", "");
-        }
-        if (isDynamicHeight()) {
-            getElement().getStyle().setProperty("height", "");
-        }
-
-        return !updateDynamicSize();
-    }
-
-    public RenderSpace getAllocatedSpace(Widget child) {
-        return renderSpace;
-    }
-
-    @Override
-    public void setHeight(String height) {
-        super.setHeight(height);
-        renderSpace.setHeight(getElement().getOffsetHeight());
-
-        if (!height.equals(this.height)) {
-            this.height = height;
-            if (!rendering) {
-                client.handleComponentRelativeSize(getWidget());
-            }
-        }
-    }
-
-    @Override
-    public void setWidth(String width) {
-        super.setWidth(width);
-        renderSpace.setWidth(getElement().getOffsetWidth());
-
-        if (!width.equals(this.width)) {
-            this.width = width;
-            if (!rendering) {
-                client.handleComponentRelativeSize(getWidget());
-            }
-        }
-    }
-
 }
index 25289c6adb97e4d8c1001bffcfe1cd00764d928a..78a68609ea86d962f46198f79dd864e00d553ec6 100644 (file)
@@ -4,8 +4,6 @@
 package com.vaadin.terminal.gwt.client.ui;
 
 import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.Scheduler;
-import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.UIDL;
@@ -17,14 +15,10 @@ public class VCustomComponentPaintable extends
 
     @Override
     public void updateFromUIDL(UIDL uidl, final ApplicationConnection client) {
-        getWidgetForPaintable().rendering = true;
         super.updateFromUIDL(uidl, client);
         if (!isRealUpdate(uidl)) {
-            getWidgetForPaintable().rendering = false;
             return;
         }
-        getWidgetForPaintable().client = client;
-
         final UIDL child = uidl.getChildUIDL(0);
         if (child != null) {
             final VPaintableWidget paintable = client.getPaintable(child);
@@ -39,32 +33,6 @@ public class VCustomComponentPaintable extends
             }
             paintable.updateFromUIDL(child, client);
         }
-
-        boolean updateDynamicSize = getWidgetForPaintable().updateDynamicSize();
-        if (updateDynamicSize) {
-            Scheduler.get().scheduleDeferred(new Command() {
-                public void execute() {
-                    // FIXME deferred relative size update needed to fix some
-                    // scrollbar issues in sampler. This must be the wrong way
-                    // to do it. Might be that some other component is broken.
-                    client.handleComponentRelativeSize(getWidgetForPaintable());
-
-                }
-            });
-        }
-
-        getWidgetForPaintable().renderSpace.setWidth(getWidgetForPaintable()
-                .getElement().getOffsetWidth());
-        getWidgetForPaintable().renderSpace.setHeight(getWidgetForPaintable()
-                .getElement().getOffsetHeight());
-
-        /*
-         * Needed to update client size if the size of this component has
-         * changed and the child uses relative size(s).
-         */
-        client.runDescendentsLayout(getWidgetForPaintable());
-
-        getWidgetForPaintable().rendering = false;
     }
 
     @Override
index 0297e8df3f2b94f79e94b1557d0a173155b22cb4..1b4dab5a33be40788b98fee86321900e09e51b00 100644 (file)
@@ -563,11 +563,6 @@ public class VDragAndDropWrapper extends VCustomComponent implements
     }
 
     protected void deEmphasis(boolean doLayout) {
-        Size size = null;
-        if (doLayout) {
-            size = new RenderInformation.Size(getOffsetWidth(),
-                    getOffsetHeight());
-        }
         if (emphasizedVDrop != null) {
             VDragAndDropWrapper.setStyleName(getElement(), OVER_STYLE, false);
             VDragAndDropWrapper.setStyleName(getElement(), OVER_STYLE + "-"
@@ -576,7 +571,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements
                     + emphasizedHDrop.toString().toLowerCase(), false);
         }
         if (doLayout) {
-            handleVaadinRelatedSizeChange(size);
+            client.doLayout(false);
         }
     }
 
@@ -594,20 +589,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements
 
         // TODO build (to be an example) an emphasis mode where drag image
         // is fitted before or after the content
-        handleVaadinRelatedSizeChange(size);
-
-    }
-
-    protected void handleVaadinRelatedSizeChange(Size originalSize) {
-        if (isDynamicHeight() || isDynamicWidth()) {
-            if (!originalSize.equals(new RenderInformation.Size(
-                    getOffsetWidth(), getOffsetHeight()))) {
-                Util.notifyParentOfSizeChange(VDragAndDropWrapper.this, false);
-            }
-        }
-        client.handleComponentRelativeSize(VDragAndDropWrapper.this);
-        Util.notifyParentOfSizeChange(this, false);
-
+        client.doLayout(false);
     }
 
 }