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.

ColumnResizeEvent.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 ColumnResizeEvent extends TestBase {
  10. private Label column1Width = new Label("Undefined");
  11. private Label column2Width = new Label("Undefined");
  12. private Label column3Width = new Label("Undefined");
  13. @Override
  14. protected void setup() {
  15. HorizontalLayout widths = new HorizontalLayout();
  16. widths.setSpacing(true);
  17. widths.setWidth("50%");
  18. column1Width.setCaption("Column 1 width");
  19. widths.addComponent(column1Width);
  20. column2Width.setCaption("Column 2 width");
  21. widths.addComponent(column2Width);
  22. column3Width.setCaption("Column 3 width");
  23. widths.addComponent(column3Width);
  24. addComponent(widths);
  25. Table table1 = initTable();
  26. addComponent(table1);
  27. }
  28. @Override
  29. protected String getDescription() {
  30. return "Table should update column size back to server";
  31. }
  32. @Override
  33. protected Integer getTicketNumber() {
  34. return 2807;
  35. }
  36. private static final int ROWS = 100;
  37. private Table initTable() {
  38. Table table = new Table();
  39. table.setWidth("100%");
  40. table.setImmediate(true);
  41. IndexedContainer idx = new IndexedContainer();
  42. idx.addContainerProperty("firstname", String.class, null);
  43. idx.addContainerProperty("lastname", String.class, null);
  44. Item i = idx.addItem(1);
  45. i.getItemProperty("firstname").setValue("John");
  46. i.getItemProperty("lastname").setValue("Johnson");
  47. i = idx.addItem(2);
  48. i.getItemProperty("firstname").setValue("Jane");
  49. i.getItemProperty("lastname").setValue("Janeine");
  50. for (int index = 3; index < ROWS; index++) {
  51. i = idx.addItem(index);
  52. i.getItemProperty("firstname").setValue("Jane");
  53. i.getItemProperty("lastname").setValue("Janeine");
  54. }
  55. idx.addContainerProperty("150pxfixedCol", String.class, "foobar");
  56. table.setContainerDataSource(idx);
  57. table.setColumnHeader("firstname", "FirstName");
  58. table.setColumnHeader("lastname", "LastName with long header");
  59. table.setColumnWidth("150pxfixedCol", 150);
  60. column3Width.setValue(table.getColumnWidth("150pxfixedCol") + "px");
  61. table.addColumnResizeListener(event -> {
  62. if (event.getPropertyId().equals("firstname")) {
  63. column1Width.setValue(event.getCurrentWidth()
  64. + "px (previously " + event.getPreviousWidth() + "px)");
  65. } else if (event.getPropertyId().equals("lastname")) {
  66. column2Width.setValue(event.getCurrentWidth()
  67. + "px (previously " + event.getPreviousWidth() + "px)");
  68. } else if (event.getPropertyId().equals("150pxfixedCol")) {
  69. column3Width.setValue(event.getCurrentWidth()
  70. + "px (previously " + event.getPreviousWidth() + "px)");
  71. }
  72. });
  73. return table;
  74. }
  75. }