選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

TestForTablesInitialColumnWidthLogicRendering.java 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 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.Table;
  26. import com.vaadin.ui.VerticalLayout;
  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 extends
  35. 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("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("Table with some columns and wide explicit width. (Ought to widen columns to use all space)");
  76. t.setWidth("1000px");
  77. main.addComponent(t);
  78. t = getTestTable(12, 4);
  79. t.setCaption("Table with some rows and lot of columns, width == 100%");
  80. t.setWidth(100, Table.UNITS_PERCENTAGE);
  81. main.addComponent(t);
  82. t = getTestTable(12, 100);
  83. t.setCaption("Table with lot of rows and lot of columns, width == 50%");
  84. t.setWidth(50, Table.UNITS_PERCENTAGE);
  85. main.addComponent(t);
  86. t = getTestTable(5, 100);
  87. t.setCaption("Table with 40 rows");
  88. // main.addComponent(t);
  89. t = getTestTable(4, 4);
  90. t.setCaption("Table with some rows and width = 200px");
  91. t.setWidth("200px");
  92. main.addComponent(t);
  93. final Button b = new Button("refresh view", new Button.ClickListener() {
  94. @Override
  95. public void buttonClick(ClickEvent event) {
  96. createNewView();
  97. }
  98. });
  99. main.addComponent(b);
  100. }
  101. public static Table getTestTable(int cols, int rows) {
  102. final Table t = new Table();
  103. t.setColumnCollapsingAllowed(true);
  104. for (int i = 0; i < cols; i++) {
  105. t.addContainerProperty(testString[i], String.class, "");
  106. }
  107. t.addContainerProperty("button", Button.class, null);
  108. for (int i = 0; i < rows; i++) {
  109. final Vector<Object> content = new Vector<Object>();
  110. for (int j = 0; j < cols; j++) {
  111. content.add(rndString());
  112. }
  113. Button button = new Button("b", new Button.ClickListener() {
  114. @Override
  115. public void buttonClick(ClickEvent event) {
  116. System.out.println("b click");
  117. }
  118. });
  119. button.setDescription("Yep yep");
  120. button.setComponentError(new UserError("Error"));
  121. content.add(button);
  122. t.addItem(content.toArray(), "" + i);
  123. }
  124. return t;
  125. }
  126. static String[] testString = new String[] { "Jacob", "Michael", "Joshua",
  127. "Matthew", "Ethan", "Andrew", "Daniel", "Anthony", "Christopher",
  128. "Joseph", "William", "Alexander", "Ryan", "David", "Nicholas",
  129. "Tyler", "James", "John", "Jonathan", "Nathan", "Samuel",
  130. "Christian", "Noah", "Dylan", "Benjamin", "Logan", "Brandon",
  131. "Gabriel", "Zachary", "Jose", "Elijah", "Angel", "Kevin", "Jack",
  132. "Caleb", "Justin", "Austin", "Evan", "Robert", "Thomas", "Luke",
  133. "Mason", "Aidan", "Jackson", "Isaiah", "Jordan", "Gavin", "Connor",
  134. "Aiden", "Isaac", "Jason", "Cameron", "Hunter", "Jayden", "Juan",
  135. "Charles", "Aaron", "Lucas", "Luis", "Owen", "Landon", "Diego",
  136. "Brian", "Adam", "Adrian", "Kyle", "Eric", "Ian", "Nathaniel",
  137. "Carlos", "Alex", "Bryan", "Jesus", "Julian", "Sean", "Carter",
  138. "Hayden", "Jeremiah", "Cole", "Brayden", "Wyatt", "Chase",
  139. "Steven", "Timothy", "Dominic", "Sebastian", "Xavier", "Jaden",
  140. "Jesse", "Devin", "Seth", "Antonio", "Richard", "Miguel", "Colin",
  141. "Cody", "Alejandro", "Caden", "Blake", "Carson" };
  142. public static String rndString() {
  143. return testString[(int) (Math.random() * testString.length)];
  144. }
  145. }