com.vaadin.v7.client.ui.label.LabelConnector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vaadin-compatibility-client Show documentation
Show all versions of vaadin-compatibility-client Show documentation
Vaadin 7 compatibility package for Vaadin 8
/*
* Copyright (C) 2000-2024 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See for the full
* license.
*/
package com.vaadin.v7.client.ui.label;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.PreElement;
import com.vaadin.client.Profiler;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.Connect.LoadStyle;
import com.vaadin.v7.client.ui.AbstractLegacyComponentConnector;
import com.vaadin.v7.client.ui.VLabel;
import com.vaadin.v7.shared.ui.label.LabelState;
import com.vaadin.v7.ui.Label;
@Connect(value = Label.class, loadStyle = LoadStyle.EAGER)
public class LabelConnector extends AbstractLegacyComponentConnector {
@Override
public LabelState getState() {
return (LabelState) super.getState();
}
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
boolean sinkOnloads = false;
Profiler.enter("LabelConnector.onStateChanged update content");
VLabel widget = getWidget();
switch (getState().contentMode) {
case PREFORMATTED:
PreElement preElement = Document.get().createPreElement();
preElement.setInnerText(getState().text);
// clear existing content
widget.setHTML("");
// add preformatted text to dom
widget.getElement().appendChild(preElement);
break;
case TEXT:
widget.setText(getState().text);
break;
case HTML:
case RAW:
sinkOnloads = true;
case XML:
widget.setHTML(getState().text);
break;
default:
widget.setText("");
break;
}
Profiler.leave("LabelConnector.onStateChanged update content");
if (sinkOnloads) {
Profiler.enter("LabelConnector.onStateChanged sinkOnloads");
WidgetUtil.sinkOnloadForImages(widget.getElement());
Profiler.leave("LabelConnector.onStateChanged sinkOnloads");
}
}
@Override
public VLabel getWidget() {
return (VLabel) super.getWidget();
}
}