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.

VRichTextAreaPaintable.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui.richtextarea;
  5. import com.google.gwt.core.client.GWT;
  6. import com.google.gwt.user.client.Event;
  7. import com.google.gwt.user.client.ui.Widget;
  8. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  9. import com.vaadin.terminal.gwt.client.UIDL;
  10. import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
  11. import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidget;
  12. public class VRichTextAreaPaintable extends VAbstractPaintableWidget implements
  13. BeforeShortcutActionListener {
  14. @Override
  15. public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
  16. getWidgetForPaintable().client = client;
  17. getWidgetForPaintable().id = uidl.getId();
  18. if (uidl.hasVariable("text")) {
  19. getWidgetForPaintable().currentValue = uidl
  20. .getStringVariable("text");
  21. if (getWidgetForPaintable().rta.isAttached()) {
  22. getWidgetForPaintable().rta
  23. .setHTML(getWidgetForPaintable().currentValue);
  24. } else {
  25. getWidgetForPaintable().html
  26. .setHTML(getWidgetForPaintable().currentValue);
  27. }
  28. }
  29. if (isRealUpdate(uidl)) {
  30. getWidgetForPaintable().setEnabled(
  31. !uidl.getBooleanAttribute("disabled"));
  32. }
  33. super.updateFromUIDL(uidl, client);
  34. if (!isRealUpdate(uidl)) {
  35. return;
  36. }
  37. getWidgetForPaintable().setReadOnly(
  38. uidl.getBooleanAttribute("readonly"));
  39. getWidgetForPaintable().immediate = uidl
  40. .getBooleanAttribute("immediate");
  41. int newMaxLength = uidl.hasAttribute("maxLength") ? uidl
  42. .getIntAttribute("maxLength") : -1;
  43. if (newMaxLength >= 0) {
  44. if (getWidgetForPaintable().maxLength == -1) {
  45. getWidgetForPaintable().keyPressHandler = getWidgetForPaintable().rta
  46. .addKeyPressHandler(getWidgetForPaintable());
  47. }
  48. getWidgetForPaintable().maxLength = newMaxLength;
  49. } else if (getWidgetForPaintable().maxLength != -1) {
  50. getWidgetForPaintable().getElement().setAttribute("maxlength", "");
  51. getWidgetForPaintable().maxLength = -1;
  52. getWidgetForPaintable().keyPressHandler.removeHandler();
  53. }
  54. if (uidl.hasAttribute("selectAll")) {
  55. getWidgetForPaintable().selectAll();
  56. }
  57. }
  58. public void onBeforeShortcutAction(Event e) {
  59. getWidgetForPaintable().synchronizeContentToServer();
  60. }
  61. @Override
  62. public VRichTextArea getWidgetForPaintable() {
  63. return (VRichTextArea) super.getWidgetForPaintable();
  64. };
  65. @Override
  66. protected Widget createWidget() {
  67. return GWT.create(VRichTextArea.class);
  68. }
  69. }