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.

TextAreaConnector.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2000-2018 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.textarea;
  17. import com.google.gwt.dom.client.Style;
  18. import com.google.gwt.event.dom.client.MouseUpEvent;
  19. import com.google.gwt.event.dom.client.MouseUpHandler;
  20. import com.vaadin.client.event.InputEvent;
  21. import com.vaadin.client.ui.VTextArea;
  22. import com.vaadin.client.ui.textfield.AbstractTextFieldConnector;
  23. import com.vaadin.shared.ui.Connect;
  24. import com.vaadin.shared.ui.textarea.TextAreaServerRpc;
  25. import com.vaadin.shared.ui.textarea.TextAreaState;
  26. import com.vaadin.ui.TextArea;
  27. @Connect(TextArea.class)
  28. public class TextAreaConnector extends AbstractTextFieldConnector {
  29. @Override
  30. public TextAreaState getState() {
  31. return (TextAreaState) super.getState();
  32. }
  33. @Override
  34. public VTextArea getWidget() {
  35. return (VTextArea) super.getWidget();
  36. }
  37. @Override
  38. protected void init() {
  39. super.init();
  40. getWidget().addChangeHandler(event -> sendValueChange());
  41. getWidget().addDomHandler(
  42. event -> getValueChangeHandler().scheduleValueChange(),
  43. InputEvent.getType());
  44. getWidget().addMouseUpHandler(new ResizeMouseUpHandler());
  45. }
  46. /*
  47. * Workaround to handle the resize on the mouse up.
  48. */
  49. private class ResizeMouseUpHandler implements MouseUpHandler {
  50. @Override
  51. public void onMouseUp(MouseUpEvent event) {
  52. Style elementStyle = getWidget().getElement().getStyle();
  53. String newHeight = elementStyle.getHeight();
  54. String newWidth = elementStyle.getWidth();
  55. if (newHeight == null) {
  56. newHeight = "";
  57. }
  58. if (newWidth == null) {
  59. newWidth = "";
  60. }
  61. if (!newHeight.equals(getState().height)) {
  62. getRpcProxy(TextAreaServerRpc.class).setHeight(newHeight);
  63. }
  64. if (!newWidth.equals(getState().width)) {
  65. getRpcProxy(TextAreaServerRpc.class).setWidth(newWidth);
  66. }
  67. }
  68. }
  69. }