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.

VTextFieldPaintable.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui;
  5. import com.google.gwt.core.client.GWT;
  6. import com.google.gwt.core.client.Scheduler;
  7. import com.google.gwt.user.client.Command;
  8. import com.google.gwt.user.client.Event;
  9. import com.google.gwt.user.client.ui.Widget;
  10. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  11. import com.vaadin.terminal.gwt.client.UIDL;
  12. import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
  13. public class VTextFieldPaintable extends VAbstractPaintableWidget implements
  14. BeforeShortcutActionListener {
  15. @Override
  16. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  17. // Save details
  18. getWidgetForPaintable().client = client;
  19. getWidgetForPaintable().paintableId = uidl.getId();
  20. super.updateFromUIDL(uidl, client);
  21. if (!isRealUpdate(uidl)) {
  22. return;
  23. }
  24. if (uidl.getBooleanAttribute("readonly")) {
  25. getWidgetForPaintable().setReadOnly(true);
  26. } else {
  27. getWidgetForPaintable().setReadOnly(false);
  28. }
  29. getWidgetForPaintable().inputPrompt = uidl
  30. .getStringAttribute(VTextField.ATTR_INPUTPROMPT);
  31. getWidgetForPaintable().setMaxLength(
  32. uidl.hasAttribute("maxLength") ? uidl
  33. .getIntAttribute("maxLength") : -1);
  34. getWidgetForPaintable().immediate = uidl
  35. .getBooleanAttribute("immediate");
  36. getWidgetForPaintable().listenTextChangeEvents = client
  37. .hasEventListeners(this, "ie");
  38. if (getWidgetForPaintable().listenTextChangeEvents) {
  39. getWidgetForPaintable().textChangeEventMode = uidl
  40. .getStringAttribute(VTextField.ATTR_TEXTCHANGE_EVENTMODE);
  41. if (getWidgetForPaintable().textChangeEventMode
  42. .equals(VTextField.TEXTCHANGE_MODE_EAGER)) {
  43. getWidgetForPaintable().textChangeEventTimeout = 1;
  44. } else {
  45. getWidgetForPaintable().textChangeEventTimeout = uidl
  46. .getIntAttribute(VTextField.ATTR_TEXTCHANGE_TIMEOUT);
  47. if (getWidgetForPaintable().textChangeEventTimeout < 1) {
  48. // Sanitize and allow lazy/timeout with timeout set to 0 to
  49. // work as eager
  50. getWidgetForPaintable().textChangeEventTimeout = 1;
  51. }
  52. }
  53. getWidgetForPaintable().sinkEvents(VTextField.TEXTCHANGE_EVENTS);
  54. getWidgetForPaintable().attachCutEventListener(
  55. getWidgetForPaintable().getElement());
  56. }
  57. if (uidl.hasAttribute("cols")) {
  58. getWidgetForPaintable().setColumns(
  59. new Integer(uidl.getStringAttribute("cols")).intValue());
  60. }
  61. final String text = uidl.getStringVariable("text");
  62. /*
  63. * We skip the text content update if field has been repainted, but text
  64. * has not been changed. Additional sanity check verifies there is no
  65. * change in the que (in which case we count more on the server side
  66. * value).
  67. */
  68. if (!(uidl
  69. .getBooleanAttribute(VTextField.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS)
  70. && getWidgetForPaintable().valueBeforeEdit != null && text
  71. .equals(getWidgetForPaintable().valueBeforeEdit))) {
  72. getWidgetForPaintable().updateFieldContent(text);
  73. }
  74. if (uidl.hasAttribute("selpos")) {
  75. final int pos = uidl.getIntAttribute("selpos");
  76. final int length = uidl.getIntAttribute("sellen");
  77. /*
  78. * Gecko defers setting the text so we need to defer the selection.
  79. */
  80. Scheduler.get().scheduleDeferred(new Command() {
  81. public void execute() {
  82. getWidgetForPaintable().setSelectionRange(pos, length);
  83. }
  84. });
  85. }
  86. // Here for backward compatibility; to be moved to TextArea.
  87. // Optimization: server does not send attribute for the default 'true'
  88. // state.
  89. if (uidl.hasAttribute("wordwrap")
  90. && uidl.getBooleanAttribute("wordwrap") == false) {
  91. getWidgetForPaintable().setWordwrap(false);
  92. } else {
  93. getWidgetForPaintable().setWordwrap(true);
  94. }
  95. }
  96. @Override
  97. protected Widget createWidget() {
  98. return GWT.create(VTextField.class);
  99. }
  100. @Override
  101. public VTextField getWidgetForPaintable() {
  102. return (VTextField) super.getWidgetForPaintable();
  103. }
  104. public void onBeforeShortcutAction(Event e) {
  105. getWidgetForPaintable().valueChange(false);
  106. }
  107. }