From: Artur Signell Date: Wed, 21 Mar 2012 13:24:23 +0000 (+0200) Subject: Code cleanup for paint/dirty state tracking changes X-Git-Tag: 7.0.0.alpha2~261 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a4798ac19e27acb4af051edfdaddafd6f704f151;p=vaadin-framework.git Code cleanup for paint/dirty state tracking changes --- diff --git a/src/com/vaadin/Application.java b/src/com/vaadin/Application.java index 4d29654fef..2cf832164b 100644 --- a/src/com/vaadin/Application.java +++ b/src/com/vaadin/Application.java @@ -2285,7 +2285,6 @@ public class Application implements Terminal.ErrorListener, Serializable { * @return A new id for the connector */ public String createConnectorId(Connector connector) { - // String connectorId = "C_" + connectorIdSequence++; String connectorId = String.valueOf(connectorIdSequence++); Connector oldReference = connectorIdToConnector.put(connectorId, connector); diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index c41c41b4c2..8ba17e1c0c 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -51,7 +51,6 @@ import com.vaadin.terminal.CombinedRequest; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Paintable; -import com.vaadin.terminal.Paintable.RepaintRequestEvent; import com.vaadin.terminal.RequestHandler; import com.vaadin.terminal.StreamVariable; import com.vaadin.terminal.StreamVariable.StreamingEndEvent; @@ -93,8 +92,7 @@ import com.vaadin.ui.Window; * TODO Document better! */ @SuppressWarnings("serial") -public abstract class AbstractCommunicationManager implements - Paintable.RepaintRequestListener, Serializable { +public abstract class AbstractCommunicationManager implements Serializable { private static final String DASHDASH = "--"; @@ -143,21 +141,6 @@ public abstract class AbstractCommunicationManager implements private static final String GET_PARAM_ANALYZE_LAYOUTS = "analyzeLayouts"; - // cannot combine with paint queue: - // this can contain dirty components from any Root - // TODO Remove, it is now in Root - // private final ArrayList dirtyPaintables = new - // ArrayList(); - - // queue used during painting to keep track of what still needs to be - // painted within the Root being painted - // private LinkedList paintQueue = new LinkedList(); - - // private final HashMap idPaintableMap = new - // HashMap(); - - private int idSequence = 0; - private final Application application; private List locales; @@ -757,13 +740,6 @@ public abstract class AbstractCommunicationManager implements return seckey; } - // for internal use by JsonPaintTarget - public void queuePaintable(Paintable paintable) { - // if (!paintQueue.contains(paintable)) { - // paintQueue.add((Connector) paintable); - // } - } - public void writeUidlResponse(boolean repaintAll, final PrintWriter outWriter, Root root, boolean analyzeLayouts) throws PaintException { @@ -774,10 +750,7 @@ public abstract class AbstractCommunicationManager implements .getDirtyConnectorTracker(); System.out.println("* Creating response to client"); if (repaintAll) { - System.out.println("Full repaint"); - getClientCache(root).clear(); - rootConnectorTracker.markAllComponentsDirty(); // Reset sent locales @@ -801,7 +774,6 @@ public abstract class AbstractCommunicationManager implements legacyPaint(paintTarget, dirtyVisibleConnectors); if (analyzeLayouts) { - // TODO Check if this works invalidComponentRelativeSizes = ComponentSizeValidator .validateComponentRelativeSizes(root.getContent(), null, null); @@ -853,7 +825,8 @@ public abstract class AbstractCommunicationManager implements outWriter.print(", "); // close states // TODO This should be optimized. The type only needs to be - // sent once for each connector id + on refresh + // sent once for each connector id + on refresh. Use the same cache as + // widget mapping JSONObject connectorTypes = new JSONObject(); for (Connector connector : dirtyVisibleConnectors) { @@ -1107,9 +1080,8 @@ public abstract class AbstractCommunicationManager implements } sortByHierarchy(paintables); for (Paintable p : paintables) { - System.out.println(" * Painting legacy Paintable " - + p.getClass().getName() + "@" - + Integer.toHexString(p.hashCode())); + logger.info("Painting legacy Paintable " + p.getClass().getName() + + "@" + Integer.toHexString(p.hashCode())); paintTarget.startTag("change"); final String pid = ((Connector) p).getConnectorId(); paintTarget.addAttribute("pid", pid); @@ -1966,27 +1938,6 @@ public abstract class AbstractCommunicationManager implements return dirtyComponents; } - /** - * @see com.vaadin.terminal.Paintable.RepaintRequestListener#repaintRequested(com.vaadin.terminal.Paintable.RepaintRequestEvent) - */ - public void repaintRequested(RepaintRequestEvent event) { - // final Paintable p = event.getPaintable(); - // if (!dirtyPaintables.contains(p)) { - // dirtyPaintables.add(p); - // } - } - - /** - * Internally mark a {@link Paintable} as painted and start collecting new - * repaint requests for it. - * - * @param paintable - */ - private void paintablePainted(Paintable paintable) { - // dirtyPaintables.remove(paintable); - // paintable.requestRepaintRequests(); - } - /** * Queues a locale to be sent to the client (browser) for date and time * entry etc. All locale specific information is derived from server-side @@ -2328,12 +2279,4 @@ public abstract class AbstractCommunicationManager implements } } - @Deprecated - public String getPaintableId(Paintable paintable) { - if (paintable instanceof Connector) { - return ((Connector) paintable).getConnectorId(); - } - throw new RuntimeException("Paintable " + paintable - + " must implement Connector"); - } } diff --git a/src/com/vaadin/terminal/gwt/server/ClientConnector.java b/src/com/vaadin/terminal/gwt/server/ClientConnector.java index e2943b499f..1026c3598b 100644 --- a/src/com/vaadin/terminal/gwt/server/ClientConnector.java +++ b/src/com/vaadin/terminal/gwt/server/ClientConnector.java @@ -4,12 +4,21 @@ import java.util.List; import com.vaadin.terminal.gwt.client.Connector; +/** + * Interface implemented by all connectors that are capable of communicating + * with the client side + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + * + */ public interface ClientConnector extends Connector { /** * Returns the list of pending server to client RPC calls and clears the * list. * - * @return unmodifiable ordered list of pending server to client method + * @return an unmodifiable ordered list of pending server to client method * calls (not null) * * @since 7.0 diff --git a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java index aaca43e6e9..2807cde33d 100644 --- a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java +++ b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java @@ -11,7 +11,6 @@ import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.Serializable; import java.io.StringWriter; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -89,10 +88,6 @@ public class JsonPaintTarget implements PaintTarget { private final Collection paintedComponents = new HashSet(); - // private Collection identifiersCreatedDueRefPaint; - - private Collection deferredPaintables; - private final Collection> usedPaintableTypes = new LinkedList>(); /** @@ -123,8 +118,6 @@ public class JsonPaintTarget implements PaintTarget { openPaintables = new Stack(); openPaintableTags = new Stack(); - deferredPaintables = new ArrayList(); - cacheEnabled = cachingRequired; } @@ -689,31 +682,23 @@ public class JsonPaintTarget implements PaintTarget { throws PaintException { boolean topLevelPaintable = openPaintables.isEmpty(); - System.out.println("startPaintable for " - + paintable.getClass().getName() + "@" - + Integer.toHexString(paintable.hashCode())); + logger.fine("startPaintable for " + paintable.getClass().getName() + + "@" + Integer.toHexString(paintable.hashCode())); startTag(tagName, true); openPaintables.push(paintable); openPaintableTags.push(tagName); - final String id = manager.getPaintableId(paintable); - paintable.addListener(manager); + final String id = getPaintIdentifier(paintable); addAttribute("id", id); // queue for painting later if already painting a paintable if (!topLevelPaintable) { - // if (!deferredPaintables.contains(paintable)) { - // notify manager: add to paint queue instead of painting now - // manager.queuePaintable(paintable); - // deferredPaintables.add(paintable); - // } return PaintStatus.DEFER; } // not a nested paintable, paint the it now paintedComponents.add(paintable); - // deferredPaintables.remove(paintable); if (paintable instanceof CustomLayout) { customLayoutArgumentsOpen = true; @@ -722,14 +707,14 @@ public class JsonPaintTarget implements PaintTarget { } public void endPaintable(Paintable paintable) throws PaintException { - System.out.println("endPaintable for " + paintable.getClass().getName() - + "@" + Integer.toHexString(paintable.hashCode())); + logger.fine("endPaintable for " + paintable.getClass().getName() + "@" + + Integer.toHexString(paintable.hashCode())); Paintable openPaintable = openPaintables.peek(); if (paintable != openPaintable) { throw new PaintException("Invalid UIDL: closing wrong paintable: '" - + manager.getPaintableId(paintable) + "' expected: '" - + manager.getPaintableId(openPaintable) + "'."); + + getPaintIdentifier(paintable) + "' expected: '" + + getPaintIdentifier(openPaintable) + "'."); } // remove paintable from the stack openPaintables.pop(); @@ -738,13 +723,12 @@ public class JsonPaintTarget implements PaintTarget { } public String getPaintIdentifier(Paintable paintable) throws PaintException { - // if (!manager.hasPaintableId(paintable)) { - // if (identifiersCreatedDueRefPaint == null) { - // identifiersCreatedDueRefPaint = new HashSet(); - // } - // identifiersCreatedDueRefPaint.add(paintable); - // } - return manager.getPaintableId(paintable); + // TODO This should be unnecessary as Paintable must be a Connector + if (paintable instanceof Connector) { + return ((Connector) paintable).getConnectorId(); + } + throw new RuntimeException("Paintable " + paintable + + " must implement Connector"); } /* @@ -1021,23 +1005,6 @@ public class JsonPaintTarget implements PaintTarget { return usedResources; } - // /** - // * Method to check if paintable is already painted into this target. - // * - // * @param p - // * @return true if is not yet painted into this target and is connected to - // * app - // */ - // public boolean needsToBePainted(Paintable p) { - // if (paintedComponents.contains(p)) { - // return false; - // } else if (((Component) p).getApplication() == null) { - // return false; - // } else { - // return true; - // } - // } - private static final Map, Class> widgetMappingCache = new HashMap, Class>(); @SuppressWarnings("unchecked") diff --git a/src/com/vaadin/ui/DirtyConnectorTracker.java b/src/com/vaadin/ui/DirtyConnectorTracker.java index a3bdd8a3a9..9253634696 100644 --- a/src/com/vaadin/ui/DirtyConnectorTracker.java +++ b/src/com/vaadin/ui/DirtyConnectorTracker.java @@ -3,6 +3,7 @@ package com.vaadin.ui; import java.util.Collection; import java.util.HashSet; import java.util.Set; +import java.util.logging.Level; import java.util.logging.Logger; import com.vaadin.terminal.Paintable.RepaintRequestEvent; @@ -49,25 +50,25 @@ public class DirtyConnectorTracker implements RepaintRequestListener { } private void markDirty(Component component) { - // TODO Remove debug info - if (!dirtyComponents.contains(component)) { - debug(component, "is now dirty"); - + if (getLogger().isLoggable(Level.FINE)) { + if (!dirtyComponents.contains(component)) { + getLogger() + .fine(getDebugInfo(component) + " " + "is now dirty"); + } } - dirtyComponents.add(component); - } - private void debug(Component component, String string) { - getLogger().info(getDebugInfo(component) + " " + string); + dirtyComponents.add(component); } private void markClean(Component component) { - // TODO Remove debug info - if (dirtyComponents.contains(component)) { - debug(component, "is no longer dirty"); + if (getLogger().isLoggable(Level.FINE)) { + if (dirtyComponents.contains(component)) { + getLogger().fine( + getDebugInfo(component) + " " + "is no longer dirty"); + } } - dirtyComponents.remove(component); + dirtyComponents.remove(component); } private String getDebugInfo(Component component) { @@ -91,13 +92,12 @@ public class DirtyConnectorTracker implements RepaintRequestListener { public void markAllComponentsDirty() { markComponentsDirtyRecursively(root); - System.out.println("All components are now dirty"); - + getLogger().fine("All components are now dirty"); } public void markAllComponentsClean() { dirtyComponents.clear(); - System.out.println("All components are now clean"); + getLogger().fine("All components are now clean"); } /**