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 7.0KB

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