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.

TestForTablesInitialColumnWidthLogicRendering.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 java.util.Iterator;
  18. import java.util.Vector;
  19. import com.vaadin.server.UserError;
  20. import com.vaadin.ui.Button;
  21. import com.vaadin.ui.Button.ClickEvent;
  22. import com.vaadin.ui.CustomComponent;
  23. import com.vaadin.ui.Label;
  24. import com.vaadin.ui.Layout;
  25. import com.vaadin.ui.VerticalLayout;
  26. import com.vaadin.v7.ui.Table;
  27. /**
  28. *
  29. * This Component contains some simple test to see that component updates its
  30. * contents propertly.
  31. *
  32. * @author Vaadin Ltd.
  33. */
  34. public class TestForTablesInitialColumnWidthLogicRendering
  35. extends CustomComponent {
  36. private final VerticalLayout main = new VerticalLayout();
  37. public TestForTablesInitialColumnWidthLogicRendering() {
  38. setCompositionRoot(main);
  39. createNewView();
  40. }
  41. public void createNewView() {
  42. main.removeAllComponents();
  43. main.addComponent(new Label(
  44. "Below are same tables that all should render somewhat nice. Also when testing, you might want to try resizing window."));
  45. Table t;
  46. Layout lo = new VerticalLayout();
  47. lo.setWidth("600px");
  48. lo.setHeight("250px");
  49. t = getTestTable(4, 50);
  50. t.setSizeFull();
  51. lo.setCaption("Fullsize table insize 400x250px layout");
  52. lo.addComponent(t);
  53. main.addComponent(lo);
  54. // t = new Table("Empty table");
  55. // main.addComponent(t);
  56. t = getTestTable(5, 0);
  57. t.setCaption("Table with only headers");
  58. // main.addComponent(t);
  59. t = getTestTable(5, 200);
  60. t.setCaption("Table with some cols and lot of rows");
  61. main.addComponent(t);
  62. t = getTestTable(5, 5);
  63. t.setCaption(
  64. "Table with some cols and rows rows, some col widths fixed");
  65. Iterator<?> it = t.getContainerPropertyIds().iterator();
  66. it.next();
  67. it.next();
  68. t.setColumnWidth(it.next(), 30);
  69. t.setColumnWidth(it.next(), 30);
  70. t.setWidth("700px");
  71. main.addComponent(t);
  72. t = getTestTable(12, 4);
  73. t.setCaption("Table with some rows and lot of columns");
  74. main.addComponent(t);
  75. t = getTestTable(3, 40);
  76. t.setCaption(
  77. "Table with some columns and wide explicit width. (Ought to widen columns to use all space)");
  78. t.setWidth("1000px");
  79. main.addComponent(t);
  80. t = getTestTable(12, 4);
  81. t.setCaption("Table with some rows and lot of columns, width == 100%");
  82. t.setWidth(100, Table.UNITS_PERCENTAGE);
  83. main.addComponent(t);
  84. t = getTestTable(12, 100);
  85. t.setCaption(
  86. "Table with lot of rows and lot of columns, width == 50%");
  87. t.setWidth(50, Table.UNITS_PERCENTAGE);
  88. main.addComponent(t);
  89. t = getTestTable(5, 100);
  90. t.setCaption("Table with 40 rows");
  91. // main.addComponent(t);
  92. t = getTestTable(4, 4);
  93. t.setCaption("Table with some rows and width = 200px");
  94. t.setWidth("200px");
  95. main.addComponent(t);
  96. final Button b = new Button("refresh view", new Button.ClickListener() {
  97. @Override
  98. public void buttonClick(ClickEvent event) {
  99. createNewView();
  100. }
  101. });
  102. main.addComponent(b);
  103. }
  104. public static Table getTestTable(int cols, int rows) {
  105. final Table t = new Table();
  106. t.setColumnCollapsingAllowed(true);
  107. for (int i = 0; i < cols; i++) {
  108. t.addContainerProperty(testString[i], String.class, "");
  109. }
  110. t.addContainerProperty("button", Button.class, null);
  111. for (int i = 0; i < rows; i++) {
  112. final Vector<Object> content = new Vector<>();
  113. for (int j = 0; j < cols; j++) {
  114. content.add(rndString());
  115. }
  116. Button button = new Button("b", new Button.ClickListener() {
  117. @Override
  118. public void buttonClick(ClickEvent event) {
  119. System.out.println("b click");
  120. }
  121. });
  122. button.setDescription("Yep yep");
  123. button.setComponentError(new UserError("Error"));
  124. content.add(button);
  125. t.addItem(content.toArray(), "" + i);
  126. }
  127. return t;
  128. }
  129. static String[] testString = new String[] { "Jacob", "Michael", "Joshua",
  130. "Matthew", "Ethan", "Andrew", "Daniel", "Anthony", "Christopher",
  131. "Joseph", "William", "Alexander", "Ryan", "David", "Nicholas",
  132. "Tyler", "James", "John", "Jonathan", "Nathan", "Samuel",
  133. "Christian", "Noah", "Dylan", "Benjamin", "Logan", "Brandon",
  134. "Gabriel", "Zachary", "Jose", "Elijah", "Angel", "Kevin", "Jack",
  135. "Caleb", "Justin", "Austin", "Evan", "Robert", "Thomas", "Luke",
  136. "Mason", "Aidan", "Jackson", "Isaiah", "Jordan", "Gavin", "Connor",
  137. "Aiden", "Isaac", "Jason", "Cameron", "Hunter", "Jayden", "Juan",
  138. "Charles", "Aaron", "Lucas", "Luis", "Owen", "Landon", "Diego",
  139. "Brian", "Adam", "Adrian", "Kyle", "Eric", "Ian", "Nathaniel",
  140. "Carlos", "Alex", "Bryan", "Jesus", "Julian", "Sean", "Carter",
  141. "Hayden", "Jeremiah", "Cole", "Brayden", "Wyatt", "Chase", "Steven",
  142. "Timothy", "Dominic", "Sebastian", "Xavier", "Jaden", "Jesse",
  143. "Devin", "Seth", "Antonio", "Richard", "Miguel", "Colin", "Cody",
  144. "Alejandro", "Caden", "Blake", "Carson" };
  145. public static String rndString() {
  146. return testString[(int) (Math.random() * testString.length)];
  147. }
  148. }