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.

ComponentsInTable.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.automatedtests;
  5. import java.util.Date;
  6. import java.util.Random;
  7. import java.util.Vector;
  8. import com.vaadin.ui.Button;
  9. import com.vaadin.ui.CustomComponent;
  10. import com.vaadin.ui.OrderedLayout;
  11. import com.vaadin.ui.Table;
  12. import com.vaadin.ui.Button.ClickEvent;
  13. @SuppressWarnings("serial")
  14. public class ComponentsInTable extends CustomComponent {
  15. public ComponentsInTable(int cols, int rows) {
  16. final OrderedLayout main = new OrderedLayout();
  17. setCompositionRoot(main);
  18. main.addComponent(getTestTable(cols, rows));
  19. }
  20. public static Table getTestTable(int cols, int rows) {
  21. Random rnd = new Random(1);
  22. final Table t = new Table();
  23. t.setColumnCollapsingAllowed(true);
  24. for (int i = 0; i < cols; i++) {
  25. t.addContainerProperty(testString[i], String.class, "");
  26. }
  27. t.addContainerProperty("button", Button.class, null);
  28. for (int i = 0; i < rows; i++) {
  29. final Vector content = new Vector();
  30. for (int j = 0; j < cols; j++) {
  31. content.add(rndString(rnd));
  32. }
  33. content.add(new Button("b" + i, new Button.ClickListener() {
  34. public void buttonClick(ClickEvent event) {
  35. System.out.println(event.getButton().getCaption()
  36. + " click: " + (new Date()).toGMTString());
  37. System.out.println(event.getButton().getApplication());
  38. }
  39. }));
  40. t.addItem(content.toArray(), "" + i);
  41. }
  42. t.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
  43. return t;
  44. }
  45. static String[] testString = new String[] { "Jacob", "Michael", "Joshua",
  46. "Matthew", "Ethan", "Andrew", "Daniel", "Anthony", "Christopher",
  47. "Joseph", "William", "Alexander", "Ryan", "David", "Nicholas",
  48. "Tyler", "James", "John", "Jonathan", "Nathan", "Samuel",
  49. "Christian", "Noah", "Dylan", "Benjamin", "Logan", "Brandon",
  50. "Gabriel", "Zachary", "Jose", "Elijah", "Angel", "Kevin", "Jack",
  51. "Caleb", "Justin", "Austin", "Evan", "Robert", "Thomas", "Luke",
  52. "Mason", "Aidan", "Jackson", "Isaiah", "Jordan", "Gavin", "Connor",
  53. "Aiden", "Isaac", "Jason", "Cameron", "Hunter", "Jayden", "Juan",
  54. "Charles", "Aaron", "Lucas", "Luis", "Owen", "Landon", "Diego",
  55. "Brian", "Adam", "Adrian", "Kyle", "Eric", "Ian", "Nathaniel",
  56. "Carlos", "Alex", "Bryan", "Jesus", "Julian", "Sean", "Carter",
  57. "Hayden", "Jeremiah", "Cole", "Brayden", "Wyatt", "Chase",
  58. "Steven", "Timothy", "Dominic", "Sebastian", "Xavier", "Jaden",
  59. "Jesse", "Devin", "Seth", "Antonio", "Richard", "Miguel", "Colin",
  60. "Cody", "Alejandro", "Caden", "Blake", "Carson" };
  61. public static String rndString(Random rnd) {
  62. return testString[(int) (rnd.nextDouble() * testString.length)];
  63. }
  64. }