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.

GAESyncTest.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package com.vaadin.tests.appengine;
  2. import com.google.apphosting.api.DeadlineExceededException;
  3. import com.vaadin.data.Property;
  4. import com.vaadin.data.Property.ValueChangeEvent;
  5. import com.vaadin.server.ClassResource;
  6. import com.vaadin.server.DownloadStream;
  7. import com.vaadin.server.LegacyApplication;
  8. import com.vaadin.ui.Button;
  9. import com.vaadin.ui.Button.ClickEvent;
  10. import com.vaadin.ui.Embedded;
  11. import com.vaadin.ui.GridLayout;
  12. import com.vaadin.ui.Label;
  13. import com.vaadin.ui.LegacyWindow;
  14. import com.vaadin.ui.Notification;
  15. import com.vaadin.v7.ui.LegacyTextField;
  16. public class GAESyncTest extends LegacyApplication {
  17. /**
  18. *
  19. */
  20. private static final long serialVersionUID = -3724319151122707926l;
  21. @Override
  22. public void init() {
  23. setMainWindow(new IntrWindow(this));
  24. }
  25. @Override
  26. public void error(com.vaadin.server.ErrorEvent event) {
  27. Throwable t = event.getThrowable();
  28. // Was this caused by a GAE timeout?
  29. while (t != null) {
  30. if (t instanceof DeadlineExceededException) {
  31. getMainWindow().showNotification("Bugger!", "Deadline Exceeded",
  32. Notification.TYPE_ERROR_MESSAGE);
  33. return;
  34. }
  35. t = t.getCause();
  36. }
  37. super.error(event);
  38. }
  39. private class IntrWindow extends LegacyWindow {
  40. private int n = 0;
  41. private static final long serialVersionUID = -6521351715072191625l;
  42. LegacyTextField tf;
  43. Label l;
  44. LegacyApplication app;
  45. GridLayout gl;
  46. private IntrWindow(LegacyApplication app) {
  47. this.app = app;
  48. tf = new LegacyTextField("Echo thingie");
  49. tf.setImmediate(true);
  50. tf.addListener(new Property.ValueChangeListener() {
  51. @Override
  52. public void valueChange(ValueChangeEvent event) {
  53. IntrWindow.this.showNotification(
  54. (String) event.getProperty().getValue());
  55. }
  56. });
  57. addComponent(tf);
  58. l = new Label("" + n);
  59. addComponent(l);
  60. {
  61. Button b = new Button("Slow", new Button.ClickListener() {
  62. @Override
  63. public void buttonClick(ClickEvent event) {
  64. try {
  65. Thread.sleep(15000);
  66. } catch (InterruptedException e) {
  67. // TODO Auto-generated catch block
  68. e.printStackTrace();
  69. }
  70. }
  71. });
  72. addComponent(b);
  73. }
  74. {
  75. Button b = new Button("Add", new Button.ClickListener() {
  76. @Override
  77. public void buttonClick(ClickEvent event) {
  78. if (getUI() == getMainWindow()) {
  79. getUI().getPage()
  80. .showNotification(new Notification("main"));
  81. try {
  82. Thread.sleep((5000));
  83. } catch (InterruptedException e) {
  84. // TODO Auto-generated catch block
  85. e.printStackTrace();
  86. }
  87. }
  88. addImage();
  89. }
  90. });
  91. addComponent(b);
  92. }
  93. gl = new GridLayout(30, 50);
  94. addComponent(gl);
  95. }
  96. private void addImage() {
  97. ClassResource res = new ClassResource("img1.png") {
  98. private static final long serialVersionUID = 1L;
  99. @Override
  100. public DownloadStream getStream() {
  101. try {
  102. Thread.sleep((long) (Math.random() * 5000));
  103. } catch (InterruptedException e) {
  104. // TODO Auto-generated catch block
  105. e.printStackTrace();
  106. }
  107. return super.getStream();
  108. }
  109. };
  110. res.setCacheTime(0);
  111. Embedded emb = new Embedded("" + n, res);
  112. emb.setWidth("30px");
  113. emb.setHeight("5px");
  114. gl.addComponent(emb);
  115. l.setValue("" + n++);
  116. }
  117. }
  118. @Override
  119. public LegacyWindow getWindow(String name) {
  120. LegacyWindow w = super.getWindow(name);
  121. if (w == null) {
  122. w = new IntrWindow(this);
  123. addWindow(w);
  124. }
  125. return w;
  126. }
  127. }