From: Artur Signell Date: Mon, 19 Mar 2012 09:42:14 +0000 (+0200) Subject: Paint Vaadin 6 changes in hierarchy order to retain backwards X-Git-Tag: 7.0.0.alpha2~282 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d5439499d5628fac0d096a5d44ac20f213b53253;p=vaadin-framework.git Paint Vaadin 6 changes in hierarchy order to retain backwards compatibility, especially for component containers --- diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index a3980d4c2a..13bce26c12 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.HashSet; @@ -802,20 +803,7 @@ public abstract class AbstractCommunicationManager implements JsonPaintTarget paintTarget = new JsonPaintTarget(this, outWriter, !repaintAll); - - for (Connector connector : dirtyVisibleConnectors) { - if (connector instanceof Paintable) { - System.out.println(" * Painting legacy Paintable " - + connector.getClass().getName() + "@" - + Integer.toHexString(connector.hashCode())); - Paintable p = (Paintable) connector; - paintTarget.startTag("change"); - final String pid = connector.getConnectorId(); - paintTarget.addAttribute("pid", pid); - p.paint(paintTarget); - paintTarget.endTag("change"); - } - } + legacyPaint(paintTarget, dirtyVisibleConnectors); if (analyzeLayouts) { // TODO Check if this works @@ -1113,6 +1101,59 @@ public abstract class AbstractCommunicationManager implements } } + private void legacyPaint(PaintTarget paintTarget, + ArrayList dirtyVisibleConnectors) + throws PaintException { + List paintables = new ArrayList(); + for (Connector connector : dirtyVisibleConnectors) { + if (connector instanceof Paintable) { + paintables.add((Paintable) connector); + } + } + sortByHierarchy(paintables); + for (Paintable p : paintables) { + System.out.println(" * Painting legacy Paintable " + + p.getClass().getName() + "@" + + Integer.toHexString(p.hashCode())); + paintTarget.startTag("change"); + final String pid = ((Connector) p).getConnectorId(); + paintTarget.addAttribute("pid", pid); + p.paint(paintTarget); + paintTarget.endTag("change"); + } + + } + + private void sortByHierarchy(List paintables) { + // Vaadin 6 requires parents to be painted before children as component + // containers rely on that their updateFromUIDL method has been called + // before children start calling e.g. updateCaption + Collections.sort(paintables, new Comparator() { + public int compare(Paintable o1, Paintable o2) { + Component c1 = (Component) o1; + Component c2 = (Component) o2; + int depth1 = 0; + while (c1.getParent() != null) { + depth1++; + c1 = c1.getParent(); + } + int depth2 = 0; + while (c2.getParent() != null) { + depth2++; + c2 = c2.getParent(); + } + if (depth1 < depth2) { + return -1; + } + if (depth1 > depth2) { + return 1; + } + return 0; + } + }); + + } + private ClientCache getClientCache(Root root) { Integer rootId = Integer.valueOf(root.getRootId()); ClientCache cache = rootToClientCache.get(rootId);