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.2KB

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