diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-02-27 14:02:33 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-02-27 14:02:33 +0200 |
commit | 773044eacc3986d768bf6668da1c201d2bbb19bf (patch) | |
tree | 72ad5e38c75cb93f0868936811029bdef9840e49 /src/com/vaadin/terminal/gwt/client/Util.java | |
parent | c12fe813927ca5226cb4ee9437650740ba001e42 (diff) | |
parent | a9541c3abdb4805ee905864d8942a62fc7bbcae2 (diff) | |
download | vaadin-framework-773044eacc3986d768bf6668da1c201d2bbb19bf.tar.gz vaadin-framework-773044eacc3986d768bf6668da1c201d2bbb19bf.zip |
Merge branch 'layoutperformance'
Conflicts:
src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
src/com/vaadin/terminal/gwt/client/Util.java
src/com/vaadin/terminal/gwt/client/VCaption.java
src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java
src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VOrderedLayoutPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java
src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java
src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java
Diffstat (limited to 'src/com/vaadin/terminal/gwt/client/Util.java')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/Util.java | 181 |
1 files changed, 26 insertions, 155 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/Util.java b/src/com/vaadin/terminal/gwt/client/Util.java index be78959830..a563a534d5 100644 --- a/src/com/vaadin/terminal/gwt/client/Util.java +++ b/src/com/vaadin/terminal/gwt/client/Util.java @@ -6,11 +6,7 @@ package com.vaadin.terminal.gwt.client; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; +import java.util.List; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; @@ -25,7 +21,6 @@ import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.EventListener; -import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.RootPanel; @@ -67,30 +62,6 @@ public class Util { return el; }-*/; - private static final int LAZY_SIZE_CHANGE_TIMEOUT = 400; - private static Set<Widget> latelyChangedWidgets = new HashSet<Widget>(); - - private static Timer lazySizeChangeTimer = new Timer() { - private boolean lazySizeChangeTimerScheduled = false; - - @Override - public void run() { - componentSizeUpdated(latelyChangedWidgets); - latelyChangedWidgets.clear(); - lazySizeChangeTimerScheduled = false; - } - - @Override - public void schedule(int delayMillis) { - if (lazySizeChangeTimerScheduled) { - cancel(); - } else { - lazySizeChangeTimerScheduled = true; - } - super.schedule(delayMillis); - } - }; - /** * This helper method can be called if components size have been changed * outside rendering phase. It notifies components parent about the size @@ -108,58 +79,40 @@ public class Util { * run componentSizeUpdated lazyly */ public static void notifyParentOfSizeChange(Widget widget, boolean lazy) { - if (lazy) { - latelyChangedWidgets.add(widget); - lazySizeChangeTimer.schedule(LAZY_SIZE_CHANGE_TIMEOUT); - } else { - Set<Widget> widgets = new HashSet<Widget>(); - widgets.add(widget); - Util.componentSizeUpdated(widgets); + ApplicationConnection applicationConnection = findApplicationConnectionFor(widget); + if (applicationConnection != null) { + applicationConnection.doLayout(lazy); } } - /** - * Called when the size of one or more widgets have changed during - * rendering. Finds parent container and notifies them of the size change. - * - * @param paintables - */ - public static void componentSizeUpdated(Set<Widget> widgets) { - if (widgets.isEmpty()) { - return; - } + private static boolean findAppConnectionWarningDisplayed = false; - Map<Container, Set<Widget>> childWidgets = new HashMap<Container, Set<Widget>>(); + private static ApplicationConnection findApplicationConnectionFor( + Widget widget) { + if (!findAppConnectionWarningDisplayed) { + findAppConnectionWarningDisplayed = true; + VConsole.log("Warning: Using Util.findApplicationConnectionFor which should be eliminated once there is a better way to find the ApplicationConnection for a Paintable"); + } - for (Widget widget : widgets) { - if (!widget.isAttached()) { + List<ApplicationConnection> runningApplications = ApplicationConfiguration + .getRunningApplications(); + for (ApplicationConnection applicationConnection : runningApplications) { + VPaintableMap paintableMap = applicationConnection + .getPaintableMap(); + VPaintableWidget paintable = paintableMap.getPaintable(widget); + if (paintable == null) { continue; } - - // ApplicationConnection.getConsole().log( - // "Widget " + Util.getSimpleName(widget) + " size updated"); - Widget parent = widget.getParent(); - while (parent != null && !(parent instanceof Container)) { - parent = parent.getParent(); - } - if (parent != null) { - Set<Widget> set = childWidgets.get(parent); - if (set == null) { - set = new HashSet<Widget>(); - childWidgets.put((Container) parent, set); + String pid = paintableMap.getPid(paintable); + if (pid != null) { + VPaintable otherPaintable = paintableMap.getPaintable(pid); + if (otherPaintable == paintable) { + return applicationConnection; } - set.add(widget); - } - } - - Set<Widget> parentChanges = new HashSet<Widget>(); - for (Container parent : childWidgets.keySet()) { - if (!parent.requestLayout(childWidgets.get(parent))) { - parentChanges.add((Widget) parent); } } - componentSizeUpdated(parentChanges); + return null; } public static float parseRelativeSize(String size) { @@ -175,26 +128,6 @@ public class Util { } } - /** - * Returns closest parent Widget in hierarchy that implements Container - * interface - * - * @param component - * @return closest parent Container - */ - public static Container getLayout(Widget component) { - Widget parent = component.getParent(); - while (parent != null && !(parent instanceof Container)) { - parent = parent.getParent(); - } - if (parent != null) { - assert ((Container) parent).hasChildComponent(component); - - return (Container) parent; - } - return null; - } - private static final Element escapeHtmlHelper = DOM.createDiv(); /** @@ -605,20 +538,7 @@ public class Util { public static void updateRelativeChildrenAndSendSizeUpdateEvent( ApplicationConnection client, HasWidgets container, Widget widget) { - /* - * Relative sized children must be updated first so the component has - * the correct outer dimensions when signaling a size change to the - * parent. - */ - Iterator<Widget> childIterator = container.iterator(); - while (childIterator.hasNext()) { - Widget w = childIterator.next(); - client.handleComponentRelativeSize(w); - } - - HashSet<Widget> widgets = new HashSet<Widget>(); - widgets.add(widget); - Util.componentSizeUpdated(widgets); + notifyParentOfSizeChange(widget, false); } public static native int getRequiredWidth( @@ -707,62 +627,13 @@ public class Util { }-*/; /** - * Locates the child component of <literal>parent</literal> which contains - * the element <literal>element</literal>. The child component is also - * returned if "element" is part of its caption. If - * <literal>element</literal> is not part of any child component, null is - * returned. - * - * This method returns the immediate child of the parent that contains the - * element. See - * {@link #getPaintableForElement(ApplicationConnection, Container, Element)} - * for the deepest nested paintable of parent that contains the element. - * - * @param client - * A reference to ApplicationConnection - * @param parent - * The widget that contains <literal>element</literal>. - * @param element - * An element that is a sub element of the parent - * @return The VPaintableWidget which the element is a part of. Null if the - * element does not belong to a child. - */ - public static VPaintableWidget getChildPaintableForElement( - ApplicationConnection client, Container parent, Element element) { - Element rootElement = ((Widget) parent).getElement(); - while (element != null && element != rootElement) { - VPaintableWidget paintable = VPaintableMap.get(client) - .getPaintable(element); - if (paintable == null) { - String ownerPid = VCaption.getCaptionOwnerPid(element); - if (ownerPid != null) { - paintable = (VPaintableWidget) VPaintableMap.get(client) - .getPaintable(ownerPid); - } - } - - if (paintable != null - && parent.hasChildComponent(paintable - .getWidgetForPaintable())) { - return paintable; - } - - element = (Element) element.getParentElement(); - } - - return null; - } - - /** * Locates the nested child component of <literal>parent</literal> which * contains the element <literal>element</literal>. The child component is * also returned if "element" is part of its caption. If * <literal>element</literal> is not part of any child component, null is * returned. * - * This method returns the deepest nested VPaintableWidget. See - * {@link #getChildPaintableForElement(ApplicationConnection, Container, Element)} - * for the immediate child component of parent that contains the element. + * This method returns the deepest nested VPaintableWidget. * * @param client * A reference to ApplicationConnection |