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.

EnterShortcutMaySendInputPromptAsValue.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package com.vaadin.tests.components.textfield;
  2. import com.vaadin.data.Property.ValueChangeEvent;
  3. import com.vaadin.data.Property.ValueChangeListener;
  4. import com.vaadin.event.Action;
  5. import com.vaadin.event.ShortcutAction;
  6. import com.vaadin.tests.components.TestBase;
  7. import com.vaadin.ui.Label;
  8. import com.vaadin.ui.TextField;
  9. public class EnterShortcutMaySendInputPromptAsValue extends TestBase {
  10. @Override
  11. protected String getDescription() {
  12. return "?";
  13. }
  14. @Override
  15. protected Integer getTicketNumber() {
  16. return 2935;
  17. }
  18. @Override
  19. protected void setup() {
  20. final TextField testField = new TextField();
  21. testField.setInputPrompt("Enter a value");
  22. getMainWindow().addActionHandler(new Action.Handler() {
  23. final Action enter = new ShortcutAction("enter",
  24. ShortcutAction.KeyCode.ENTER, null);
  25. @Override
  26. public Action[] getActions(Object target, Object sender) {
  27. return new Action[] { enter };
  28. }
  29. @Override
  30. public void handleAction(Action action, Object sender, Object target) {
  31. if (action == enter) {
  32. }
  33. }
  34. });
  35. testField.addListener(new ValueChangeListener() {
  36. @Override
  37. public void valueChange(ValueChangeEvent event) {
  38. String value = event.getProperty().getValue().toString();
  39. addComponent(new Label("TextField sent value: " + value));
  40. testField.setValue("");
  41. }
  42. });
  43. addComponent(testField);
  44. }
  45. }