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.

Footer.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.server.VaadinRequest;
  3. import com.vaadin.tests.components.AbstractReindeerTestUI;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.CheckBox;
  6. import com.vaadin.ui.HorizontalLayout;
  7. import com.vaadin.ui.TextField;
  8. import com.vaadin.ui.VerticalLayout;
  9. import com.vaadin.v7.data.Container;
  10. import com.vaadin.v7.data.Item;
  11. import com.vaadin.v7.data.util.IndexedContainer;
  12. import com.vaadin.v7.ui.Table;
  13. public class Footer extends AbstractReindeerTestUI {
  14. @Override
  15. protected void setup(VaadinRequest request) {
  16. HorizontalLayout layout = new HorizontalLayout();
  17. final Table table = new Table();
  18. table.setWidth("400px");
  19. table.setHeight("400px");
  20. table.setContainerDataSource(createContainer());
  21. table.setImmediate(true);
  22. table.setColumnCollapsingAllowed(true);
  23. table.setColumnReorderingAllowed(true);
  24. table.setFooterVisible(true);
  25. table.setColumnFooter("col1", "Footer1");
  26. table.setColumnFooter("col2", "Footer2");
  27. table.setColumnFooter("col3", "Footer3");
  28. table.setColumnAlignment("col2", Table.ALIGN_CENTER);
  29. table.setColumnAlignment("col3", Table.ALIGN_RIGHT);
  30. layout.addComponent(table);
  31. // Add some options to play with
  32. VerticalLayout options = new VerticalLayout();
  33. options.setMargin(false);
  34. final CheckBox visible = new CheckBox("Footers Visible", true);
  35. visible.addValueChangeListener(
  36. event -> table.setFooterVisible(visible.getValue()));
  37. options.addComponent(visible);
  38. final TextField footer1Value = new TextField(null, "Footer1");
  39. Button footer1Btn = new Button("Change",
  40. event -> table.setColumnFooter("col1",
  41. footer1Value.getValue() == null ? ""
  42. : footer1Value.getValue()));
  43. HorizontalLayout footer1 = new HorizontalLayout();
  44. footer1.setSpacing(false);
  45. footer1.addComponent(footer1Value);
  46. footer1.addComponent(footer1Btn);
  47. options.addComponent(footer1);
  48. final TextField footer2Value = new TextField(null, "Footer2");
  49. Button footer2Btn = new Button("Change",
  50. event -> table.setColumnFooter("col2",
  51. footer2Value.getValue() == null ? ""
  52. : footer2Value.getValue()));
  53. HorizontalLayout footer2 = new HorizontalLayout();
  54. footer2.setSpacing(false);
  55. footer2.addComponent(footer2Value);
  56. footer2.addComponent(footer2Btn);
  57. options.addComponent(footer2);
  58. final TextField footer3Value = new TextField(null, "Footer3");
  59. Button footer3Btn = new Button("Change",
  60. event -> table.setColumnFooter("col3",
  61. footer3Value.getValue() == null ? ""
  62. : footer3Value.getValue()));
  63. HorizontalLayout footer3 = new HorizontalLayout();
  64. footer3.setSpacing(false);
  65. footer3.addComponent(footer3Value);
  66. footer3.addComponent(footer3Btn);
  67. options.addComponent(footer3);
  68. layout.addComponent(options);
  69. addComponent(layout);
  70. }
  71. @Override
  72. protected String getTestDescription() {
  73. return "Table with footer";
  74. }
  75. @Override
  76. protected Integer getTicketNumber() {
  77. return 1553;
  78. }
  79. private Container createContainer() {
  80. IndexedContainer container = new IndexedContainer();
  81. container.addContainerProperty("col1", String.class, "");
  82. container.addContainerProperty("col2", String.class, "");
  83. container.addContainerProperty("col3", String.class, "");
  84. for (int i = 0; i < 100; i++) {
  85. Item item = container.addItem("item " + i);
  86. item.getItemProperty("col1").setValue("first" + i);
  87. item.getItemProperty("col2").setValue("middle" + i);
  88. item.getItemProperty("col3").setValue("last" + i);
  89. }
  90. return container;
  91. }
  92. }