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.

KeyControl.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package com.vaadin.tests.components.table;
  2. import java.util.Set;
  3. import com.vaadin.tests.components.TestBase;
  4. import com.vaadin.ui.HorizontalLayout;
  5. import com.vaadin.ui.Label;
  6. import com.vaadin.ui.VerticalLayout;
  7. import com.vaadin.v7.data.Container;
  8. import com.vaadin.v7.data.Item;
  9. import com.vaadin.v7.data.Property.ValueChangeEvent;
  10. import com.vaadin.v7.data.util.IndexedContainer;
  11. import com.vaadin.v7.ui.Table;
  12. @SuppressWarnings("serial")
  13. public class KeyControl extends TestBase {
  14. private final Label selected1 = new Label("No selected items.");
  15. private final Table table1 = new Table("Read only table");
  16. private final Label selected2 = new Label("No selected items");
  17. private final Table table2 = new Table("Selectable table");
  18. private final Label selected3 = new Label("Not selected items");
  19. private final Table table3 = new Table("Multi-selectable table");
  20. @Override
  21. protected void setup() {
  22. HorizontalLayout layout = new HorizontalLayout();
  23. layout.setSpacing(true);
  24. addComponent(layout);
  25. // Create read only table
  26. VerticalLayout layout1 = new VerticalLayout();
  27. layout1.setSpacing(true);
  28. table1.setContainerDataSource(createContainer());
  29. table1.setWidth("300px");
  30. table1.setHeight("300px");
  31. table1.setImmediate(true);
  32. layout1.addComponent(table1);
  33. table1.addListener(new Table.ValueChangeListener() {
  34. @Override
  35. public void valueChange(ValueChangeEvent event) {
  36. @SuppressWarnings("unchecked")
  37. Set<String> value = (Set<String>) table1.getValue();
  38. selected1.setValue(value + " TOTAL: " + value.size());
  39. }
  40. });
  41. layout1.addComponent(selected1);
  42. layout.addComponent(layout1);
  43. // Create single select table
  44. VerticalLayout layout2 = new VerticalLayout();
  45. layout2.setSpacing(true);
  46. table2.setContainerDataSource(createContainer());
  47. table2.setSelectable(true);
  48. table2.setWidth("300px");
  49. table2.setHeight("300px");
  50. table2.setImmediate(true);
  51. layout2.addComponent(table2);
  52. table2.addListener(new Table.ValueChangeListener() {
  53. @Override
  54. public void valueChange(ValueChangeEvent event) {
  55. String value = table2.getValue() == null ? "No selected items"
  56. : table2.getValue().toString();
  57. selected2.setValue(value);
  58. }
  59. });
  60. layout2.addComponent(selected2);
  61. layout.addComponent(layout2);
  62. // Create multi select table
  63. VerticalLayout layout3 = new VerticalLayout();
  64. layout3.setSpacing(true);
  65. table3.setContainerDataSource(createContainer());
  66. table3.setSelectable(true);
  67. table3.setMultiSelect(true);
  68. table3.setWidth("300px");
  69. table3.setHeight("300px");
  70. table3.setImmediate(true);
  71. layout3.addComponent(table3);
  72. table3.addListener(new Table.ValueChangeListener() {
  73. @Override
  74. public void valueChange(ValueChangeEvent event) {
  75. @SuppressWarnings("unchecked")
  76. Set<String> value = (Set<String>) table3.getValue();
  77. selected3.setValue(value.size() == 0 ? "No selected items"
  78. : value + ": Total " + value.size() + " items");
  79. }
  80. });
  81. selected3.setWidth("300px");
  82. selected3.setHeight("500px");
  83. layout3.addComponent(selected3);
  84. layout.addComponent(layout3);
  85. }
  86. @Override
  87. protected String getDescription() {
  88. return "Add keyboard control to the Table";
  89. }
  90. @Override
  91. protected Integer getTicketNumber() {
  92. return 2390;
  93. }
  94. private Container createContainer() {
  95. IndexedContainer container = new IndexedContainer();
  96. container.addContainerProperty("col1", String.class, "");
  97. container.addContainerProperty("col2", String.class, "");
  98. container.addContainerProperty("col3", String.class, "");
  99. container.addContainerProperty("col4", String.class, "");
  100. container.addContainerProperty("col5", String.class, "");
  101. container.addContainerProperty("col6", String.class, "");
  102. for (int i = 0; i < 100; i++) {
  103. Item item = container.addItem("item " + i);
  104. item.getItemProperty("col1").setValue("First column " + i);
  105. item.getItemProperty("col2").setValue("Second column " + i);
  106. item.getItemProperty("col3").setValue("Third column" + i);
  107. item.getItemProperty("col4").setValue("Fourth column" + i);
  108. item.getItemProperty("col5").setValue("Fifth column" + i);
  109. item.getItemProperty("col6").setValue("Sixth column" + i);
  110. }
  111. return container;
  112. }
  113. }