You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CachingDemo.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.demo;
  5. import com.itmill.toolkit.terminal.PaintException;
  6. import com.itmill.toolkit.terminal.PaintTarget;
  7. import com.itmill.toolkit.ui.Label;
  8. import com.itmill.toolkit.ui.Layout;
  9. import com.itmill.toolkit.ui.OrderedLayout;
  10. import com.itmill.toolkit.ui.TabSheet;
  11. import com.itmill.toolkit.ui.Window;
  12. /**
  13. * This example is a (simple) demonstration of client-side caching. The content
  14. * in one tab is intentionally made very slow to produce server-side. When the
  15. * user changes to this tab for the first time, there will be a 3 second wait
  16. * before the content shows up, but the second time it shows up immediately
  17. * since the content has not changed and is cached client-side.
  18. *
  19. * @author IT Mill Ltd.
  20. */
  21. public class CachingDemo extends com.itmill.toolkit.Application {
  22. public void init() {
  23. final Window main = new Window("Client-side caching example");
  24. setMainWindow(main);
  25. setTheme("example");
  26. final TabSheet ts = new TabSheet();
  27. main.addComponent(ts);
  28. Layout layout = new OrderedLayout();
  29. layout.setMargin(true);
  30. Label l = new Label(
  31. "This is a normal label, quick to render.<br/>The second tab will be slow to render the first time, after that it will be as quick as this one.");
  32. l.setCaption("A normal label");
  33. l.setContentMode(Label.CONTENT_XHTML);
  34. layout.addComponent(l);
  35. ts.addTab(layout, "Normal", null);
  36. layout = new OrderedLayout();
  37. layout.setMargin(true);
  38. l = new Label(
  39. "The first time you change to this tab, this label is very slow to produce (server-side).<br/> However, it will seem fast the second time you change to this tab, because it has not changed and is cached client-side.") {
  40. public void paintContent(PaintTarget target) throws PaintException {
  41. try {
  42. Thread.sleep(3000);
  43. } catch (final Exception e) {
  44. // IGNORED
  45. }
  46. super.paintContent(target);
  47. }
  48. };
  49. l.setCaption("A slow label");
  50. l.setContentMode(Label.CONTENT_XHTML);
  51. layout.addComponent(l);
  52. ts.addTab(layout, "Slow", null);
  53. }
  54. }