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.7KB

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