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.

TextFieldRelativeWidth.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.server.VaadinRequest;
  3. import com.vaadin.tests.components.AbstractReindeerTestUI;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.Button.ClickEvent;
  6. import com.vaadin.ui.Component;
  7. import com.vaadin.v7.data.Item;
  8. import com.vaadin.v7.data.util.IndexedContainer;
  9. import com.vaadin.v7.ui.Table;
  10. import com.vaadin.v7.ui.TextField;
  11. public class TextFieldRelativeWidth extends AbstractReindeerTestUI {
  12. @Override
  13. public void setup(VaadinRequest request) {
  14. TextField tf = new TextField("test", "testing");
  15. tf.setWidth("100%");
  16. EditTable t = new EditTable();
  17. t.setButtonCaption("Click to add new Key Research Question");
  18. t.setInputPrompt("Key Reseach question");
  19. t.setInputPromptChild("Question details");
  20. t.addNewRow();
  21. addComponent(t);
  22. }
  23. public class EditTable extends Table implements Button.ClickListener {
  24. private Button addButton = new Button("Add new row", this);
  25. private String inputPrompt;
  26. private String inputPromptChild;
  27. private int nextItemIndex = 1;
  28. @SuppressWarnings("unchecked")
  29. public EditTable() {
  30. setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
  31. inputPrompt = "";
  32. setPageLength(100);
  33. setHeight("100%");
  34. setSizeFull();
  35. addContainerProperty("id", Integer.class, null);
  36. addContainerProperty("text", Component.class, null);
  37. addContainerProperty("button", Button.class, null);
  38. setColumnExpandRatio("text", 1);
  39. Item i = getItem(addItem());
  40. i.getItemProperty("text").setValue(addButton);
  41. setImmediate(true);
  42. setSelectable(true);
  43. }
  44. @SuppressWarnings("unchecked")
  45. public void addNewRow() {
  46. IndexedContainer idc = (IndexedContainer) getContainerDataSource();
  47. int size = idc.size();
  48. Object itemId = idc.addItemAt(size - 1);
  49. Item newItem = idc.getItem(itemId);
  50. TextField tf = new TextField();
  51. if (inputPrompt != null && !inputPrompt.isEmpty()) {
  52. tf.setInputPrompt(inputPrompt);
  53. }
  54. tf.setWidth("100%");
  55. newItem.getItemProperty("id").setValue(nextItemIndex);
  56. nextItemIndex++;
  57. newItem.getItemProperty("text").setValue(tf);
  58. setValue(itemId);
  59. itemId = idc.addItemAt(size);
  60. newItem = idc.getItem(itemId);
  61. tf = new TextField();
  62. if (inputPromptChild != null && !inputPromptChild.isEmpty()) {
  63. tf.setInputPrompt(inputPromptChild);
  64. }
  65. tf.setWidth("100%");
  66. tf.addStyleName("childtf");
  67. newItem.getItemProperty("text").setValue(tf);
  68. }
  69. public void setButtonCaption(String caption) {
  70. addButton.setCaption(caption);
  71. }
  72. @Override
  73. public void buttonClick(ClickEvent event) {
  74. Button b = event.getButton();
  75. if (b == addButton) {
  76. select(getNullSelectionItemId());
  77. addNewRow();
  78. }
  79. }
  80. public void setInputPrompt(String string) {
  81. inputPrompt = string;
  82. }
  83. public void setInputPromptChild(String string) {
  84. inputPromptChild = string;
  85. }
  86. }
  87. @Override
  88. protected String getTestDescription() {
  89. return "The table has 3 columns. The second column is expanded and contains 100% wide textfields. These should fill the available space. The third column is empty.";
  90. }
  91. @Override
  92. protected Integer getTicketNumber() {
  93. return 3145;
  94. }
  95. }