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.

TableItemDescriptionGeneratorUI.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.ValueChangeEvent;
  5. import com.vaadin.data.Property.ValueChangeListener;
  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.AbstractSelect.ItemDescriptionGenerator;
  10. import com.vaadin.ui.Button;
  11. import com.vaadin.ui.CheckBox;
  12. import com.vaadin.ui.Component;
  13. import com.vaadin.ui.Table;
  14. import com.vaadin.ui.TextField;
  15. public class TableItemDescriptionGeneratorUI extends AbstractTestUI {
  16. private final String TEXT_PROPERTY_ID = "Text";
  17. private final String GEN_WIDGET_PROPERTY_ID = "Generated component";
  18. private final String WIDGET_PROPERTY_ID = "Component";
  19. private CheckBox componentDescription;
  20. private CheckBox tableCellItemDescription;
  21. private CheckBox tableRowItemDescription;
  22. @Override
  23. protected void setup(VaadinRequest request) {
  24. final Table table = createTable();
  25. table.setId("table");
  26. componentDescription = new CheckBox("Tooltip on components");
  27. componentDescription.addValueChangeListener(new ValueChangeListener() {
  28. @Override
  29. public void valueChange(ValueChangeEvent event) {
  30. table.setContainerDataSource(createContainer(componentDescription
  31. .getValue()));
  32. }
  33. });
  34. componentDescription.setImmediate(true);
  35. componentDescription.setValue(true);
  36. tableCellItemDescription = new CheckBox("Tooltip on table cells");
  37. tableCellItemDescription
  38. .addValueChangeListener(new ValueChangeListener() {
  39. @Override
  40. public void valueChange(ValueChangeEvent event) {
  41. table.refreshRowCache();
  42. }
  43. });
  44. tableCellItemDescription.setImmediate(true);
  45. tableCellItemDescription.setValue(true);
  46. tableRowItemDescription = new CheckBox("Tooltip on table Rows");
  47. tableRowItemDescription
  48. .addValueChangeListener(new ValueChangeListener() {
  49. @Override
  50. public void valueChange(ValueChangeEvent event) {
  51. table.refreshRowCache();
  52. }
  53. });
  54. tableRowItemDescription.setImmediate(true);
  55. tableRowItemDescription.setValue(true);
  56. addComponent(componentDescription);
  57. addComponent(tableCellItemDescription);
  58. addComponent(tableRowItemDescription);
  59. addComponent(table);
  60. table.setItemDescriptionGenerator(new ItemDescriptionGenerator() {
  61. @Override
  62. public String generateDescription(Component source, Object itemId,
  63. Object propertyId) {
  64. if (propertyId == null && tableRowItemDescription.getValue()) {
  65. return "Row description " + itemId;
  66. } else if (tableCellItemDescription.getValue()) {
  67. return "Cell description " + itemId + ", " + propertyId;
  68. }
  69. return null;
  70. }
  71. });
  72. table.addGeneratedColumn(GEN_WIDGET_PROPERTY_ID,
  73. new Table.ColumnGenerator() {
  74. @Override
  75. public Component generateCell(Table source, Object itemId,
  76. Object columnId) {
  77. TextField lbl = new TextField();
  78. if (componentDescription.getValue()) {
  79. lbl.setDescription("Textfield's own description");
  80. }
  81. return lbl;
  82. }
  83. });
  84. }
  85. protected Table createTable() {
  86. return new Table();
  87. }
  88. @Override
  89. protected String getTestDescription() {
  90. return "Cells and rows should have tooltips";
  91. }
  92. @Override
  93. protected Integer getTicketNumber() {
  94. return 5414;
  95. }
  96. @SuppressWarnings("unchecked")
  97. private Container createContainer(boolean description) {
  98. IndexedContainer container = new IndexedContainer();
  99. container.addContainerProperty(TEXT_PROPERTY_ID, String.class, "");
  100. container.addContainerProperty(WIDGET_PROPERTY_ID, Component.class,
  101. null);
  102. for (int i = 0; i < 5; i++) {
  103. Item item = container.addItem("item " + i);
  104. item.getItemProperty(TEXT_PROPERTY_ID).setValue("Text " + i);
  105. Button b = new Button("Button " + i);
  106. if (description) {
  107. b.setDescription("Button " + i + " description");
  108. }
  109. item.getItemProperty(WIDGET_PROPERTY_ID).setValue(b);
  110. }
  111. return container;
  112. }
  113. }