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.

ColumnReorderEvent.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.tests.components.TestBase;
  3. import com.vaadin.ui.HorizontalLayout;
  4. import com.vaadin.ui.Label;
  5. import com.vaadin.v7.data.Item;
  6. import com.vaadin.v7.data.util.IndexedContainer;
  7. import com.vaadin.v7.ui.Table;
  8. @SuppressWarnings("serial")
  9. public class ColumnReorderEvent extends TestBase {
  10. private Label order = new Label("Column order");
  11. @Override
  12. protected void setup() {
  13. HorizontalLayout widths = new HorizontalLayout();
  14. widths.setSpacing(true);
  15. widths.setWidth("50%");
  16. order.setCaption("Column 1 width");
  17. widths.addComponent(order);
  18. addComponent(widths);
  19. Table table1 = initTable();
  20. addComponent(table1);
  21. order.setValue(aToString(table1.getVisibleColumns()));
  22. }
  23. private String aToString(Object[] visibleColumns) {
  24. StringBuilder sb = new StringBuilder();
  25. for (Object object : visibleColumns) {
  26. sb.append(object);
  27. sb.append(" | ");
  28. }
  29. return sb.toString();
  30. }
  31. @Override
  32. protected String getDescription() {
  33. return "Test ColumnReorderEvents";
  34. }
  35. @Override
  36. protected Integer getTicketNumber() {
  37. return 6283;
  38. }
  39. private static final int ROWS = 100;
  40. private Table initTable() {
  41. final Table table = new Table();
  42. table.setWidth("100%");
  43. table.setImmediate(true);
  44. IndexedContainer idx = new IndexedContainer();
  45. idx.addContainerProperty("firstname", String.class, null);
  46. idx.addContainerProperty("lastname", String.class, null);
  47. Item i = idx.addItem(1);
  48. i.getItemProperty("firstname").setValue("John");
  49. i.getItemProperty("lastname").setValue("Johnson");
  50. i = idx.addItem(2);
  51. i.getItemProperty("firstname").setValue("Jane");
  52. i.getItemProperty("lastname").setValue("Janeine");
  53. for (int index = 3; index < ROWS; index++) {
  54. i = idx.addItem(index);
  55. i.getItemProperty("firstname").setValue("Jane");
  56. i.getItemProperty("lastname").setValue("Janeine");
  57. }
  58. idx.addContainerProperty("property", String.class, "foobar");
  59. table.setContainerDataSource(idx);
  60. table.setColumnHeader("firstname", "FirstName");
  61. table.setColumnHeader("lastname", "LastName");
  62. table.addListener(new Table.ColumnReorderListener() {
  63. @Override
  64. public void columnReorder(
  65. com.vaadin.v7.ui.Table.ColumnReorderEvent event) {
  66. order.setValue(aToString(table.getVisibleColumns()));
  67. }
  68. });
  69. table.setColumnReorderingAllowed(true);
  70. return table;
  71. }
  72. }