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 | |
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
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java | 35 | ||||
-rw-r--r-- | tests/src/com/vaadin/tests/components/panel/PanelShouldNotScroll.html | 46 |
2 files changed, 73 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) { diff --git a/tests/src/com/vaadin/tests/components/panel/PanelShouldNotScroll.html b/tests/src/com/vaadin/tests/components/panel/PanelShouldNotScroll.html new file mode 100644 index 0000000000..8b03ca330f --- /dev/null +++ b/tests/src/com/vaadin/tests/components/panel/PanelShouldNotScroll.html @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="" /> +<title>CssLayoutRemoveComponent</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">CssLayoutRemoveComponent</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.components.panel.PanelShouldNotScroll?restartApplication</td> + <td></td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentspanelPanelShouldNotScroll::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VPanel[0]/VCssLayout[0]/VCssLayout$FlowPane[0]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>scroll</td> + <td>vaadin=runcomvaadintestscomponentspanelPanelShouldNotScroll::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VPanel[0]/domChild[1]</td> + <td>443</td> +</tr> +<tr> + <td>pause</td> + <td>300</td> + <td></td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentspanelPanelShouldNotScroll::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VPanel[0]/VCssLayout[0]/VCssLayout$FlowPane[0]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td></td> +</tr> +</tbody></table> +</body> +</html> |