]> source.dussan.org Git - vaadin-framework.git/commitdiff
Code cleanup for paint/dirty state tracking changes
authorArtur Signell <artur@vaadin.com>
Wed, 21 Mar 2012 13:24:23 +0000 (15:24 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 21 Mar 2012 13:28:21 +0000 (15:28 +0200)
src/com/vaadin/Application.java
src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
src/com/vaadin/terminal/gwt/server/ClientConnector.java
src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java
src/com/vaadin/ui/DirtyConnectorTracker.java

index 4d29654fef831594661d2c3eab6ba3283e6a4703..2cf832164bdb2d5442fd8bcfd657828bbee4a6f9 100644 (file)
@@ -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);
index c41c41b4c2d45b915263451c1752cc8d853d0709..8ba17e1c0c0cab8395469b3377f60ee22ec29d20 100644 (file)
@@ -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<Paintable> dirtyPaintables = new
-    // ArrayList<Paintable>();
-
-    // queue used during painting to keep track of what still needs to be
-    // painted within the Root being painted
-    // private LinkedList<Connector> paintQueue = new LinkedList<Connector>();
-
-    // private final HashMap<String, Paintable> idPaintableMap = new
-    // HashMap<String, Paintable>();
-
-    private int idSequence = 0;
-
     private final Application application;
 
     private List<String> 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");
-    }
 }
index e2943b499f2a3557bd55dcea3b4acfa75c24936d..1026c3598bfa95861987b28dea8ff7b09f4d10d4 100644 (file)
@@ -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
index aaca43e6e98c5e346c9ccd4d129ee46a060962ae..2807cde33db9315438ab7bb83fc8c8025539c090 100644 (file)
@@ -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<Paintable> paintedComponents = new HashSet<Paintable>();
 
-    // private Collection<Paintable> identifiersCreatedDueRefPaint;
-
-    private Collection<Paintable> deferredPaintables;
-
     private final Collection<Class<? extends Paintable>> usedPaintableTypes = new LinkedList<Class<? extends Paintable>>();
 
     /**
@@ -123,8 +118,6 @@ public class JsonPaintTarget implements PaintTarget {
         openPaintables = new Stack<Paintable>();
         openPaintableTags = new Stack<String>();
 
-        deferredPaintables = new ArrayList<Paintable>();
-
         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<Paintable>();
-        // }
-        // 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<? extends Paintable>, Class<? extends Paintable>> widgetMappingCache = new HashMap<Class<? extends Paintable>, Class<? extends Paintable>>();
 
     @SuppressWarnings("unchecked")
index a3bdd8a3a90a3eb8593ece49a102c669876a0249..9253634696d30b8d114924d07736303a44d4b293 100644 (file)
@@ -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");
     }
 
     /**