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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2000-2014 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.Element;
  18. import com.google.gwt.event.dom.client.MouseUpEvent;
  19. import com.google.gwt.event.dom.client.MouseUpHandler;
  20. import com.vaadin.client.WidgetUtil.CssSize;
  21. import com.vaadin.client.legacy.ui.textfield.LegacyTextFieldConnector;
  22. import com.vaadin.client.ui.VTextArea;
  23. import com.vaadin.shared.ui.Connect;
  24. import com.vaadin.shared.ui.textarea.TextAreaState;
  25. import com.vaadin.ui.TextArea;
  26. @Connect(TextArea.class)
  27. public class TextAreaConnector extends LegacyTextFieldConnector {
  28. @Override
  29. public TextAreaState getState() {
  30. return (TextAreaState) super.getState();
  31. }
  32. @Override
  33. public VTextArea getWidget() {
  34. return (VTextArea) super.getWidget();
  35. }
  36. @Override
  37. protected void init() {
  38. super.init();
  39. getWidget().addMouseUpHandler(new ResizeMouseUpHandler());
  40. }
  41. /*
  42. * Workaround to handle the resize on the mouse up.
  43. */
  44. private class ResizeMouseUpHandler implements MouseUpHandler {
  45. @Override
  46. public void onMouseUp(MouseUpEvent event) {
  47. Element element = getWidget().getElement();
  48. updateSize(element.getStyle().getHeight(), getState().height,
  49. "height");
  50. updateSize(element.getStyle().getWidth(), getState().width, "width");
  51. }
  52. /*
  53. * Update the specified size on the server.
  54. */
  55. private void updateSize(String sizeText, String stateSizeText,
  56. String sizeType) {
  57. CssSize stateSize = CssSize.fromString(stateSizeText);
  58. CssSize newSize = CssSize.fromString(sizeText);
  59. if (stateSize == null && newSize == null) {
  60. return;
  61. } else if (newSize == null) {
  62. sizeText = "";
  63. // Else, if the current stateSize is null, just go ahead and set
  64. // the newSize, so no check on stateSize is needed.
  65. } else if (stateSize != null && stateSize.equals(newSize)) {
  66. return;
  67. }
  68. getConnection().updateVariable(getConnectorId(), sizeType,
  69. sizeText, false);
  70. }
  71. }
  72. }