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.

TestCaptionWrapper.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package com.vaadin.tests;
  2. import com.vaadin.server.ClassResource;
  3. import com.vaadin.server.ErrorMessage;
  4. import com.vaadin.server.ExternalResource;
  5. import com.vaadin.server.UserError;
  6. import com.vaadin.shared.ui.ContentMode;
  7. import com.vaadin.tests.components.TestDateField;
  8. import com.vaadin.ui.AbstractComponent;
  9. import com.vaadin.ui.AbstractDateField;
  10. import com.vaadin.ui.Button;
  11. import com.vaadin.ui.CheckBox;
  12. import com.vaadin.ui.Component.Listener;
  13. import com.vaadin.ui.CustomComponent;
  14. import com.vaadin.ui.Embedded;
  15. import com.vaadin.ui.GridLayout;
  16. import com.vaadin.ui.Label;
  17. import com.vaadin.ui.Layout;
  18. import com.vaadin.ui.Link;
  19. import com.vaadin.ui.Panel;
  20. import com.vaadin.ui.RichTextArea;
  21. import com.vaadin.ui.Slider;
  22. import com.vaadin.ui.TabSheet;
  23. import com.vaadin.ui.Upload;
  24. import com.vaadin.ui.VerticalLayout;
  25. import com.vaadin.ui.Window;
  26. import com.vaadin.v7.ui.NativeSelect;
  27. import com.vaadin.v7.ui.OptionGroup;
  28. import com.vaadin.v7.ui.ProgressIndicator;
  29. import com.vaadin.v7.ui.Select;
  30. import com.vaadin.v7.ui.Table;
  31. import com.vaadin.v7.ui.TextField;
  32. import com.vaadin.v7.ui.Tree;
  33. import com.vaadin.v7.ui.TwinColSelect;
  34. public class TestCaptionWrapper extends CustomComponent implements Listener {
  35. VerticalLayout main = new VerticalLayout();
  36. final String eventListenerString = "Component.Listener feedback: ";
  37. Label eventListenerFeedback = new Label(
  38. eventListenerString + " <no events occurred>");
  39. int count = 0;
  40. public TestCaptionWrapper() {
  41. setCompositionRoot(main);
  42. }
  43. @Override
  44. public void attach() {
  45. super.attach();
  46. createNewView();
  47. }
  48. public void createNewView() {
  49. main.removeAllComponents();
  50. main.addComponent(
  51. new Label("Each Layout and their contained components should "
  52. + "have icon, caption, description, user error defined. "
  53. + "Eeach layout should contain similar components."));
  54. main.addComponent(eventListenerFeedback);
  55. main.addComponent(new Label("OrderedLayout"));
  56. test(main);
  57. populateLayout(main);
  58. VerticalLayout panelLayout = new VerticalLayout();
  59. panelLayout.setMargin(true);
  60. final Panel panel = new Panel("Panel", panelLayout);
  61. test(panel);
  62. populateLayout(panelLayout);
  63. final TabSheet tabsheet = new TabSheet();
  64. test(tabsheet);
  65. final VerticalLayout tab1 = new VerticalLayout();
  66. tab1.addComponent(new Label("try tab2"));
  67. final VerticalLayout tab2 = new VerticalLayout();
  68. test(tab2);
  69. populateLayout(tab2);
  70. tabsheet.addTab(tab1, "TabSheet tab1", new ClassResource("m.gif"));
  71. tabsheet.addTab(tab2, "TabSheet tab2", new ClassResource("m.gif"));
  72. final VerticalLayout expandLayout = new VerticalLayout();
  73. test(expandLayout);
  74. populateLayout(expandLayout);
  75. final GridLayout gridLayout = new GridLayout();
  76. test(gridLayout);
  77. populateLayout(gridLayout);
  78. VerticalLayout layout = new VerticalLayout();
  79. layout.setMargin(true);
  80. final Window window = new Window("TEST: Window", layout);
  81. test(window);
  82. populateLayout(layout);
  83. }
  84. void populateLayout(Layout layout) {
  85. final Button button = new Button("Button " + count++);
  86. test(layout, button);
  87. button.addListener(this);
  88. final AbstractDateField<?, ?> df = new TestDateField(
  89. "DateField " + count++);
  90. test(layout, df);
  91. final CheckBox cb = new CheckBox("Checkbox " + count++);
  92. test(layout, cb);
  93. final Embedded emb = new Embedded("Embedded " + count++);
  94. test(layout, emb);
  95. VerticalLayout panelLayout = new VerticalLayout();
  96. panelLayout.setMargin(true);
  97. final Panel panel = new Panel("Panel " + count++, panelLayout);
  98. test(layout, panel);
  99. final Label label = new Label("Label " + count++);
  100. test(layout, label);
  101. final Link link = new Link("Link " + count++,
  102. new ExternalResource("www.vaadin.com"));
  103. test(layout, link);
  104. final NativeSelect nativeSelect = new NativeSelect(
  105. "NativeSelect " + count++);
  106. test(layout, nativeSelect);
  107. final OptionGroup optionGroup = new OptionGroup(
  108. "OptionGroup " + count++);
  109. test(layout, optionGroup);
  110. final ProgressIndicator pi = new ProgressIndicator();
  111. test(layout, pi);
  112. final RichTextArea rta = new RichTextArea();
  113. test(layout, rta);
  114. final Select select = new Select("Select " + count++);
  115. test(layout, select);
  116. final Slider slider = new Slider("Slider " + count++);
  117. test(layout, slider);
  118. final Table table = new Table("Table " + count++);
  119. test(layout, table);
  120. final TextField tf = new TextField("Textfield " + count++);
  121. test(layout, tf);
  122. final Tree tree = new Tree("Tree " + count++);
  123. test(layout, tree);
  124. final TwinColSelect twinColSelect = new TwinColSelect(
  125. "TwinColSelect " + count++);
  126. test(layout, twinColSelect);
  127. final Upload upload = new Upload("Upload (non-functional)", null);
  128. test(layout, upload);
  129. // Custom components
  130. layout.addComponent(new Label("<B>Below are few custom components</B>",
  131. ContentMode.HTML));
  132. final TestForUpload tfu = new TestForUpload();
  133. layout.addComponent(tfu);
  134. }
  135. /**
  136. * Stresses component by configuring it
  137. *
  138. * @param c
  139. */
  140. void test(AbstractComponent c) {
  141. final ClassResource res = new ClassResource("m.gif");
  142. final ErrorMessage errorMsg = new UserError("User error " + c);
  143. if ((c.getCaption() == null) || (c.getCaption().length() <= 0)) {
  144. c.setCaption("Caption " + c);
  145. }
  146. c.setDescription("Description " + c);
  147. c.setComponentError(errorMsg);
  148. c.setIcon(res);
  149. }
  150. /**
  151. * Stresses component by configuring it in a given layout
  152. *
  153. * @param c
  154. */
  155. void test(Layout layout, AbstractComponent c) {
  156. test(c);
  157. layout.addComponent(c);
  158. }
  159. @Override
  160. public void componentEvent(Event event) {
  161. final String feedback = eventListenerString + " source="
  162. + event.getSource() + ", toString()=" + event;
  163. System.out.println("eventListenerFeedback: " + feedback);
  164. eventListenerFeedback.setValue(feedback);
  165. }
  166. }