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.

TableSelectTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.vaadin.tests;
  2. import com.vaadin.ui.CustomComponent;
  3. import com.vaadin.ui.Label;
  4. import com.vaadin.ui.VerticalLayout;
  5. import com.vaadin.v7.data.Property.ValueChangeEvent;
  6. import com.vaadin.v7.ui.Table;
  7. public class TableSelectTest extends CustomComponent
  8. implements Table.ValueChangeListener {
  9. public TableSelectTest() {
  10. final VerticalLayout main = new VerticalLayout();
  11. setCompositionRoot(main);
  12. main.addComponent(new Label("Hello World!"));
  13. Table t;
  14. t = new Table("single nullsel");
  15. main.addComponent(t);
  16. t(t);
  17. t.setMultiSelect(false);
  18. t.setNullSelectionAllowed(true);
  19. t.addListener(this);
  20. t = new Table("single NO-nullsel");
  21. main.addComponent(t);
  22. t(t);
  23. t.setMultiSelect(false);
  24. t.setNullSelectionAllowed(false);
  25. t.addListener(this);
  26. t = new Table("multi nullsel");
  27. main.addComponent(t);
  28. t(t);
  29. t.setMultiSelect(true);
  30. t.setNullSelectionAllowed(true);
  31. t.addListener(this);
  32. t = new Table("multi NO-nullsel");
  33. main.addComponent(t);
  34. t(t);
  35. t.setMultiSelect(true);
  36. t.setNullSelectionAllowed(false);
  37. t.addListener(this);
  38. // --
  39. t = new Table("single nullsel nullselid");
  40. main.addComponent(t);
  41. Object id = t(t);
  42. t.setNullSelectionItemId(id);
  43. t.setMultiSelect(false);
  44. t.setNullSelectionAllowed(true);
  45. t.addListener(this);
  46. t = new Table("single NO-nullsel nullselid");
  47. main.addComponent(t);
  48. id = t(t);
  49. t.setNullSelectionItemId(id);
  50. t.setMultiSelect(false);
  51. t.setNullSelectionAllowed(false);
  52. t.addListener(this);
  53. t = new Table("multi(fails) nullsel nullselid");
  54. main.addComponent(t);
  55. id = t(t);
  56. t.setNullSelectionItemId(id);
  57. try {
  58. t.setMultiSelect(true);
  59. t.setCaption("multi(SHOLD FAIL BUT DID NOT) nullsel nullselid");
  60. } catch (final Exception e) {
  61. System.err.println("failed ok");
  62. }
  63. t.setNullSelectionAllowed(true);
  64. t.addListener(this);
  65. t = new Table("multi(fails) NO-nullsel nullselid");
  66. main.addComponent(t);
  67. id = t(t);
  68. t.setNullSelectionItemId(id);
  69. try {
  70. t.setMultiSelect(true);
  71. t.setCaption("multi(SHOLD FAIL BUT DID NOT) NO-nullsel nullselid");
  72. } catch (final Exception e) {
  73. System.err.println("failed ok");
  74. }
  75. t.setNullSelectionAllowed(false);
  76. t.addListener(this);
  77. /*
  78. * And that's it! The framework will display the main window and its
  79. * contents when the application is accessed with the terminal.
  80. */
  81. }
  82. private Object t(Table t) {
  83. t.setImmediate(true);
  84. t.setSelectable(true);
  85. Object id = null;
  86. for (int i = 0; i < 5; i++) {
  87. id = t.addItem();
  88. }
  89. t.addContainerProperty("asd", String.class, "the asd thing");
  90. t.addContainerProperty("foo", String.class, "foo stuff");
  91. t.addContainerProperty("Alonger column header", String.class, "short");
  92. return id;
  93. }
  94. @Override
  95. public void valueChange(ValueChangeEvent event) {
  96. final Object val = event.getProperty().getValue();
  97. System.err.println("Value: " + val);
  98. }
  99. }