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.

LabelConnector.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.label;
  17. import com.google.gwt.dom.client.Document;
  18. import com.google.gwt.dom.client.PreElement;
  19. import com.vaadin.client.Profiler;
  20. import com.vaadin.client.WidgetUtil;
  21. import com.vaadin.client.communication.StateChangeEvent;
  22. import com.vaadin.client.ui.AbstractComponentConnector;
  23. import com.vaadin.client.ui.VLabel;
  24. import com.vaadin.shared.ui.Connect;
  25. import com.vaadin.shared.ui.Connect.LoadStyle;
  26. import com.vaadin.shared.ui.label.LabelState;
  27. import com.vaadin.ui.Label;
  28. @Connect(value = Label.class, loadStyle = LoadStyle.EAGER)
  29. public class LabelConnector extends AbstractComponentConnector {
  30. @Override
  31. public LabelState getState() {
  32. return (LabelState) super.getState();
  33. }
  34. @Override
  35. public void onStateChanged(StateChangeEvent stateChangeEvent) {
  36. super.onStateChanged(stateChangeEvent);
  37. boolean sinkOnloads = false;
  38. Profiler.enter("LabelConnector.onStateChanged update content");
  39. VLabel widget = getWidget();
  40. switch (getState().contentMode) {
  41. case PREFORMATTED:
  42. PreElement preElement = Document.get().createPreElement();
  43. preElement.setInnerText(getState().text);
  44. // clear existing content
  45. widget.setHTML("");
  46. // add preformatted text to dom
  47. widget.getElement().appendChild(preElement);
  48. break;
  49. case TEXT:
  50. widget.setText(getState().text);
  51. break;
  52. case HTML:
  53. sinkOnloads = true;
  54. widget.setHTML(getState().text);
  55. break;
  56. }
  57. Profiler.leave("LabelConnector.onStateChanged update content");
  58. if (sinkOnloads) {
  59. Profiler.enter("LabelConnector.onStateChanged sinkOnloads");
  60. WidgetUtil.sinkOnloadForImages(widget.getElement());
  61. Profiler.leave("LabelConnector.onStateChanged sinkOnloads");
  62. }
  63. }
  64. @Override
  65. public VLabel getWidget() {
  66. return (VLabel) super.getWidget();
  67. }
  68. }