diff options
author | Leif Åstrand <leif@vaadin.com> | 2011-09-07 13:41:53 +0000 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2011-09-07 13:41:53 +0000 |
commit | 96c7bb0066094c20cacf53c58fbe30d4c42c017b (patch) | |
tree | 0337208dbf563f12136eaff69b0df4430027f80b /src | |
parent | 1300d93c35dc4e9eb20fe589cdddc3a4c0b9c735 (diff) | |
download | vaadin-framework-96c7bb0066094c20cacf53c58fbe30d4c42c017b.tar.gz vaadin-framework-96c7bb0066094c20cacf53c58fbe30d4c42c017b.zip |
Don't remove and re-add children for every update to avoid changing scrolling in parent container (#7462)
svn changeset:20905/svn branch:6.7
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java index 213651ab89..5eae0ed3d2 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java @@ -4,8 +4,9 @@ package com.vaadin.terminal.gwt.client.ui; -import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -133,6 +134,7 @@ public class VCssLayout extends SimplePanel implements Paintable, Container { private final HashMap<Widget, VCaption> widgetToCaption = new HashMap<Widget, VCaption>(); private ApplicationConnection client; + private int lastIndex; public FlowPane() { super(); @@ -152,36 +154,37 @@ public class VCssLayout extends SimplePanel implements Paintable, Container { // for later requests this.client = client; - final ArrayList<Widget> oldWidgets = new ArrayList<Widget>(); + final Collection<Widget> oldWidgets = new HashSet<Widget>(); for (final Iterator<Widget> iterator = iterator(); iterator .hasNext();) { oldWidgets.add(iterator.next()); } - clear(); ValueMap mapAttribute = null; if (uidl.hasAttribute("css")) { mapAttribute = uidl.getMapAttribute("css"); } + lastIndex = 0; for (final Iterator<Object> i = uidl.getChildIterator(); i .hasNext();) { final UIDL r = (UIDL) i.next(); final Paintable child = client.getPaintable(r); - if (oldWidgets.contains(child)) { + final Widget widget = (Widget) child; + if (widget.getParent() == this) { oldWidgets.remove(child); VCaption vCaption = widgetToCaption.get(child); if (vCaption != null) { - add(vCaption); + addOrMove(vCaption, lastIndex++); oldWidgets.remove(vCaption); } } - add((Widget) child); + addOrMove(widget, lastIndex++); if (mapAttribute != null && mapAttribute.containsKey(r.getId())) { String css = null; try { - Style style = ((Widget) child).getElement().getStyle(); + Style style = widget.getElement().getStyle(); css = mapAttribute.getString(r.getId()); String[] cssRules = css.split(";"); for (int j = 0; j < cssRules.length; j++) { @@ -208,12 +211,26 @@ public class VCssLayout extends SimplePanel implements Paintable, Container { // loop oldWidgetWrappers that where not re-attached and unregister // them for (Widget w : oldWidgets) { + remove(w); if (w instanceof Paintable) { final Paintable p = (Paintable) w; client.unregisterPaintable(p); } - widgetToCaption.remove(w); + VCaption vCaption = widgetToCaption.remove(w); + if (vCaption != null) { + remove(vCaption); + } + } + } + + private void addOrMove(Widget child, int index) { + if (child.getParent() == this) { + int currentIndex = getWidgetIndex(child); + if (index == currentIndex) { + return; + } } + insert(child, index); } public boolean hasChildComponent(Widget component) { @@ -242,8 +259,10 @@ public class VCssLayout extends SimplePanel implements Paintable, Container { caption = new VCaption(component, client); widgetToCaption.put(widget, caption); insert(caption, getWidgetIndex(widget)); + lastIndex++; } else if (!caption.isAttached()) { insert(caption, getWidgetIndex(widget)); + lastIndex++; } caption.updateCaption(uidl); } else if (caption != null) { |