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.

RichTextAreaConnector.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2011 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui.richtextarea;
  17. import com.google.gwt.user.client.Event;
  18. import com.vaadin.client.ApplicationConnection;
  19. import com.vaadin.client.Paintable;
  20. import com.vaadin.client.UIDL;
  21. import com.vaadin.client.ui.AbstractFieldConnector;
  22. import com.vaadin.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
  23. import com.vaadin.client.ui.VRichTextArea;
  24. import com.vaadin.shared.ui.Connect;
  25. import com.vaadin.shared.ui.Connect.LoadStyle;
  26. import com.vaadin.ui.RichTextArea;
  27. @Connect(value = RichTextArea.class, loadStyle = LoadStyle.LAZY)
  28. public class RichTextAreaConnector extends AbstractFieldConnector implements
  29. Paintable, BeforeShortcutActionListener {
  30. @Override
  31. public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
  32. getWidget().client = client;
  33. getWidget().id = uidl.getId();
  34. if (uidl.hasVariable("text")) {
  35. getWidget().currentValue = uidl.getStringVariable("text");
  36. if (getWidget().rta.isAttached()) {
  37. getWidget().rta.setHTML(getWidget().currentValue);
  38. } else {
  39. getWidget().html.setHTML(getWidget().currentValue);
  40. }
  41. }
  42. if (isRealUpdate(uidl)) {
  43. getWidget().setEnabled(isEnabled());
  44. }
  45. if (!isRealUpdate(uidl)) {
  46. return;
  47. }
  48. getWidget().setReadOnly(isReadOnly());
  49. getWidget().immediate = getState().immediate;
  50. int newMaxLength = uidl.hasAttribute("maxLength") ? uidl
  51. .getIntAttribute("maxLength") : -1;
  52. if (newMaxLength >= 0) {
  53. if (getWidget().maxLength == -1) {
  54. getWidget().keyPressHandler = getWidget().rta
  55. .addKeyPressHandler(getWidget());
  56. }
  57. getWidget().maxLength = newMaxLength;
  58. } else if (getWidget().maxLength != -1) {
  59. getWidget().getElement().setAttribute("maxlength", "");
  60. getWidget().maxLength = -1;
  61. getWidget().keyPressHandler.removeHandler();
  62. }
  63. if (uidl.hasAttribute("selectAll")) {
  64. getWidget().selectAll();
  65. }
  66. }
  67. @Override
  68. public void onBeforeShortcutAction(Event e) {
  69. flush();
  70. }
  71. @Override
  72. public VRichTextArea getWidget() {
  73. return (VRichTextArea) super.getWidget();
  74. }
  75. @Override
  76. public void flush() {
  77. getWidget().synchronizeContentToServer();
  78. };
  79. }