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.

TextFieldInputPromptAndClickShortcut.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.vaadin.tests.components.textfield;
  2. import com.vaadin.event.ShortcutAction.KeyCode;
  3. import com.vaadin.tests.components.TestBase;
  4. import com.vaadin.tests.util.Log;
  5. import com.vaadin.ui.Button;
  6. import com.vaadin.ui.CheckBox;
  7. import com.vaadin.v7.ui.TextField;
  8. public class TextFieldInputPromptAndClickShortcut extends TestBase {
  9. @Override
  10. protected void setup() {
  11. final Log log = new Log(5);
  12. final TextField textField = new TextField();
  13. Button button = new Button("Show Text",
  14. event -> log.log("Field value: " + textField.getValue()));
  15. button.setClickShortcut(KeyCode.ESCAPE);
  16. final CheckBox inputPromptSelection = new CheckBox("Input prompt");
  17. inputPromptSelection.addValueChangeListener(event -> {
  18. if (event.getValue()) {
  19. textField.setInputPrompt("Input prompt");
  20. } else {
  21. textField.setInputPrompt(null);
  22. }
  23. log.log("Set input prompt: " + textField.getInputPrompt());
  24. });
  25. addComponent(textField);
  26. addComponent(button);
  27. addComponent(inputPromptSelection);
  28. addComponent(log);
  29. }
  30. @Override
  31. protected String getDescription() {
  32. return "With the input propmpt enabled, enter something into the field, press enter, remove the entered text and press the button. The previous text is still reported as the value. Without the input prompt, the new value is instead reported as blank.";
  33. }
  34. @Override
  35. protected Integer getTicketNumber() {
  36. // TODO Auto-generated method stub
  37. return null;
  38. }
  39. }