]> source.dussan.org Git - vaadin-framework.git/commitdiff
UIDL Caching system implemenatation. Closes #855
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Sun, 30 Sep 2007 13:56:37 +0000 (13:56 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Sun, 30 Sep 2007 13:56:37 +0000 (13:56 +0000)
svn changeset:2396/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java
src/com/itmill/toolkit/terminal/gwt/server/JsonPaintTarget.java
src/com/itmill/toolkit/ui/AbstractComponent.java

index 8a5d55bfe124de46c4fd8811837551f186116612..9ad29152e1ac11a82e3b142384d72318544aeb94 100755 (executable)
@@ -368,6 +368,10 @@ public class ApplicationConnection implements FocusListener {
        public boolean updateComponent(Widget component, UIDL uidl,
                        boolean manageCaption) {
 
+               // If the server request that a cached instance should be used, do nothing
+               if (uidl.getBooleanAttribute("cached"))
+                       return true;
+               
                // Switch to correct implementation if needed
                if (!widgetSet.isCorrectImplementation(component, uidl)) {
                        Container parent = getParentLayout(component);
index c9531bcf55d706b03b69a47dc66308893a99dd3e..d039fb44e84cfd37416e2b5fe14f08554778de78 100644 (file)
@@ -293,7 +293,7 @@ public class CommunicationManager implements Paintable.RepaintRequestListener,
 
                                        outWriter.print("\"changes\":[");
 
-                                       paintTarget = new JsonPaintTarget(this, outWriter);
+                                       paintTarget = new JsonPaintTarget(this, outWriter, !repaintAll);
 
                                        // Paints components
                                        Set paintables;
@@ -901,6 +901,11 @@ public class CommunicationManager implements Paintable.RepaintRequestListener,
                return id;
        }
 
+       public synchronized boolean hasPaintableId(Paintable paintable) {
+
+               return paintableIdMap.containsKey(paintable);
+       }
+       
        /**
         * 
         * @return
index 7102adde6c617ede35c34abcb570b858f25cd94b..1fa7b6d82ee64cf115c39fe3c5f69ce87743b96d 100644 (file)
@@ -88,6 +88,8 @@ public class JsonPaintTarget implements PaintTarget {
        private JsonTag tag;
 
        private int errorsOpen;
+       
+       private boolean cacheEnabled = false;
 
        /**
         * Creates a new XMLPrintWriter, without automatic line flushing.
@@ -100,7 +102,7 @@ public class JsonPaintTarget implements PaintTarget {
         *             if the paint operation failed.
         */
        public JsonPaintTarget(
-                       CommunicationManager manager, PrintWriter outWriter)
+                       CommunicationManager manager, PrintWriter outWriter, boolean cachingRequired)
                        throws PaintException {
 
                this.manager = manager;
@@ -116,6 +118,8 @@ public class JsonPaintTarget implements PaintTarget {
                // Adds document declaration
 
                // Adds UIDL start tag and its attributes
+               
+               this.cacheEnabled = cachingRequired;
        }
 
        public void startTag(String tagName) throws PaintException {
@@ -774,10 +778,11 @@ public class JsonPaintTarget implements PaintTarget {
        public boolean startTag(Paintable paintable, String tagName)
                        throws PaintException {
                startTag(tagName, true);
+               boolean isPreviouslyPainted = manager.hasPaintableId(paintable);
                String id = manager.getPaintableId(paintable);
                paintable.addListener(manager);
                addAttribute("id", id);
-               return false;
+               return cacheEnabled && isPreviouslyPainted;
        }
 
        /**
@@ -1086,8 +1091,6 @@ public class JsonPaintTarget implements PaintTarget {
        }
 
        public void setPreCachedResources(Set preCachedResources) {
-               // TODO Auto-generated method stub
-
+               throw new UnsupportedOperationException();
        }
-
 }
index 9befb25f1c0841bb071a762f065ca0cec77abaaa..18ce5b59a5711ead51ee37150e2b61f83eacce44 100644 (file)
@@ -518,6 +518,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
         * interface.
         */
        public void attach() {
+               requestRepaint();
        }
 
        /*
@@ -551,7 +552,10 @@ public abstract class AbstractComponent implements Component, MethodEventSource
         */
        public final void paint(PaintTarget target) throws PaintException {
 
-               if (!target.startTag(this, this.getTag())) {
+               if (!target.startTag(this, this.getTag()) || repaintRequestListenersNotified) {
+                       
+                       // Paint the contents of the component
+                       
                        if (styles != null && styles.size() > 0)
                                target.addAttribute("style", getStyle());
                        if (isReadOnly())
@@ -580,6 +584,10 @@ public abstract class AbstractComponent implements Component, MethodEventSource
                                if (error != null)
                                        error.paint(target);
                        }
+               } else {
+                       
+                       // Contents have not changed, only cached presentation can be used
+                       target.addAttribute("cached", true);
                }
                target.endTag(this.getTag());