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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests;
  17. import com.vaadin.data.Property.ValueChangeEvent;
  18. import com.vaadin.ui.CustomComponent;
  19. import com.vaadin.ui.Label;
  20. import com.vaadin.ui.Table;
  21. import com.vaadin.ui.VerticalLayout;
  22. public class TableSelectTest extends CustomComponent implements
  23. Table.ValueChangeListener {
  24. public TableSelectTest() {
  25. final VerticalLayout main = new VerticalLayout();
  26. setCompositionRoot(main);
  27. main.addComponent(new Label("Hello World!"));
  28. Table t;
  29. t = new Table("single nullsel");
  30. main.addComponent(t);
  31. t(t);
  32. t.setMultiSelect(false);
  33. t.setNullSelectionAllowed(true);
  34. t.addListener(this);
  35. t = new Table("single NO-nullsel");
  36. main.addComponent(t);
  37. t(t);
  38. t.setMultiSelect(false);
  39. t.setNullSelectionAllowed(false);
  40. t.addListener(this);
  41. t = new Table("multi nullsel");
  42. main.addComponent(t);
  43. t(t);
  44. t.setMultiSelect(true);
  45. t.setNullSelectionAllowed(true);
  46. t.addListener(this);
  47. t = new Table("multi NO-nullsel");
  48. main.addComponent(t);
  49. t(t);
  50. t.setMultiSelect(true);
  51. t.setNullSelectionAllowed(false);
  52. t.addListener(this);
  53. // --
  54. t = new Table("single nullsel nullselid");
  55. main.addComponent(t);
  56. Object id = t(t);
  57. t.setNullSelectionItemId(id);
  58. t.setMultiSelect(false);
  59. t.setNullSelectionAllowed(true);
  60. t.addListener(this);
  61. t = new Table("single NO-nullsel nullselid");
  62. main.addComponent(t);
  63. id = t(t);
  64. t.setNullSelectionItemId(id);
  65. t.setMultiSelect(false);
  66. t.setNullSelectionAllowed(false);
  67. t.addListener(this);
  68. t = new Table("multi(fails) nullsel nullselid");
  69. main.addComponent(t);
  70. id = t(t);
  71. t.setNullSelectionItemId(id);
  72. try {
  73. t.setMultiSelect(true);
  74. t.setCaption("multi(SHOLD FAIL BUT DID NOT) nullsel nullselid");
  75. } catch (final Exception e) {
  76. System.err.println("failed ok");
  77. }
  78. t.setNullSelectionAllowed(true);
  79. t.addListener(this);
  80. t = new Table("multi(fails) NO-nullsel nullselid");
  81. main.addComponent(t);
  82. id = t(t);
  83. t.setNullSelectionItemId(id);
  84. try {
  85. t.setMultiSelect(true);
  86. t.setCaption("multi(SHOLD FAIL BUT DID NOT) NO-nullsel nullselid");
  87. } catch (final Exception e) {
  88. System.err.println("failed ok");
  89. }
  90. t.setNullSelectionAllowed(false);
  91. t.addListener(this);
  92. /*
  93. * And that's it! The framework will display the main window and its
  94. * contents when the application is accessed with the terminal.
  95. */
  96. }
  97. private Object t(Table t) {
  98. t.setImmediate(true);
  99. t.setSelectable(true);
  100. Object id = null;
  101. for (int i = 0; i < 5; i++) {
  102. id = t.addItem();
  103. }
  104. t.addContainerProperty("asd", String.class, "the asd thing");
  105. t.addContainerProperty("foo", String.class, "foo stuff");
  106. t.addContainerProperty("Alonger column header", String.class, "short");
  107. return id;
  108. }
  109. @Override
  110. public void valueChange(ValueChangeEvent event) {
  111. final Object val = event.getProperty().getValue();
  112. System.err.println("Value: " + val);
  113. }
  114. }