]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added CachingDemo; a small client-side caching demo.
authorMarc Englund <marc.englund@itmill.com>
Thu, 1 Nov 2007 16:27:41 +0000 (16:27 +0000)
committerMarc Englund <marc.englund@itmill.com>
Thu, 1 Nov 2007 16:27:41 +0000 (16:27 +0000)
svn changeset:2662/svn branch:trunk

src/com/itmill/toolkit/demo/CachingDemo.java [new file with mode: 0644]

diff --git a/src/com/itmill/toolkit/demo/CachingDemo.java b/src/com/itmill/toolkit/demo/CachingDemo.java
new file mode 100644 (file)
index 0000000..afec854
--- /dev/null
@@ -0,0 +1,50 @@
+package com.itmill.toolkit.demo;\r
+\r
+import com.itmill.toolkit.terminal.PaintException;\r
+import com.itmill.toolkit.terminal.PaintTarget;\r
+import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.TabSheet;\r
+import com.itmill.toolkit.ui.Window;\r
+\r
+/**\r
+ * This example is a (simple) demonstration of client-side caching. The content\r
+ * in one tab is intentionally made very slow to produce server-side. When the\r
+ * user changes to this tab for the first time, there will be a 3 second wait\r
+ * before the content shows up, but the second time it shows up immediately\r
+ * since the content has not changed and is cached client-side.\r
+ * \r
+ * @author IT Mill Ltd.\r
+ */\r
+public class CachingDemo extends com.itmill.toolkit.Application {\r
+\r
+       public void init() {\r
+\r
+               Window main = new Window("Client-side caching example");\r
+               setMainWindow(main);\r
+\r
+               setTheme("example");\r
+\r
+               TabSheet ts = new TabSheet();\r
+               ts.setCaption("setHeigth(300)");\r
+               main.addComponent(ts);\r
+               ts.setHeight(300);\r
+               Label l = new Label(\r
+                               "A normal label, quick to render. The second tab will be slow to render the first time, after that it will be as quick as this one.");\r
+               ts.addTab(l, "Normal", null);\r
+               l = new Label(\r
+                               "The first time you change to this tab, this label is very slow to produce (server-side). However, it will seem fast the second time you change to this tab, because it has not changed and is cached client-side.") {\r
+                       public void paintContent(PaintTarget target) throws PaintException {\r
+                               try {\r
+                                       Thread.sleep(3000);\r
+                               } catch (Exception e) {\r
+                                       // IGNORED\r
+                               }\r
+                               super.paintContent(target);\r
+                       }\r
+\r
+               };\r
+               ts.addTab(l, "Slow", null);\r
+\r
+       }\r
+\r
+}\r