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

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