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.9KB

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