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.

ConverterThatEnforcesAFormat.java 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.vaadin.tests.converter;
  2. import java.util.Locale;
  3. import com.vaadin.data.Property.ValueChangeEvent;
  4. import com.vaadin.data.Property.ValueChangeListener;
  5. import com.vaadin.tests.components.TestBase;
  6. import com.vaadin.tests.util.Log;
  7. import com.vaadin.ui.TextField;
  8. public class ConverterThatEnforcesAFormat extends TestBase {
  9. private Log log = new Log(5);
  10. @Override
  11. protected void setup() {
  12. final TextField tf = new TextField(
  13. "This field should always be formatted with 3 digits");
  14. tf.setLocale(Locale.ENGLISH);
  15. tf.setConverter(new StringToDoubleConverterWithThreeFractionDigits());
  16. tf.addValueChangeListener(new ValueChangeListener() {
  17. @Override
  18. public void valueChange(ValueChangeEvent event) {
  19. log.log("Value changed to "
  20. + event.getProperty().getValue()
  21. + "(converted value is "
  22. + tf.getConvertedValue()
  23. + "). Two-way conversion gives: "
  24. + tf.getConverter().convertToPresentation(
  25. tf.getConverter().convertToModel(tf.getValue(),
  26. tf.getLocale()), tf.getLocale()) + ")");
  27. }
  28. });
  29. tf.setImmediate(true);
  30. addComponent(log);
  31. addComponent(tf);
  32. tf.setConvertedValue(50.0);
  33. }
  34. @Override
  35. protected String getDescription() {
  36. return "Entering a valid double in the field should always cause the field contents to be formatted to contain 3 digits after the decimal point";
  37. }
  38. @Override
  39. protected Integer getTicketNumber() {
  40. return 8191;
  41. }
  42. }